Worked solution from the Programming Paper 2 Problem-solving and Programming booklet, Part 3 of 3.
Write any two of these benefits:
The code can be called whenever it is needed [1]
A later change to the algorithm is made once only, so the program is easier to maintain [1]
Less code, with no duplication (or the algorithm is designed, coded and tested once). Only two of these points can score.
Say how the repeated code is turned into a module:
Create a module (function, procedure or subroutine) from the algorithm code [1]
Replace the old code in every place with a call to the module [1]
Pass the data in as parameters (or use global variables) and return the result (or assign it to a global variable or a BYREF parameter). Create local variables if needed. Any one of these points earns the last mark [1]
Choose the built-in function or operator from the insert that gives each value:
| Pseudocode expression | Evaluates to |
|---|---|
| MID("Random", 2, 3) | "and" |
| 5 + DAY(10/11/2023) | 15 |
| IS_NUM("45000") | TRUE |
| (20 MOD 3) + 1 | 3 |
MID correct [1]
DAY correct [1]
IS_NUM correct [1]
MOD correct [1]
▶ Starts at Q1 (0:27)
Starts at Q1 (0:27) · 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.