(Latest Revision: 10/14/2000)
Lists: A Program That Simulates a Grocery Store Checkout
Procedure
PRELIMINARIES:
You need to read chapter three and most of chapter four of
Carrano before you begin this assignment. You also need to
read the directions and examples here:
http://shalim.csustan.edu/~john/Classes/General_Info/progAsgRules/
THE ASSIGNMENT:
Write, run, and test a program to simulate the operation of a
grocery store checkout system. Your program will first make a
list containing information on all the products available in
the store. Then the program will read a series of customer
orders, and print the cash register receipt for each order.
INPUT:
The input for this program has two sources: the program inputs
inventory information from a text file called invent,
and it inputs customer transaction information from a text file
called transac.
THE INPUT FILE: invent
The invent file consists of a series of lines. Each
line consists of a series of fields separated by white space.
Each line contains the information about one of the products
carried by the store. Here is the format for a line of the
invent file:
<product number> <description> <price>
<tax>
For example:
11012 gallon-milk 1.99 N
states that the store stocks item 11012 (gallon of milk),
priced at $1.99 per unit, and this item is not taxable.
<product number> is a five-digit positive
(non-zero) integer, <description> is a string of
no more than 20 characters with no embedded blanks,
<price> is a real number, and
<tax> is a character ('T' if the product is
taxable, 'N' if it is not taxable). It is a
precondition of the program that the data in the inventory file
is sorted from smallest to largest product number. (Be sure
you understand that the program is not supposed to sort
the invent file. We assume the file is sorted before
we execute the program. You will have to sort "by hand" the
invent files you create for testing.)
THE FORMAT FOR PRICES:
All prices in invent will be formatted as "dollar
amounts" and as fixed-point real numbers. By this I
mean that:
- prices will have a decimal point,
- there will be exactly two digits after the decimal
point,
- there will be at least one digit before the
decimal point,
- the price will have no embedded blanks (blanks in
the middle), and
- the price will not have a dollar sign ('$') in
it.
THE INPUT FILE: transac
The program inputs the customer transaction (order) information
from the file named transac. The transac
file consists of a series of zero or more customer order
records plus a final line containing an end-of-file sentinel.
The end-of-file sentinel looks like this:
-1 0
Each customer order record consists of a series of one or more item
purchase records plus a final line containing an end-of-record
sentinel. The end-of-record sentinel looks like this:
0 0
Each item purchase record consists of a single line of text.
The line of text consists of two fields separated by white
space. An item purchase record has the following format:
<product number> <times>
where <product number> is as described above,
and <times> is an integer in the range 1 to 100,
indicating the quantity of this product desired. For example
11012 3
would represent an order for 3 gallons of milk.
PROCESSING:
The program first reads all of the inventory information from
file invent. It puts this information into a list
variable and also echoprints the information to an output file
called receipts. The program then begins reading from
the transac file. As the program reads each customer
order record, it prints a receipt to the output file
receipts.
ERROR CHECKING:
The following input errors are possible, and must be handled by
the program:
- Duplicate <product number> in the
inventory file. If the program encounters a
product number in the inventory file
invent a second or subsequent time, then
the program must write an error message on the
current line of the receipts file, and
skip the duplicate entry in the invent
file.
- <Product number> not in inventory
file. If the program is processing the
transac file and encounters a product
number that is not in the inventory file
invent then it writes an error message on
the current line of the receipts file and
skips the incorrect item in the transac
file.
- <Times> not in the specified
range. If an entry in the transac file
has a valid product number, but the
times entry is not in the range from 1 to
100, then the program must write an appropriate
error message on the current line of the
receipts file, and skip that entry in the
transac file.
NOTE: All error messages must adequately explain what the error
was.
OUTPUT:
The program will write its output to a text file called
receipts.
As stated above, the echoprint of the inventory (plus whatever
associated error messages are needed) will appear first on the
output file.
Next on the output file will come a series of receipts. There
will be one receipt for each customer order record in the
transac file. The receipt for each customer order record
will be nicely formatted. It will contain:
- A heading that takes up a whole number of lines,
- A series of one-line descriptions, one for each item
purchase record in the customer order record. Each of
these one-line descriptions will contain:
- the product description string,
- the times field from the item
purchase record (number of items),
- the price per item (the price field
from the item's inventory record), and
- the price for all the items (price *
times).
- A line with the subtotal for all the items in the
customer order record,
- A line showing the total amount of the tax on all
the taxable items in the customer order record, and
- A line containing the grand total for the customer
order record.
All the material described above must be clearly printed,
aligned and labelled. (Assume that the tax rate is 7.38% for
taxable items.)
OUTPUTTING PRICES:
All prices in the invent file have to be formatted as
real numbers and without dollar signs because they are going to
be read into C++ float or double variables. On the
receipt file, you may use a different format. In
particular, if you want to, you can print out prices that
contain dollar signs. However, remember that your format has
to be neat and easy to read, like the examples below.
EXAMPLE INPUT and OUTPUT FILES:
EXAMPLE FILE: invent:
11012 gallon-milk 1.99 N
11014 butter 2.59 N
11110 pie-shells 0.99 N
20115 laundry-soap 3.60 T
30005 homestyle-br 0.99 N
EXAMPLE FILE: transac:
11110 2
40012 3
20115 1
0 0
30005 1
11014 2
11012 1
0 0
-1 0
EXAMPLE FILE: receipts:
#################################################
SEP 10, 2001 Welcome to Sam's Grocery
Sam's Inventory is:
11012 gallon-milk 1.99 N
11014 butter 2.59 N
11110 pie-shells 0.99 N
20115 laundry-soap 3.60 T
30005 homestyle-br 0.99 N
#################################################
-------------------------------------------------
SEP 10, 2001 Welcome to Sam's Grocery
Customer 1
pie-shells 2 @ 0.99 1.98
*** ERROR: item 40012 is not in the inventory ***
laundry-soap 1 @ 3.60 3.60
Subtotal 5.58
Tax 0.27
Total 5.85
Thanks very much. Please come again.
-------------------------------------------------
-------------------------------------------------
SEP 10, 2001 Welcome to Sam's Grocery
Customer 2
homestyle-br 1 @ 0.99 0.99
butter 2 @ 2.59 5.18
gallon-milk 1 @ 1.99 1.99
Subtotal 8.16
Tax 0.00
Total 8.16
Thanks very much. Please come again.
-------------------------------------------------
DATA STRUCTURES:
The program can store inventory information internally in a
list. The elements of the list can be structs defined for this
purpose. The structs can have fields for product number,
description, price, tax, and whatever other information you
want to store. Assume that the maximum number of products is
50. Since the data in the inventory file is ordered from
smallest to largest product number, it is very simple to insert
the product records into the list in order. While processing
customer orders, the program can use either a sequential or
binary search to locate a product number in the inventory. You
should create a version of the listClass of our text book for
use as an inventory list.
You can also design other data structures, such as a class to
represent a customer order. The effort you make to design good
data structures is likely to make the rest of the design and
programming work go more quickly and easily.
TEST FILES:
You are responsible for deciding what sort of tests need to be
done on your program to check it for correctness. Your script
must demonstrate adequate code coverage and data coverage. I
expect you to make your own test input files. The sample input
files in this document are not adequate for thorough testing.
We can discuss some testing ideas in class.
WHAT TO TURN IN:
You will be sending me three e-mail messages. Please follow
these rules:
- Always send me e-mail as plain text in the main
message body. Never send me attachments.
- I will tell you what subject line to use with each
message, and I need you to use exactly the
subject lines I give you. (I get hundreds of e-mail
messages at a time and your subject line allows me to
sort messages.)
Here is the list of things you have to turn in:
- Send the following items to me by e-mail before
midnight on the first due date:
A
level two version of the source code
and
a script
showing your test runs. Include all the source
files (*.h files and *.cpp files) that are required
to compile the program into an executable image --
everything I need so that I can compile and test
your program. Combine all the source files and the
script into one
shell archive file
and e-mail me the archive file with the subject
line: CS2500,prog3.2.
- Send the following items to me by e-mail before
midnight on the second due date:
A level three version of the source code and a script
showing your test runs. Include all the source
files (*.h files and *.cpp files) that are required
to compile the program into an executable image --
everything I need so that I can compile and test
your program. Combine all the source files and the
script into one
shell archive file
and e-mail me the archive file with the subject
line: CS2500,prog3.3.
- Send the following items to me by e-mail before
midnight on the third due date:
A
final version of the source code
and
a script
showing your test runs. Include all the source files
(*.h files and *.cpp files) that are required to
compile the program into an executable image --
everything I need so that I can compile and test your
program. Combine all the source files and the script
into one
shell archive file
and e-mail me the archive file with the subject line:
CS2500,prog3.f.
Note that there are no spaces in the subject lines given. It
is important that you do not insert any spaces. My e-mail
address is:
john@ishi.csustan.edu.
DUE DATES:
For the due dates, see
the class schedule.