Designing an algorithm - example one
Algorithm design option one - flow diagram
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
EndOutput 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: £15Hours worked: 40Overtime hours worked: 5Total pay: £475Testing table
| Test no. | Description | Test data | Test type | Expected outcome |
| 1 | Calculate normal pay only | 20 | Valid | £200 |
| 2 | Borderline - calculate normal pay only - lower end | 1 | Extreme | £10 |
| 3 | Borderline calculate normal pay only - higher end | 40 | Extreme | £400 |
| 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 |
| Test no. | 2 |
|---|---|
| Description | Borderline - calculate normal pay only - lower end |
| Test data | 1 |
| Test type | Extreme |
| Expected outcome | £10 |
| Test no. | 3 |
|---|---|
| Description | Borderline calculate normal pay only - higher end |
| Test data | 40 |
| Test type | Extreme |
| Expected outcome | £400 |
| 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 algorithmA sequence of logical instructions for carrying out a task. In computing, algorithms are needed to design computer programs. has been designed.