Worked solution from the Programming Paper 2 Problem-solving and Programming booklet, Part 1 of 3.
Decide what each statement does: FOR and UNTIL repeat, IF selects, READFILE and WRITEFILE are input/output:
| Pseudocode example | Selection | Iteration | Input/Output |
|---|---|---|---|
| FOR Index ← 1 TO 10 ... NEXT Index | ✓ | ||
| WRITEFILE ThisFile, "**" | ✓ | ||
| UNTIL Level > 25 | ✓ | ||
| IF Mark > 74 THEN READFILE ... ENDIF | ✓ | ✓ |
FOR row: iteration only [1]
WRITEFILE row: input/output only [1]
UNTIL row: iteration only [1]
IF row: selection and input/output [1]
Choose a function that gives the data type on the left of each line:
| Expression | Function(s) |
|---|---|
| MyInt ← ... (3.1415926) | INT |
| MyChar ← ... ("Elwood", 3, 1) | MID |
| MyString ← ... ( ... (27.509)) | NUM_TO_STR ( INT ( ... ) ) |
| MyInt ← ... ( ... ("ABC123", 3)) | STR_TO_NUM ( RIGHT ( ... ) ) |
INT [1]
MID [1]
MyString ← NUM_TO_STR(INT(27.509)) [1]
MyInt ← STR_TO_NUM(RIGHT("ABC123", 3)) [1]
Other valid answers also score: CHR(INT(27.509)), TO_UPPER(NUM_TO_STR(27.509)), LENGTH(RIGHT("ABC123", 3)) or LENGTH(LEFT("ABC123", 3)).
Write both points:
Way of documenting: an identifier table [1]
One piece of information: what (each) variable is used for (its purpose), or an example value or initial value [1]
▶ Starts at Q1 (0:24)
Starts at Q1 (0:24) · 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.