Homework #5


Deadline: The source code for this program (retail.cpp) and its executable (retail.exe) must be available in your home directory (i.e., cpsuser3.cps.udayton.edu/cps150/sectionn1/cps150-N1.[your number goes here]) by 5:50p on Thursday, September 16, 2004. Also, turn in a printout of your code in class, before class starts.

Note: You must use the filenames exactly as shown above (i.e., all lower case).

Algorithm: A complete and type-written algorithm is due Tuesday, September 14, 2004, in class, before class starts.

Problem: A mail order house sells five different products whose retail prices are shown in the following table:

Product number Retail price
1$2.98
2$4.50
3$9.98
4$4.49
5$6.87

Write an efficient (no unnecessary operations/comparisons) program that reads a series of pairs of numbers as follows:
  1. Product number
  2. Quantity sold for one day
Your program should use a switch() statement to help determine the retail price for each product. Your program should calculate and display the total retail value of all products sold.

Input: An input file contains a single integer indicating how many pairs of integers (i.e., the first integer in the file indicates how many pairs must be processed). Each pair of integers is a product number followed by the quantity sold for that item. The input file will be error-free. Be sure to test your program with several different input streams. There is a sample input file here.

Output: Print an aligned, well-spaced table with labeled columns. The rows and columns must appear exactly as below, and the last column should be totaled.
product		retail		total		proceeds
number		price		number		by product
		  $		sold		  $

   1		2.98
   2		4.50
   3		9.98
   4		4.49
   5		6.87

				total proceeds:
Specifications:

Use a switch() to accumulate both the total number sold for each product.

Set the field width and precision to print aligned output.

Declare each retail price as a symbolic constant:
   const double RET_PR_1 = 2.98
   const double RET_PR_2 = 4.50
   const double RET_PR_3 = 9.98
   const double RET_PR_4 = 4.49
   const double RET_PR_5 = 6.87

Return Home