< previous page page_298 next page >

Page 298
Problem-solving case study Shipping Invoices
0298-01.gif
Problem: The Mill Hollow Boring and Bearing Company occasionally has to ship products outside its delivery area. The company has asked you to write a program that prints shipping invoices. Only one invoice is printed at a time, but each invoice may have several items on it.
The inputin a file inFileis a series of data sets, one set per item, each on a separate line. Each data set contains the quantity of an item shipped, a description of the item, and the unit price of the item. The end of the data is indicated by an item quantity of zero or less. After the last data set is processed, the total number of items and the total amount should be output.
Input: A file inFile, where each line of input contains the quantity shipped of an item (int), followed by a blank, followed by a 30-character description of the item, followed by another blank and then the unit price of the item (float). The end of the data is indicated by an item quantity of zero or less. Here is a sample of the input data:
15 Titanium bearing assembly      14.35
42 Bore insert (Part no. 36JX425) 9.29
18 Assembly bolt packet           12.45
0
Output: An invoice with four columns of information: the quantity of each item shipped, a description of each item, the unit price of each item, and the billing amount for the given number of items. Each column should have an appropriate heading, as should the overall invoice. After the last item has been printed, the total number of units shipped and the total amount of the invoice should be printed.
Discussion: This program simply reads each line of data and prints out the quantity, description, price, and amount for the given number of units. Running sums of the quantity and amount values must be kept. There are two loops in this program: a sentinel-controlled loop to control the reading of the data sets and a nested count-controlled loop to read and print the string of 30 characters in the item description.

 
< previous page page_298 next page >