Worked solution from the Software Development Paper 2 Problem-solving and Programming booklet, Part 3 of 3.
Dry run line by line. Format is "X3Y2W4", so Count is 1, 3 and 5. The first row shows the starting values.
| Count | C | L | Index | Result | Data[1] | Data[2] | Data[3] |
|---|---|---|---|---|---|---|---|
| "**" | "aaaaaa" | "bbbbbb" | "cccccc" | ||||
| 1 | 'X' | 3 | 1 | ||||
| "AAAAAA" | "AAA" | ||||||
| 3 | 'Y' | 2 | 2 | ||||
| "bbbbbb" | "bb" | ||||||
| 5 | 'W' | 4 | 3 | ||||
| "bbbb" |
For W no CASE branch runs, so Result stays "bbbbbb" and Data[3] becomes the first 4 letters of it.
Starting values row correct [1]
Count column 1, 3, 5 correct [1]
C column 'X', 'Y', 'W' correct [1]
L and Index columns correct (3, 2, 4 and 1, 2, 3) [1]
Result and Data[1] for Count = 1 correct [1]
Result, Data[2] and Data[3] for Counts 3 and 5 correct [1]
Write: OTHERWISE : CALL Error(C) [1]
Write: after the 'Z' clause and before ENDCASE [1]
▶ Starts at Q5 (40:00)
Starts at Q5 (40:00) · by Pseudocode Pro. 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.