Cambridge AS Level Computer Science 9618 · 11.2 Constructs

Q52 · 9618/23/M/J/24 Q5

Worked solution from the Programming Paper 2 Problem-solving and Programming booklet, Part 2 of 3.

Q529618/23/M/J/24original Q5Structured · 6 marks
Question 5 from 9618/23/M/J/24

Worked solution

(a)

Write: a count-controlled loop (FOR ... NEXT) [1]

because the number of iterations is known (1000) [1]

(b)

Explain the problem, then give the fix:

The functions return the same value every time they are called [1]

...because Label does not change inside the loop, so almost all 1000 calls repeat the same work [1]

Fix: before the loop, store FormatA(Label) and FormatB(Label) in two local variables [1]

Use these variables in the CASE clauses in place of the function calls [1]

KEY IDEADo any calculation whose result never changes once, before the loop, and use the stored value inside it.
TOTAL 6 marks

Official mark scheme

Mark scheme for 9618/23/M/J/24 question 5
VIDEO
▶ Starts at Q5 (38:53)

Starts at Q5 (38:53) · 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.