Worked solution from the Data Types and Structures Paper 2 Problem-solving and Programming booklet, Part 2 of 4.
The highest score is 5 × 3 + 4 × 5 = 35, so the array needs indexes 0 to 35.
DECLARE CheckTotal : ARRAY[0:35] OF BOOLEAN
DECLARE Index : INTEGER
FOR Index ← 0 TO 35
CheckTotal[Index] ← FALSE
NEXT IndexCheckTotal array declared [1]
Loop counter declared [1]
Loop with correct syntax and 36 passes (0 to 35) [1]
Each array element assigned FALSE [1]
Easy questions score 0, 3, 6 ... 15 (step 3). Hard questions score 0, 5, ... 20 (step 5). The total is the two added.
DECLARE EasyQ, HardQ : INTEGER
FOR EasyQ ← 0 TO 15 STEP 3
FOR HardQ ← 0 TO 20 STEP 5
CheckTotal[HardQ + EasyQ] ← TRUE
NEXT HardQ
NEXT EasyQEasyQ starts at 0 [1]
EasyQ STEP 3 [1]
HardQ loop ends at 20 [1]
HardQ STEP 5 [1]
Index is HardQ + EasyQ (or EasyQ + HardQ) [1]
Write the steps in words:
Step 1: check that the score is between 0 and 35 [1]
Step 2: if it is not, return FALSE [1]
Step 3: use the score as the index into CheckTotal [1]
Step 4: return the value stored at that index (TRUE or FALSE) [1]
▶ 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.