±«Óătv

Designing an algorithm

Algorithm design option one - flow diagram

A flow diagram showing how a programme would calculate the braking distance for a new model of go-kart

Algorithm design option two - pseudo-code

wet_calc ← 1.5

OUTPUT “What speed is the go-kart travelling at?”
speed ← USERINPUT
WHILE (speed IS NOT integer) OR (speed < 10) OR(speed > 50)  DO
  OUTPUT “Speed must be a whole number between 10 and 50. Try again.”
  speed ← USERINPUT
ENDWHILE

OUTPUT “Is the ground wet? (yes/no)”
wet_ground ← USERINPUT

IF wet_gound = “yes” THEN
   braking_dist ← (speed * 5)* wet_calc
ELSE
   braking_dist ← speed * 5
ENDIF
OUTPUT “The braking distance is: “ + braking_dist + “m”

Testing table

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

Test noDescriptionTest dataTest typeExpected outcome
1Calculate normal speed on dry ground20, noNormal100m
2Calculate normal speed on wet ground20, yesNormal150m
3Borderline calculate normal speed on dry ground10, noBoundary50m
4Borderline calculate normal speed on wet ground10, yesBoundary75m
5Test rejected input - below minimum5, yesErroneousAsked to input again
6Test rejected input - above maximum100, yesErroneousAsked to input again
7Test rejected input - not a numberten, yesErroneousAsked to input again
Test no1
DescriptionCalculate normal speed on dry ground
Test data20, no
Test typeNormal
Expected outcome100m
Test no2
DescriptionCalculate normal speed on wet ground
Test data20, yes
Test typeNormal
Expected outcome150m
Test no3
DescriptionBorderline calculate normal speed on dry ground
Test data10, no
Test typeBoundary
Expected outcome50m
Test no4
DescriptionBorderline calculate normal speed on wet ground
Test data10, yes
Test typeBoundary
Expected outcome75m
Test no5
DescriptionTest rejected input - below minimum
Test data5, yes
Test typeErroneous
Expected outcomeAsked to input again
Test no6
DescriptionTest rejected input - above maximum
Test data100, yes
Test typeErroneous
Expected outcomeAsked to input again
Test no7
DescriptionTest rejected input - not a number
Test dataten, yes
Test typeErroneous
Expected outcomeAsked to input again

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