Welcome! Log In Create A New Profile

Advanced

Assignment 2 Question 1

Posted by sanjivdo 
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
Assignment 2 Question 1
April 13, 2007 09:11AM
I have started assignment 2 but I am not sure how to answer question 1.

"Design your solution so that the same logic adds the first numbers (units position) as well as the rest of the number. In
other words, do not have special one-time logic for adding the units position."

Must I design a function that will accept 2 parameters and then add these parameters, or must the function accept 2 linked lists and then add the numbers within a loop i.e the loop contains the generic logic to add each set of digits. Please can you provide me with an example of what is required.

Sanjiv
Re: Assignment 2 Question 1
April 18, 2007 08:47PM
I am not sure either. Anyones help is most welcome please. Thanks
Re: Assignment 2 Question 1
April 19, 2007 11:10AM
So do I. The tips will be welcomed and appreciated!
Re: Assignment 2 Question 1
April 19, 2007 11:14AM
I received this email:

Hi the function should accept two linked lists as parameters and then the numbers within a loop that contains generic logic to add each set of digits. The first bits will have a carryin of 0.

regard
Lazarus
Re: Assignment 2 Question 1
April 20, 2007 08:52PM
One thing i am still not sure about. Does the function return a linked list containning the sum or it just add up the numbers of the 2 linked list. Do u have any idea what the function header should be? Help is most welcome. Thanks.
Re: Assignment 2 Question 1
April 26, 2007 08:53AM
Hi

The function should in theory return a linked list but since this was not specified in the question you will get full marks if you just added the numbers and did a cout.

regards
Lazarus
Re: Assignment 2 Question 1
April 26, 2007 08:12PM
Thanks for your help.
Re: Assignment 2 Question 1
May 16, 2007 09:25AM
sanjivdo,
what do u mean by "then the numbers within a loop that contains generic logic "? i get the two parameters but the other part,i'm lost with the numbers.
Re: Assignment 2 Question 1
May 16, 2007 09:46AM
is it posibble to find the size of the linked list? is so, how do i get this. because i'm struggling to add the two lists if their two sizes are not equal...
Re: Assignment 2 Question 1
May 16, 2007 10:01AM
hi giggs

1. The loop will contain the logic to do the calculation. For each iteration of the loop add the 2 numbers in each list as well as the carry from the previous calculation.

2. Use a while loop and test if the lists are empty. After each iteration delete the node (you have already used it to calculate the value).

Hope this helps
Sanjiv
Re: Assignment 2 Question 1
May 16, 2007 10:24AM
so after deleting, ur two linked list won't exist?
Re: Assignment 2 Question 1
May 16, 2007 10:31AM
Yes that's right. The function must return a linked list which is the sum of 2 other linked lists. You don't need the original linked lists after you calculate the sum. Also note you are not passing the 2 linked lists as ref.

Sanjiv
Re: Assignment 2 Question 1
May 17, 2007 11:19AM
Then, after adding those two link if we have carry how to create the node which will hold the carry of last node
Re: Assignment 2 Question 1
May 17, 2007 05:23PM
insertLast ?
Sorry, only registered users may post in this forum.

Click here to login