
CS 226 – Intro. to O-O Programming w/C++: Programming Assignment 1
1. Write a data entry program to meet the following specification and requirements.
A wholesale hardware distributor sells five products, number 1-5, at the unit prices indicated:
Product Unit Price
1 $2.98
2 $3.25
3 $8.47
4 $5.15
5 $4.24
At the end of each sales period the data entry personnel use a computer application program
to enter the quantities of each product that has been sold to various retail outlets. The data is
entered as pairs of numbers (as integers, not characters) that represent a product and the
quantity sold. The user has the option of quitting the program before entering any data, e.g.:
Product Data Entry Program. Do want to continue?y/n y
Enter product and quantity: 2 7
Continue product and quantity entry?y/n
After data has been entered the user is prompted to continue entering more data or quit the
process as shown above. Input for the “y/n” response will be taken as character data. Entry
of product and quantity data will continue until the user enters ‘n’ at the “continue” prompt.
Multiple entries of the same product are allowed and the totals “accumulate”. When the
user is through entering data the program will calculate individual sales totals for each
product and the total sales for all product sales for the data entry period, then print a report
to the screen formatted as shown below.
Product Sales Report:
Product Qty Totals
1 3 8.94
2 5 16.25
3 4 33.88
4 2 10.30
5 12 50.88
Total Sales 120.25
If the user quits the program before entering any data the program should display some kind
of appropriate message instead of printing a report, e.g.:
Product Sales Report: no product data entered.
2. There are several specific programming requirements for the program as follows:
the program must use a while loop for the repetition construct
the program must use a switch selection construct for handling product detection
the program must handle invalid product numbers with an appropriate error message,
e.g.:
Enter product and quantity: 7 4
Invalid product code: 7
the program must handle inputs of uppercase and lowercase letters, i.e. ‘n’ and ‘N’
1