6.15. Answers to Exercises
- 1. Here is the new function declaration that needs to be added to the StockItem interface definition (from code\item6.h):
- and the one to be added to the Inventory interface definition (from code\invent2.h):
- 2. Figure 6.36 shows the implementation of the Write member function for StockItem, and Figure 6.37 is the implementation of the StoreInventory member function of the Inventory class. As you can see, neither of these functions is tremendously complex or, for that matter, very different from the Display function.
- Finally, Figure 6.38 shows the changes needed to the application program to write the updated inventory back to a new file.
- Of course in a real program, it would probably be better to write the updated inventory back to the original file, so that the next time we ran the program the updated inventory would be used. However, in the case of a test application, it's simpler to avoid modifying the input file so we can run the same test again if necessary.
- Assuming that you've installed the software from the CD in the back of this book, you can try out this program. First, you have to compile it by following the compilation instructions on the CD. Then type itemtst6 to run the program. When the program asks for a UPC you can use 7904886261, which is the (made-up) UPC for "antihistamines". When the program asks you for a transaction code, type S for "sale" or P for "price check" and then hit Enter.
|
www.steveheller.com steve@steveheller.com |