CO311: Introduction to Modern Programming II

Practice Test to prepare for Practical #13 on May 8

Please read the entire problem before jumping into the code!

Using the in-class examples and practice test as a guide, modify the solution to Practical 8 to use a “safe” array to hold your data read from a file.

The following are the exact instructions from that original Practical:

CO311: Introduction to Modern Programming II

Lab Practical #8: March 27, 2000

Please read the entire problem before jumping into the code!

Your boss at the hardware store wants you to help him develop software to automate his billing process. He’s already bought some hardware that will scan and put a list of items into a file. Your task is to write a program that will do the following:

  1. Read data from the file
  2. Ask for a sales tax to be added to the purchase (some purchases aren’t taxable, so you can’t hard-code this value).
  3. Print out a list of all the items in the order
  4. Calculate and display the subtotal of the purchases
  5. Calculate and display the tax on the purchase (don’t worry about pretty formatting)
  6. Calculate and display the grand total of the purchases (don’t worry about pretty formatting).

The scanning machine can only handle up to 50 items, so your input file will never have more items than that, but you won’t know ahead of time how many items are actually recorded in the file. At this point, you shouldn’t worry about duplicate items in the file: treat each line as an individual item. You do know, however, that there is one record per line in the following format:

328712 Hammer 15.75

Each record consists of three components:

  • A whole-number that represents the part number (e.g.: 328712).
  • A single-word description that represents an item description (e.g.: Hammer).
  • A floating-point number that represents the price of the item (e.g.: 15.75).

Example input:

328712 Hammer 15.75
33274 Pliers 8.95
1000456 Bolt-cutter 38.99
43234 Screwdriver 8.95
9833321 Fencing 75.00

Example output:

Hammer (328712)  $15.75
Pliers (33274)  $8.95
Bolt-cutter (1000456)  $38.99
Screwdriver (43234)  $8.95
Fencing (9833321)  $75.00
-------------------------------
Subtotal: $147.64
Tax (5%): $7.382
Total: $155.022

Use good programming methods, including separate functions where appropriate. A copy of a sample file (order.txt) can be found in the COMMON area of the FTP site under practicals/p8.

Submit the finished CPP file to the FTP site in its own folder called P8.

Your class definition, implementation and driver program should be in separate files as appropriate. If you want them reviewed, submit your copies to the FTP site in a separate folder called P13PREP and send email to jim3@millard.org.