Worked solution from the Programming Paper 2 Problem-solving and Programming booklet, Part 1 of 3.
Look at each example for IF/CASE (selection), FOR/WHILE (iteration) and CALL or a function call (subroutine):
| Pseudocode example | Selection | Iteration | Subroutine |
|---|---|---|---|
| IF Status = FALSE THEN ... FOR ... CALL Reset(Count) ... NEXT Count ... ENDIF | ✓ | ✓ | ✓ |
| OTHERWISE : Status ← TRUE | ✓ | ||
| WHILE AllDone() = TRUE | ✓ | ✓ | |
| 30 : NextChar ← 'X' | ✓ |
Row 1 correct [1]
Row 2 correct [1]
Row 3 correct [1]
Row 4 correct [1]
| Variable | Example data value | Data type |
|---|---|---|
| Result | 5.42 | REAL |
| MonthLetter | "JFMAMJJASOND" | STRING |
| Birthday | 15/11/2009 | DATE |
REAL [1]
STRING [1]
DATE [1]
Work each one out:
INT(5.42) = 5, and 5 + 1 = 6, which is not greater than 6, so FALSE.
LENGTH of the string = 12, so NUM_TO_STR gives "12".
Result + "3.2" adds a number to a string, so it is an error.
MONTH(Birthday) = 11, and 11 − 2 = 9. The 9th letter is S.
| Expression | Evaluates to |
|---|---|
| INT(Result) + 1 > 6 | FALSE |
| NUM_TO_STR(LENGTH(MonthLetter)) | "12" |
| NUM_TO_STR(Result + "3.2") | ERROR |
| MID(MonthLetter, MONTH(Birthday) − 2, 1) | "S" |
FALSE [1]
"12" [1]
ERROR [1]
"S" [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.