(
Latest Revision:
03/08/2008
)
Lists: A Program That Simulates a (Simplified) Grocery Store Checkout
Procedure
PRELIMINARIES:
You need to read chapter three of Carrano before you begin this assignment.
You also need to read the directions and examples here:
http://www.cs.csustan.edu/~john/Classes/General_Info/progAsgRules/
THE ASSIGNMENT:
Write, run, and test a program to simulate the operation of a (simplified)
grocery store checkout system. Your program will first make a list containing
information on 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:
Input for this program will come from 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 is an
inventory record containing information
about one of the types of item the store offers for sale. An inventory record consists of a series of fields
separated by white space. Here is the format for an
inventory record:
<product number> <description> <price>
<tax>
For example:
11012 gallon-milk 1.99 N
means 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-data sentinel. The end-of-data 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
records from the file invent. The program creates an
internal representation of each inventory
record, inserts it into a list, and 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
inventory record
in the invent file.
- <Product number> not in inventory file. If
the program encounters an
item purchase record
in the transac file with a product number that is not in
the inventory file invent then the program must write an
error message on the current line of the receipts file
and skip the incorrect item purchase
record.
- <Times> not in the specified range. If an
item purchase record 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 the incorrect item purchase record.
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 valid
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 (the product: price *
times).
- A subtotal line showing the total before-tax cost of 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 charges for all items in the
customer order record.
All the material described above must be clearly printed,
aligned and labelled. (Assume that the tax rate is 7.375% for
taxable items.)
OUTPUTTING PRICES:
All prices in the invent file have to be formatted as real numbers
and without dollar signs because they have 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. You may 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 must use a version of the List class of our text book as the
inventory list. I have provided one such version in the assignment directory
(suitably 'customized') and you are invited to use it (files ListA.h and
ListA.cpp)
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 turning in three hardcopy versions of your program and you will be
sending me three e-mail messages.
With regard to the e-mail please follow these rules:
- Always send me e-mail as plain text in the main message body. Never send
me attachments.
- Always use the exact subject line I specify for each message.
(I often get hundreds of e-mail messages in a week. The subject line
allows me to find, filter and sort messages.) You will lose a
significant number of points on the assignment if you use the wrong
subject line.
- Be very careful when typing the command to send e-mail. You may use the
instructions in your
Hello World! lab excercise
for guidance. Of course, you will need to make the obvious changes to
those directions -- you have to use the correct subject line and
filename.
- Always send yourself a copy of each e-mail message you send to me, and
check to see if you receive the message intact. You are
responsible for sending e-mail correctly.
Here is the list of things you have to turn in:
- At the start of class on first due date, turn in a hardcopy
of a
level two version of the source code.
Include all the program source code except the files I gave you: ListA.h
and ListA.cpp.
- 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. In the e-mail 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:
CS2500Prog3.2
- At the start of class on the second due date, turn in a
hardcopy of a level three version of the source code.
Include all the program source code except the files I gave you: ListA.h
and ListA.cpp.
- 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. In the e-mail 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:
CS2500Prog3.3
- At the start of class on the third due date, turn in a
hardcopy of a
final level version of the source code.
Include all the program source code except the files I gave you: ListA.h
and ListA.cpp.
- 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. In the e-mail 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:
CS2500Prog3.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.