Question 2 (8 marks): Invoice Anyone?
You are asked to create a invoice generation module for your company’s Point of Sale software.
The invoice will consist of a table, of rows and columns, presented in string text. The first row will provide column headers. Then a row for each product sold, including their respective price, quantity GST and Total. The final row contains the product totals. Each row will be 70 characters long unless numerical fields exceed the size allocated.
For each item sold, you will ask the user four questions:
Name of the product
Unit Price
Quantity sold
Whether to apply GST (YES or NO)
If the product name field is left empty (i.e. the user simply presses enter), it signifies no more products are in the order. Your program should then print the invoice. If no
products are provided by the user, no invoice should be printed.
All products should be processed before printing the invoice. The formatting of the invoice must be as follows:
Product | $ Price | Qty | ———————————————————————-
ARTISTS SET
BUZZ LIGHT YEAR
RULER
SKIPPING ROPES
STATIONARY SET ———————————————————————- Total: $2370.21 Less 5% Discount: $118.51 ———————————————————————- The product lines must have:
GST |
131.60 | $ 3.58 | $
0.00 | $ 0.00 | $ 0.00 | $
Sub Total
1447.60 39.36
16.00 442.75 424.50
| $ | $
| $ | $
| $
65.80 | 35.78 |
20 | $ 1 | $
0.32 | 12.65 | 8.49 |
50 | $ 35 | $ 50 | $
Order Total: $2251.70
20 columns for the product name (product names should be shortened if needed)
10 columns for the unit price (Price)
5 columns for the quantity sold (an integer)
10 columns for GST and Sub Total (floats displayed to two decimal places)
The GST (if applied) should be 10% of the subtotal, otherwise 0. The row’s subtotal is the unit price multiplied by the quantity plus GST. The product name must be
” | ” for non currency fields, otherwise ” | $”
If the Totals row is over $500, the order of each field must be as follows:
Total: in 8 columns, left aligned, followed by ” $” and the total (with two decimal places)
Less 5% Discount: in 20 columns, right aligned, followed by ” $” and the discount (with two decimal places)
Order Total: in 16 columns, right aligned, followed by ” $” and the order total after discount is applied (with two decimal places)
Where no discount is applied, the Totals row should contain only the following fields:
Starting at column 43 the heading Order total: in 15 columns, left aligned, followed by “$” and the order total, right aligned and 12 columns (with
printed in uppercase.
Between each field should be:
two decimal places)
———————————————————————-
Order total $
———————————————————————-
Invoice sections are separated using dashed lines of 70 columns.
44.00
Sample session with the program:
Quantity? 2
Quantity? 1
Product | $ Price | Qty | ———————————————————————- BEAN BAG | $ 45.00 | 2 | $ DESK | $ 199.50 | 1 | $ ———————————————————————-
GST |
Sub Total
Product
name?
bean
bag
Unit
price?
45
GST?
yes
Product
name?
desk
Unit
price?
199.5
GST?
no
Product
name?
Order total $ ———————————————————————-
9.00 | $ 0.00 | $
99.00 199.50
298.50