Assignment 9 - Reference Counting and a Linked List

due December 4th

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 the inventory of various "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

  1. add <item number> - add the item to the inventory, or increase the count for that item 
  2. subtract <item number> - subtract the item from the inventory, or decrease the count for that item
  3. print inventory - print the contents of the linked list (in sorted order) as shown below
  4. misspelled transactions (add, subtract, or print may be misspelled) - print an error message, including the line number in the file
  5. blank lines - skip over these (but count the lines)

Program Requirements

  1. You must write your own linked list.  You may not use any STL containers.
  2. The linked list must be maintained in sorted order by the item number.
  3. The linked list node must contain the item number and a count of the number of that item that are added to the inventory.
  4. If the item is not in the inventory, then that node must be removed.
  5. You must print out the contents of the linked list when a "print inventory" transaction record appears.  See sample output below.
  6. You must write at least 2 classes, a "node" class and a "linked list" class.  Both classes must contain constructors and the "linked list" class must have a destructor.
  7. You must include at least two overloaded operators as member functions.
  8. The print function of your "linked list" class must be implemented as an overloaded insertion operator function.

Input File

This is the first 32 records of the input file.

add 9171
add 6503
add 0042

add 0042
add 4467

add 6965
ad 8469
add 8469

subtract 4467
subttact 9171
add 6335
add 6503
add 8469
subtract 6503
add 4467
subtract 0042
subtract 8469
add 6335
subtract 6503
add 1480
subtract 8469
add 1480

add 9171
add 1480
subtract 6335
print inventory
subtract 9171
subtract 6335
...

Get input file here

Program Output

Here is some partial output from the program.  

Output
Bad transaction: ad in line #9
Bad transaction: subttact in line #13

Item  Quantity
0042       1
1480       3
4467       1
6335       1
6965       1
9171       2

Bad transaction: prlnt in line #51

Item  Quantity
0042       1
1480       4
4467       2
5726       1
...

This output shows the contents of the linked list after the first print inventory transaction (plus a few more lines).