Example Program Invoice Processing Details of an invoice

  • Slides: 10
Download presentation
Example Program: Invoice Processing • Details of an invoice are available as follows: The

Example Program: Invoice Processing • 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 (pounds, pence) Thus a typical set of input values for an invoice might be: 3 161432 5 6 50 543289 10 2 25 876234 2 10 75

Example Program: Invoice Processing • indicating that there are three items on the invoice

Example Program: Invoice Processing • indicating 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 pounds fifty pence. • 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:

Example Program: Invoice Processing Invoice date: 10/6/96 Item 161432 543289 876234 quantity unit price

Example Program: Invoice Processing Invoice date: 10/6/96 Item 161432 543289 876234 quantity unit price total price 5 10 2 6. 50 2. 25 10. 75 32. 50 21. 50 Total 76. 50

Example Program: Invoice Processing • A first attempt at an algorithm might be: initialise.

Example Program: Invoice Processing • 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.

Example Program: Invoice Processing • Assume that there are four programmers available to implement

Example Program: Invoice Processing • 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.

Example Program: Invoice Processing • For example consider the operation enter a record. •

Example Program: Invoice Processing • For example consider the operation enter a record. • This function must read in the integer quantities item number, quantity and unit price in pounds and pence. • Hence it has no input parameters and four output parameters. • A definition of the function could then be written as follows:

Example Program: Invoice Processing Function name: dataentry Operation: Enter a record Description: Enters four

Example Program: Invoice Processing 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 unitpounds Output parameter int unitpence

Example Program: Invoice Processing Function name : calccost Operation : Calculates the cost for

Example Program: Invoice Processing Function name : calccost Operation : Calculates the cost for a single item. Description : Given the unit price of an item in pounds and pence and the quantity of the item calculates the total cost in pounds and pence. Parameters : Input parameter int quantity input parameter int unitpounds input parameter int unitpence output parameter int totalpound output parameter int totalpence

Example Program: Invoice Processing Function name : acctotal Operation : Accumulates the total cost

Example Program: Invoice Processing 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 totalpound input parameter int totalpence input & output parameter int invpound input & output parameter int invpence

Example Program: Invoice Processing Function name : writeline Operation : Writes a line of

Example Program: Invoice Processing 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 unitpounds input parameter int unitpence input parameter int totalpound input parameter int totalpence