Worked solution from the Algorithm design and problem-solving Paper 2 Algorithms, Programming and Logic booklet, Part 7 of 8.
Compare each line with what the algorithm should do. Write any five of these:
Line 01: Names holds text, so ARRAY[1:500] OF STRING [1]
Line 09: Total must start at zero, so Total ← 0 [1]
Line 11: the index must change each time, so INPUT Names[Counter] [1]
Line 13: the height must be added to the total, so Total ← Total + Heights[Counter] [1]
Line 20: the output must be the shortest height, so OUTPUT "The shortest height is ", Shortest (or Heights[Index]) [1]
Use the ROUND function with 1 decimal place around the calculation:
OUTPUT ROUND(Total / 500, 1)
OUTPUT with the correct average calculation (Total / 500, or an Average variable) [1]
ROUND used with 1 as the number of decimal places [1]
Add a second check beside the shortest check, as follows:
Declare a new variable such as Tallest at the start [1]
Set Tallest to a low number such as 0 before the loop [1]
Inside the loop, after the height is input, add an IF to compare Heights[Counter] with Tallest [1]
If the height is larger, set Tallest to Heights[Counter] [1]
After the loop ends, OUTPUT Tallest. This also scores, but the maximum for this part is 4.
▶ Topic lesson
A lesson on this topic · by Mr Bulmer's Learning Zone. Tap the picture to open it on YouTube.
Solutions follow the official Cambridge mark schemes; marks are shown in grey. Videos are from other YouTube channels. Paper codes read component / series / year: M/J = May/June, O/N = October/November. Past-paper questions © UCLES, reproduced for classroom practice.