Worked solution from the Algorithm design and problem-solving Paper 2 Algorithms, Programming and Logic booklet, Part 6 of 8.
Follow the flowchart one input at a time. 7686 is stored in the first empty place. Face is already in CodeStore[3]. Speed has 5 characters. 432U fills the last place, then Count reaches 7.
| Code | Store | Count | [1] | [2] | [3] | [4] | [5] | [6] | OUTPUT |
|---|---|---|---|---|---|---|---|---|---|
| aBcd | 1532 | Face | 63q8 | ||||||
| 7686 | FALSE | 1 | |||||||
| 2 | |||||||||
| 3 | |||||||||
| 4 | |||||||||
| TRUE | 5 | 7686 | |||||||
| 6 | |||||||||
| Face | FALSE | 1 | |||||||
| 2 | |||||||||
| 3 | Code used before | ||||||||
| Speed | Length must be 4 | ||||||||
| 432U | FALSE | 1 | |||||||
| 2 | |||||||||
| 3 | |||||||||
| 4 | |||||||||
| 5 | |||||||||
| TRUE | 6 | 432U | |||||||
| 7 | CodeStore full |
Code column correct [1]
Store column correct [1]
Count column correct [1]
CodeStore[1] to [4] left unchanged [1]
CodeStore[5] = 7686 and CodeStore[6] = 432U [1]
OUTPUT column correct (Code used before, Length must be 4, CodeStore full) [1]
Write three of these points:
It checks that the code input is 4 characters long [1]
It checks the code against the codes already in the array to see if it has been used before [1]
If it passes the checks, it stores the code in the lowest empty place in the array [1]
Also accepted: it checks that the code store is not full and outputs a message when it is full.
Declare the array and a counter, then use a loop to set all six places to the empty string.
DECLARE CodeStore : ARRAY[1:6] OF STRING
DECLARE Index : INTEGER
FOR Index ← 1 TO 6
CodeStore[Index] ← ""
NEXT IndexArray declared with the correct name and data type [1]
Loop counter declared [1]
A loop that runs six times [1]
Every element set to "" using the counter as the index [1]
Any type of loop is accepted.
▶ Whole paper
Video solution of the whole paper · by MAK CS. 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.