Assignment
9 - Reference Counting and a Linked List
due
November 24th
The
assignment will give you practice writing constructors and destructors,
overloaded operator functions,
and implementing a linked list. You will also employ a
technique called reference counting.
The
Plan
The
goal of the assignment is to track a list of various (fruit) "items".
You will read and process a transaction
file
(partially displayed below). The transaction file contains 5
types of transactions.
You are to store a count of the items in
a sorted linked list.
Details
- The transaction file contains slightly over 100 random
transaction entries. The five transaction type entries are:
- add
<item> - add the item to the inventory, or
increase the count for that item
- remove
<item> - remove the item from the inventory, or
decrease the count for that item. If the item does not exist,
print error message.
- print
inventory - print the contents of the linked list (in
sorted order) as shown below
- misspelled
transactions (add, remove, or print may be misspelled) -
print an error message, including the line number in the file
- blank
lines - skip over these (but count the lines)
Required
Classes
Node
class with the
following
- The
item name (fruit name) and a count of the number of that item that are
contained in the list.
- A
constructor
- At
least 2 overloaded operator functions
- An
overloaded insertion operator as a friend function
List
class with the
following
- A
constructor
- A
destructor
- At
least 2 overloaded operator functions
- An
overloaded insertion operator as a friend function
Program
Requirements
- Produce
the output shown below
- Use
your overloaded insertion operators for output
- Use
your overloaded operators to add and remove from the linked list.
- The
linked list must be
maintained in sorted (alphabetical) order by the
(fruit) item. You
may not
use a sort function.
This is the
first 32 records of the input file.
add
banana
add pear
add orange
add orange
add apple
add peach
add plum
ad plum
remove apple
add watermelon
add pear
add plum
reomve banana
remove pear
add apple
remove orange
remove plum
add watermelon
remove pear
add papaya
remove plum
add papaya
remove potato
add banana
add papaya
remove watermelon
print list
remove banana
remove watermelon
... |
Program
Output
Here is
some partial output from the program.
Output
Bad
transaction: ad in line #10
Bad
transaction: reomve in line #16
Unable
to remove potato in line #26
Item
Quantity
apple
1
banana
2
orange
1
papaya
3
peach
1
watermelon
1
Bad
transaction: prlnt in line #50
Item
Quantity
apple
2
apricot
2
banana
7
orange
1
papaya
4
...
|
This
output shows the contents of the linked list after the first print
list transaction
(plus a few more lines).
Extra Credit (1 point)
You
may receive one extra credit point on this assignment if you split your
solution into a multiple file application. You should split the
solution into 5 files: 3 source files and 2 header files. You
should have a source file and a header file for each class and a
separate source file for main. Submit your solution as a
compressed (zipped) file as an attachment. The extra credit will
only be applied if your assignment is received on time.