Designing an algorithm â example one
Algorithm design option one - flow diagram
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. | Description | Test data | Test type | Expected outcome |
1 | Calculate normal pay only | 20 | Valid | ÂŁ200.00 |
2 | Borderline - calculate normal pay only - lower end | 1 | Extreme | ÂŁ10.00 |
3 | Borderline calculate normal pay only - higher end | 40 | Extreme | ÂŁ400.00 |
4 | Calculate normal and overtime pay | 45.5 | Valid | ÂŁ482.50 |
5 | Borderline - calculate normal and overtime pay - lower end | 41 | Extreme | ÂŁ415 |
6 | Borderline - calculate normal and overtime pay - higher end | 60 | Extreme | ÂŁ700 |
7 | Test rejected input - below minimum | 0 | Invalid | Asked to input again |
8 | Test rejected output - above maximum | 61 | Invalid | Asked to input again |
Test no. | 1 |
---|---|
Description | Calculate normal pay only |
Test data | 20 |
Test type | Valid |
Expected outcome | ÂŁ200.00 |
Test no. | 2 |
---|---|
Description | Borderline - calculate normal pay only - lower end |
Test data | 1 |
Test type | Extreme |
Expected outcome | ÂŁ10.00 |
Test no. | 3 |
---|---|
Description | Borderline calculate normal pay only - higher end |
Test data | 40 |
Test type | Extreme |
Expected outcome | ÂŁ400.00 |
Test no. | 4 |
---|---|
Description | Calculate normal and overtime pay |
Test data | 45.5 |
Test type | Valid |
Expected outcome | ÂŁ482.50 |
Test no. | 5 |
---|---|
Description | Borderline - calculate normal and overtime pay - lower end |
Test data | 41 |
Test type | Extreme |
Expected outcome | ÂŁ415 |
Test no. | 6 |
---|---|
Description | Borderline - calculate normal and overtime pay - higher end |
Test data | 60 |
Test type | Extreme |
Expected outcome | ÂŁ700 |
Test no. | 7 |
---|---|
Description | Test rejected input - below minimum |
Test data | 0 |
Test type | Invalid |
Expected outcome | Asked to input again |
Test no. | 8 |
---|---|
Description | Test rejected output - above maximum |
Test data | 61 |
Test type | Invalid |
Expected outcome | Asked to input again |
The problem has now been fully decomposed and an algorithm has been designed.