Using an abstract data type

 

Now that you have written your class for money values, you can incorporate it into the previous inventory program. You will also learn how to use file streams.

Tasks

Take your inventory and Money ADT source code files and make the following changes:

  1. Remove the main function from the file containing the Money ADTand save the file as money.h
  2. Include this file in the inventory source code with #include "money.h"
  3. Alter every use of a money value (you probably used float) to Money, the name of your ADT class.
  4. Recompile the inventory source code to check for errors. It should behave in exactly the same way as the original, except that the output may look a little different because of you overloading of the insertion operator for the Money class.
  5. Change the I/O behavior so that the program reads the initial values for the inventory from a file, and writes the new values out to the same file after the transactions have been read from the keyboard. This will turn the program into more of a database program that preserves values across program runs. Prompt the user for the name of the database file and then open the file whose name is typed in.

Notes

Testing

You should test your program with a wide variety of inputs, but please use the following data for the final testing and submission of results:

 

Run 1:

 

4 100
6 50
12 75
6 50
4 -20

Run 2:

 

8 100
10 100
4 70
12 -25

Deliverables

  1. The source code of your inventory program, and results of running the two tests in the sequence given above, in hardcopy form, handed to me (RTH).
  2. The source code of your program, submitted using the assignment submitter as 'program3'.

Due Date

Friday, April 14th  before 5 pm.