Welcome! Log In Create A New Profile

Advanced

Urgent Help - Assign 02

Posted by AndreB 
Announcements Last Post
Announcement SoC Curricula 09/30/2017 01:08PM
Announcement Demarcation or scoping of examinations and assessment 02/13/2017 07:59AM
Announcement School of Computing Short Learning Programmes 11/24/2014 08:37AM
Announcement Unisa contact information 07/28/2011 01:28PM
Urgent Help - Assign 02
May 14, 2007 10:31PM
I know I haven't slept for a while, but I'm really battling to get my head around a few things with the first questions. And the anguish is killing me.

Question 1: Adding 2 integer based lists. How do you traverse these lists? I'm assuming that because the type is specified as integer, that this function occurs outside of the class definition. If so, how do you create a pointer to the first node if the member pointer is protected. How else do you traverse the nodes of this list?

I'm probably missing something small, but please could someone shed a little light on this for me?

Thanks in advance
AndreB
Re: Urgent Help - Assign 02
May 15, 2007 12:23AM
I think I may have it now, although I'm now thoroughly half asleep.
I've copied the list passed as parameters to temp lists, got the front() values of each temp list, added these values + carry bit, inserted sum value into return list, then deleted the values from the temp list, thus moving the next value to the front() of the list. This is repeated.

It works fine, but not sure if this is what was expected from the question..
I'd appreciate and comments or pointers.
Thanks.
Re: Urgent Help - Assign 02
May 15, 2007 02:21PM
Dear AndreB,

I took a different view when answering the first question. The question did not (as far as I could see) require the function to be defined outside of the class, so I have assumsed that we are given a free hand in how the problem is solved. I created a friend function and that seemed to work very well in the tests that I did, once I had overcome compiler problems that is.

Whilst I can see that there may be some merit in having the function defined outside the class, for handling large numbers in an application that is arithmetic intensive, I would think that deleting values from your lists and then building them up again may give risk to performance problems due to deallocation and reallocation of memory. That is probably well beyond the scope of the question, but may be a practical consideration.

Hope you nailed the question after getting some shuteye!

Richard
Re: Urgent Help - Assign 02
May 15, 2007 05:56PM
Thanks for the feedback Richard.
You are quite right, making temporary copies of lists just doesn't make sense. In reality, you would have public iterators in place to traverse the list. Thus I'm of the humble opinion that this question was really poorly defined. Perhaps this is on purpose, to see what ideas we can come up with - if that is the case I would definitely included public iterators.

You spoke about compiler problems - could you elaborate.

Regards,
AndreB
Re: Urgent Help - Assign 02
May 16, 2007 09:25AM
I got errors like:

[Linker error] undefined reference to `operator << (std:: ostream&, linkedListType<int> const& )' 
collect2 C:\unisa\devcpp\collect2 
ld returned 1 exit status C:\unisa\devcpp\Makefile.win 
[Build Error] exe: *** [Project1.exe] Error 1

when trying to compile the linked list and ordered linked list classes together with test programs or assignment programs. I tried everything, e.g. (bullet points below copied from e-mail to lecturer):

* Re-installed the software (DevCpp and Mingw) from scratch, after removing all traces of it including from the registry. I deinstalled first from add/remove programs.
* I have checked that all directories for Binaries, Libraries, C Includes and C++ Includes are correct
* Have confirmed that I am using mingw32-make.exe for make.
* Have put in the < > in friend ostream& operator << <> (ostream&, const linkedListType<Type> & ); and tried to compile with and without the <>.

All my files were correctly added to a project so the linker should not have had problems.

I was led to believe by one of the lecturers that I was not alone in having problems with the 2007 disk. I reverted to the 2006 disk at their recommendation and together with putting in <> in a few places have not had any problems since. I reckon I spent about 2-3 days in total trying to get my programs to compile, and there were no problems with my code (well, not relating to compilation anyway). This put strain on me in getting the assignment done in line because of all the pulling out of hair, gnashing of teeth and general tail-chasing!

Regards,

Richard
Re: Urgent Help - Assign 02
May 16, 2007 07:51PM
I can relate to the pulling out of hair and gnashing of teeth. When working through the Link List chapter, I believed I had a solid understanding of what was going on. However the compilation problems have given my confidence a little knock. I usually regard the programming modules as my better modules, but I've taken a bit of a knock in the last couple of days. Compound this with quaterly management meetings and extra job stress and I'm left with my head spinning and licking my wounds. Not to mention a couple of days behind schedule.
Sorry, only registered users may post in this forum.

Click here to login