Programming · 4 question types
Past paper frequency (2018 to 2024)
This topic accounts for approximately 5% of your exam marks.
1D array manipulation with FOR loops appears regularly in Paper 2. 4 to 6 marks.
Example — A parent records the minutes of TV watched by 4 children (Quinn, Lyla, Harry, Elias) over 5 weekdays (Monday to Friday). The data is held in a 2D array called minsWatched indexed with [Day, Child], where days 1 to 5 are Monday to Friday and children 1 to 4 are Quinn, Lyla, Harry and Elias respectively.
| 1 (Quinn) | 2 (Lyla) | 3 (Harry) | 4 (Elias) | |
|---|---|---|---|---|
| 1 Monday | 34 | 67 | 89 | 78 |
| 2 Tuesday | 56 | 43 | 45 | 56 |
| 3 Wednesday | 122 | 23 | 34 | 45 |
| 4 Thursday | 13 | 109 | 23 | 90 |
| 5 Friday | 47 | 100 | 167 | 23 |
Now answer:
OUTPUT minsWatched[2, 2] → outputs 43.OUTPUT minsWatched[5, 3] → outputs 167.OUTPUT minsWatched[3, 1] → outputs 122.Many questions of this kind appear in past papers. The trick is to remember the row-then-column order shown in the question and not to swap them by accident.
FOR Child ← 1 TO 4
ChildTotal ← 0
FOR Day ← 1 TO 5
ChildTotal ← ChildTotal + minsWatched[Day, Child]
NEXT Day
OUTPUT "Child ", Child, ": ", ChildTotal, " minutes"
NEXT Child
For Quinn (Child 1): 34 + 56 + 122 + 13 + 47 = 272 minutes.
DECLARE MaxTotal : INTEGER
DECLARE MaxDay : INTEGER
MaxTotal ← 0
MaxDay ← 0
FOR Day ← 1 TO 5
DayTotal ← 0
FOR Child ← 1 TO 4
DayTotal ← DayTotal + minsWatched[Day, Child]
NEXT Child
IF DayTotal > MaxTotal THEN
MaxTotal ← DayTotal
MaxDay ← Day
ENDIF
NEXT Day
OUTPUT "Highest day was ", MaxDay, " with ", MaxTotal, " minutes total"