Homework 2 Structured programming
Unit 2 Problem solving
Homework 2: Structured programming
1. (a) How many lines of output will the following pseudocode program produce? [1]
(b) Trace through the program and write down what is output. [4]
FOR a = 8 to 19 step 4
FOR b = 1 to 3
IF a mod b >= b/3 THEN
IF a/4 <= b+1 THEN
OUTPUT “Homer”
ELSE
OUTPUT “Marge”
ENDIF
ELSE
OUTPUT “Bart”
ENDIF
ENDFOR
ENDFOR
2. (a) Describe three features of structured programming. [6]
(b) List four benefits of using structured programming techniques. [4]
3. The following steps are followed when processing invoices for a batch of customer orders.
Details such as description and price of each stock item are held on a Product file.
Discounts are calculated depending on the total value of the order. Details of all sales are
held on a Sales file. Customer details are held on a Customer file.
Open Product file, Customer file and Sales file
initialise variables
Read Sales file to find last invoice number
for each order
Read Customer file to get customer details
print invoice number, customer details
increment invoice number
for each item on the order
Input the item code, quantity
look up description and price
calculate price*quantity
print line of order
endfor
calculate overall gross total
calculate discount and net price
print total discount and invoice total
update Sales file
endfor
close files
Draw a hierarchy chart showing the major tasks and subtasks involved. [5]
[Total 20 marks]