Details of an invoice are available as follows:
The number of items on the invoice - n
For each item
an item code (6 digits), a quantity and
a unit cost (dollars,cents)
Thus a typical set of input values for an invoice might be:3 161432 5 6 50 543289 10 2 25 876234 2 10 75indicating that there are three items on the invoice, the first item having an item code of 161432, an order quantity of 5 and a unit price of six dollars fifty cents. Assume that the days date will also be entered.
Write a C++ program to enter details of such an invoice and to output an invoice which indicates the total cost of each item and the total cost of the invoice together with full details. The above details might produce an invoice as follows:
Invoice date: 10/6/00
Item quantity unit price total price
161432 5 6.50 32.50
543289 10 2.25 22.50
876234 2 10.75 21.50
Total 76.50
A first attempt at an algorithm might be:
initialise.
enter date.
enter number of items into n.
output headings.
for n items do
{
enter a record.
calculate total cost of item.
accumulate total invoice cost.
write line of invoice.
}
output total cost.
Assume that there are four programmers available to implement this
program. There are four major operations inside the for loop
hence each programmer could be given one operation to implement. The
best way to do this is to use a function for each operation. Each
programmer can then be given a precise definition of a function.
For example consider the operation enter a record. This
function must read in the integer quantities item number, quantity and
unit price in dollars and cents. Hence it has no input parameters and
four output parameters. A definition of the function could then be
written as follows:
Function name: dataentry
Operation: Enter a record
Description: Enters four integers from the current
input line and returns their values.
Parameters: Output parameter int itemno
Output parameter int quantity
Output parameter int unitdollars
Output parameter int unitcents
Similarly the other functions could be specified as follows:
Function name : calccost
Operation : Calculates the cost for a single item.
Description : Given the unit price of an item in
dollars and cents and the quantity of
the item calculates the total cost in
dollars and cents.
Parameters : Input parameter int quantity
input parameter int unitdollars
input parameter int unitcents
output parameter int totaldollar
output parameter int totalcents
Function name : acctotal
Operation : Accumulates the total cost of invoice
Description : Given current total invoice cost and
the total cost of an invoice item
calculates the new total invoice cost.
Parameters : input parameter int totaldollar
input parameter int totalcents
input & output parameter int invdollar
input & output parameter int invcents
Function name : writeline
Operation : Writes a line of the invoice.
Description : Given the item reference number, the
quantity, the unit price and total
price of an item outputs a line of
the invoice.
Parameters : input parameter int itemno
input parameter int quantity
input parameter int unitdollars
input parameter int unitcents
input parameter int totaldollar
input parameter int totalcents