CS 162 Fall 2001 Assignment 9 –List Internals 100 points
Assigned: 11/12/2001
Due: 11/26/2001 at the start of class – you will have two labs to work on this – but don’t leave a lot of this for Thanksgiving weekend!
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 AcctList
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 AcctListList.h and .cpp and the AcctListNode.h and .cpp and the
Account-new.h and .cpp files on my WWW
page are necessary for this assignment). Your additions to the AcctList class
should be member functions/operators:
Like Real List Class:
1)
Remove
- which given an Account, will find and remove the corresponding element(s) in
the list
2)
Reverse
– which will reverse the list so that the last element becomes the first etc
Something a little different
1)
GetNth
– which given an integer 0®#elements-1 will return the
Account in that number Node in the List
2)
GetNthPtr
– which given an integer 0®#elements-1 will return a
pointer to that number node in the list
3)
Append
– which given another list will add the passed list to the end of the current
list – not changing the passed list,
nor linking the actual exact same nodes into the current list.
4)
Member
operator += which will – given another list append a copy of the passed list to
the current I.e. It can probably use
append
Details:
1)
Your functions can, and in many cases should, make use
of other functions provided by the classes involved (and remember that AcctList
is a friend of AcctNode, so can use the private parts of AcctNode).
2)
GetNth functions should start with 0 – 0th
element is the first one in the list
3)
Unlike the library version, the Remove function should
return whether the removal actually happened – true if found and removed, false
if not found (and thus not removed).
Also our 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. I want you to remove based on matching account
numbers – some extra work for you.
4)
Reverse – there may be some subtle difficulties here.
Try to get started on this in time to brainstorm, sleep on it, ask questions,
debug, etc.
5)
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.
6)
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. I may substitute
in another main to further test your functions.
7)
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.
8)
You may not use the list library AT ALL for this
assignment. Do not even include it!!
Hand-in:
1) Listing of
the program
2) Disk with all relevant .h and .cpp files, plus your .exe file. NAME YOUR CLIENT FILE
yourlastname9.cpp Name your project
yourlastname9 so that the executable will be yourlastname9.exe. If you are
working in pairs, use both last names (e.g. redmondsmith9.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
GetNth - myOtherList Account: 0 Acct# 4551
Bal: 827
Using
GetNth - myOtherList Account: 1 Acct# 6857
Bal: 1726
Using
GetNth - myOtherList Account: 2 Acct# 4113
Bal: 868
Using
GetNth - myOtherList Account: 3 Acct# 2860
Bal: 942
Using
GetNth - myOtherList Account: 4 Acct# 3446
Bal: 1840
Using
GetNthPtr - myOtherList Account: 0 Acct# 4551
Bal: 827
Using
GetNthPtr - myOtherList Account: 1 Acct# 6857
Bal: 1726
Using
GetNthPtr - myOtherList Account: 2 Acct# 4113
Bal: 868
Using
GetNthPtr - myOtherList Account: 3 Acct# 2860
Bal: 942
Using
GetNthPtr - 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
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
reverse - show that myList has changed and myOtherList has not
myList
has 9 elements
Acct#
3446 Bal: 1840
Acct#
2860 Bal: 942
Acct#
6857 Bal: 1726
Acct#
4551 Bal: 827
Acct#
0900 Bal: 1006
Acct#
7931 Bal: 1529
Acct#
7954 Bal: 703
Acct#
7614 Bal: 1902
Acct#
1740 Bal: 1169
myOtherList
has 3 elements
Acct#
6857 Bal: 1726
Acct#
4113 Bal: 868
Acct#
2860 Bal: 942
Waiting
for you - type char and return> d