Decomposition and algorithm practice questions - EduqasDesigning 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
Set HOURLY_RATE = 10.00
Set OVERTIME_RATE = 15.00
Set MAX_HOURS = 60
Set MIN_HOURS = 1
Set NORMAL_HOURS = 40
Set hours_worked = 0
Set overtime_hours = 0
Set normal_pay = 0
Set overtime_pay = 0
total_pay = 0 {input number of hours worked}
while hours_worked < MIN_HOURS OR hours_worked > MAX_HOURS output "Enter the number of hours worked" input hours_worked end while {calculate overtime hours}
if hours_worked > NORMAL_HOURS then overtime_hours = hours_worked - NORMAL_HOURS hours_worked = NORMAL_HOURS
end if {calculate pay}
normal_pay = hours_worked * HOURLY_RATE
overtime_pay = overtime_hours * OVERTIME_RATE
total_pay = normal_pay + overtime_pay {output result}
Output "Normal pay rate: £" < HOURLY_RATE
Output "Overtime pay rate: £" < OVERTIME_RATE
Output "Hours worked: " < hours_worked
Output "Overtime hours worked: " < overtime_hours
Output "Total pay: £" < total_pay
End

Output table

With the inputs stated below the outputs would be:

Example 1: 4 hours

Enter the number of hours worked: 4

Normal pay rate: £10

Overtime pay rate: £15

Hours worked: 4

Overtime hours worked: 0

Total pay: £40

Example 2: 45 hours

Enter the number of hours worked: 45

Normal pay rate: £10

Overtime pay rate: £15
Hours worked: 40
Overtime hours worked: 5
Total pay: £475

Testing table

Test no.DescriptionTest dataTest typeExpected outcome
1Calculate normal pay only20Valid£200
2Borderline - calculate normal pay only - lower end1Extreme£10
3Borderline calculate normal pay only - higher end40Extreme£400
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
Test no.2
DescriptionBorderline - calculate normal pay only - lower end
Test data1
Test typeExtreme
Expected outcome£10
Test no.3
DescriptionBorderline calculate normal pay only - higher end
Test data40
Test typeExtreme
Expected outcome£400
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 has been designed.