Arrays, Functions, and File I/O (checkout)
CS 161 - Spring 2006 modified for CS 420 testing assignment

Overview
For this assignment, you will write a program to simulate a grocery store checkout system. Information about store items (item code, name, cost per unit, and whether the item is sold by pounds or quantity) will be stored in a file. Standard input will contain the name of that file followed by lines representing items to be purchased. Your program will print a report of the purchased items and total cost.

Checkout Description
The first line of standard input will contain a file name. You are to open the file and read the contents to obtain the information on items for sale. The file will contain one line per item. The line will contain four values. The values are
1: item number (an integer),
2: item name (a string),
3: item price (a double), and
4: item type (a string, either pounds or each).
You may assume the item information file is properly formatted. You may assume that the item numbers are unique.

The item number can be any positive integer. Hint: Do NOT use them as an index since they have a very large range. The item name is a string of non-space characters. The item price is a positive real number. The item type is a string. It is either pounds, meaning the item is sold by the pound, or it is each, meaning the item is sold by units. Note that the lines in the file are not sorted in any way and that you should store them within your program.

After the item file name, the standard input will contain purchase information. Each line will contain an item number and a quantity or weight as appropriate for the item. You should write out a line of information for the purchase after reading each input line. To compute the appropriate output line, you will need to look up the item number in the item information list. If the item number is not in your list, print a message and skip the item.

After all input has been processed, write out a line with the total purchase price.

Sample File named itemfile

22 apple 0.69 pounds
10 gallonMilk 2.99 each

Sample Input

itemfile
22 3.1
10 2 

Sample Output

apple 3.10 lb @ 0.69/lb = $2.14
gallonMilk 2 @ 2.99 each = $5.98

Total = $8.12