CS 162 Spring 2000 Assignment 8 –List Internals 100 points

Assigned: 04/10/2000

Due: 04/17/2000 at the start of class.

Pairs: You may work in pairs if you want. Note, during the course of the semester, you cannot pair with any one person more than twice. If you work in a pair, turn in ONE copy that is the work of both of you, with both of your names on it. Each member of the pair will receive the same grade for that lab.

Main Assignment:

You will update the AccountList class that that is patterned after Budd’s slist.h simple list template, and write a main that demonstrates the capabilities of your functions. (the list AccountList.h and .cpp and the AccountLink.h and .cpp and the Account.h and .cpp files on my WWW page are necessary for this assignment). Your additions to the AccountList class should be member functions/operators:

    1. GetNthAccount – which given an integer 0® #elements-1 will return the Account in that number Node in the List
    2. GetNthAccountLinkPtr – which given an integer 0® #elements-1 will return a pointer to that number node in the list
    3. Remove – which given an Account, will find and remove the corresponding element in the list
    4. Sort – which will sort the list according to the < and > operators of the Account class (currently uses the balance)
    5. Member operator += which will – given another list append a copy of the passed list to the current list – not changing the passed list, nor linking the actual exact same nodes into the current list.

Details:

0) Your functions can, and in many cases should, make use of other functions provided by the classes involved (and remember that AccountList is a friend of AccountLink, so can use the private parts of AccountLink).

  1. GetNth functions should start with 0 – 0th element is the first one in the list
  2. Remove function should return whether the removal actually happened – true if found and removed, false if not found (and thus not removed). Your Remove is under a little handicap in that the Account class == operator is only testing the balance, which is not good enough for determining if we found a matching account.
  3. Sort – I recommend an approach where a list is built up from empty by adding the largest (remaining) element in the original list, as the original list is reduced. This is easily the hardest part of this assignment. Try to get started on this in time to brainstorm, sleep on it, ask questions, debug, etc.
  4. In our previous classes operators such as += were defined outside the class, here I suggest that it will be easier if it is defined inside the class.
  5. Your main should provide capabilities as shown in the example below. You are welcome to test further. If you want to hand in main with further tests a) let me know; and b) do my example tests first; and c) before doing more, ask user y/n whether they want to see them.
  6. The client program on my www page should give some ideas of how you could go about writing your main (the specific things there were put there to test my adaptation of Budd’s code however, not the current assignment.
  7. The AccountList.h on my www page prior to 4/11 needed a small update to make erase work. Get latest version if you already got it before.
  8. It is possible that sometime in a class member function that you would have to refer to the current object (rather than just one of its data members or member functions. If you do, *this refers to the (entire) current object.

Hand-in:

1) Listing of the program

2) Disk with all relevant .h and .cpp files, plus your .exe file. NAME YOUR CLIENT FILE yourlastname8.cpp Name your project yourlastname8 so that the executable will be yourlastname8.exe. If you are working in pairs, use both last names (e.g. redmondsmith8.cpp)

Miscellaneous:

1) If you have any questions about what should be done, please ask!!

2) MAKE SURE YOUR PROGRAM WORKS! (i.e. more than just removing compile errors).

3) Remember: Indentation, meaningful variable names, symbolic constants, and meaningful comments. Weaknesses in any of these could result in points off. Also make sure you put YOUR NAME(s), section, and e-mail address in comments at the beginning of the program.

Sample Interaction:

create empty lists and show them

myList has 0 elements

myOtherList has 0 elements

Waiting for you - type char and return> d

show two lists with random acct#s and random deposits

myList has 5 elements

Acct# 1740 Bal: 1169

Acct# 7614 Bal: 1902

Acct# 7954 Bal: 703

Acct# 7931 Bal: 1529

Acct# 0900 Bal: 1006

myOtherList has 5 elements

Acct# 4551 Bal: 827

Acct# 6857 Bal: 1726

