Decompostion and algorithm practice questions - OCRDesigning an algorithm – example one

Every programming problem needs decomposing so that it can be properly understood. From this, an algorithm can be designed and tested.

Part ofComputer ScienceStudy skills

Designing an algorithm – example one

Algorithm design option one - flow diagram

Flow diagram showing how hours worked determine total pay

Algorithm design option two - pseudocode

#variable and constant declaration
HOURLY_RATE = 10.00
OVERTIME_RATE = 15.00
MAX_HOURS = 60
MIN_HOURS = 1
NORMAL_HOURS = 40
hours_worked = 0
overtime_hours = 0
normal_pay = 0
overtime_pay = 0
total_pay = 0 #input number of hours worked
while hours_worked < MIN_HOURS or hours_worked > MAX_HOURS hours_worked = float(input("Enter the number of hours worked: "))
endwhile #calculate overtime hours
if hours_worked > NORMAL_HOURS then overtime_hours = hours_worked - NORMAL_HOURS hours_worked = NORMAL_HOURS
endif #calculate pay
normal_pay = hours_worked * HOURLY_RATE
overtime_pay = overtime_hours * OVERTIME_RATE
total_pay = normal_pay + overtime_pay #output result
print("Normal pay rate: £", HOURLY_RATE)
print("Overtime pay rate: £", OVERTIME_RATE)
print("Hours worked: ", hours_worked)
print("Overtime hours worked: ", overtime_hours)
print("Total pay: £", total_pay)

Testing table

Tests will be required to check that the final program runs correctly.

Test no.DescriptionTest dataTest typeExpected outcome
1Calculate normal pay only20Valid£200.00
2Borderline - calculate normal pay only - lower end1Extreme£10.00
3Borderline calculate normal pay only - higher end40Extreme£400.00
4Calculate normal and overtime pay 45.5Valid£482.50
5Borderline - calculate normal and overtime pay - lower end41Extreme£415
6Borderline - calculate normal and overtime pay - higher end60Extreme£700
7Test rejected input - below minimum0InvalidAsked to input again
8Test rejected output - above maximum61InvalidAsked to input again
Test no.1
DescriptionCalculate normal pay only
Test data20
Test typeValid
Expected outcome£200.00
Test no.2
DescriptionBorderline - calculate normal pay only - lower end
Test data1
Test typeExtreme
Expected outcome£10.00
Test no.3
DescriptionBorderline calculate normal pay only - higher end
Test data40
Test typeExtreme
Expected outcome£400.00
Test no.4
DescriptionCalculate normal and overtime pay
Test data45.5
Test typeValid
Expected outcome£482.50
Test no.5
DescriptionBorderline - calculate normal and overtime pay - lower end
Test data41
Test typeExtreme
Expected outcome£415
Test no.6
DescriptionBorderline - calculate normal and overtime pay - higher end
Test data60
Test typeExtreme
Expected outcome£700
Test no.7
DescriptionTest rejected input - below minimum
Test data0
Test typeInvalid
Expected outcomeAsked to input again
Test no.8
DescriptionTest rejected output - above maximum
Test data61
Test typeInvalid
Expected outcomeAsked to input again

The problem has now been fully decomposed and an algorithm has been designed.