Acct# 4113 Bal: 868

Acct# 2860 Bal: 942

Acct# 3446 Bal: 1840

Waiting for you - type char and return> d

test += operator - show that myList has changed and myOtherList has not

myList has 10 elements

Acct# 1740 Bal: 1169

Acct# 7614 Bal: 1902

Acct# 7954 Bal: 703

Acct# 7931 Bal: 1529

Acct# 0900 Bal: 1006

Acct# 4551 Bal: 827

Acct# 6857 Bal: 1726

Acct# 4113 Bal: 868

Acct# 2860 Bal: 942

Acct# 3446 Bal: 1840

myOtherList has 5 elements

Acct# 4551 Bal: 827

Acct# 6857 Bal: 1726

Acct# 4113 Bal: 868

Acct# 2860 Bal: 942

Acct# 3446 Bal: 1840

Waiting for you - type char and return> d

test getNth functions

Using GetNthAccount - myOtherList Account: 0 Acct# 4551 Bal: 827

Using GetNthAccount - myOtherList Account: 1 Acct# 6857 Bal: 1726

Using GetNthAccount - myOtherList Account: 2 Acct# 4113 Bal: 868

Using GetNthAccount - myOtherList Account: 3 Acct# 2860 Bal: 942

Using GetNthAccount - myOtherList Account: 4 Acct# 3446 Bal: 1840

Using GetNthAccountLinkPtr - myOtherList Account: 0 Acct# 4551 Bal: 827

Using GetNthAccountLinkPtr - myOtherList Account: 1 Acct# 6857 Bal: 1726

Using GetNthAccountLinkPtr - myOtherList Account: 2 Acct# 4113 Bal: 868

Using GetNthAccountLinkPtr - myOtherList Account: 3 Acct# 2860 Bal: 942

Using GetNthAccountLinkPtr - myOtherList Account: 4 Acct# 3446 Bal: 1840

Waiting for you - type char and return> d

test remove function - show that myList has changed (element 7 gone) and myOtherList has not

remove ok: 1

myList has 9 elements

Acct# 1740 Bal: 1169

Acct# 7614 Bal: 1902

Acct# 7954 Bal: 703

Acct# 7931 Bal: 1529

Acct# 0900 Bal: 1006

Acct# 4551 Bal: 827

Acct# 6857 Bal: 1726

Acct# 2860 Bal: 942

Acct# 3446 Bal: 1840

myOtherList has 5 elements

Acct# 4551 Bal: 827

Acct# 6857 Bal: 1726

Acct# 4113 Bal: 868

Acct# 2860 Bal: 942

Acct# 3446 Bal: 1840

Waiting for you - type char and return> d

test remove function special cases - show that myOtherList has changed (first and last elements gone)

myList has 9 elements

Acct# 1740 Bal: 1169

Acct# 7614 Bal: 1902

Acct# 7954 Bal: 703

Acct# 7931 Bal: 1529

Acct# 0900 Bal: 1006

Acct# 4551 Bal: 827

Acct# 6857 Bal: 1726

Acct# 2860 Bal: 942

Acct# 3446 Bal: 1840

myOtherList has 3 elements

Acct# 6857 Bal: 1726

Acct# 4113 Bal: 868

Acct# 2860 Bal: 942

Waiting for you - type char and return> d

test sort - show that myList has changed and myOtherList has not

myList has 9 elements

Acct# 7614 Bal: 1902

Acct# 3446 Bal: 1840

Acct# 6857 Bal: 1726

Acct# 7931 Bal: 1529

Acct# 1740 Bal: 1169

Acct# 0900 Bal: 1006

Acct# 2860 Bal: 942

Acct# 4551 Bal: 827

Acct# 7954 Bal: 703

myOtherList has 3 elements

Acct# 6857 Bal: 1726

Acct# 4113 Bal: 868

Acct# 2860 Bal: 942

Waiting for you - type char and return> d