Cambridge AS Level Computer Science 9618 · 11.2 Constructs

Q39 · 9618/22/O/N/21 Q4

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

Q399618/22/O/N/21original Q4Structured · 11 marks
Question 4 from 9618/22/O/N/21

Worked solution

(a)

QuestionAnswer
Line with a variable being incremented19
Type of loop structurepre-condition
Number of functions used3
Parameters passed to STR_TO_NUM()1
Procedure other than Check()Result

Line 19 (21 or 23 also accepted) [1]

Pre-condition loop (WHILE) [1]

3 functions: LENGTH, MID and STR_TO_NUM [1]

1 parameter [1]

Result [1]

(b)

Write three of these features:

Meaningful variable names [1]

Indentation / white space / blank lines [1]

Capital letters for keywords [1]

(c)(i)

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

Justification: the number of repeats is known, as it is the length of InString [1]

(c)(ii)

The FOR loop sets and adds to Index itself, so the Index ← 1 line and the Index ← Index + 1 line are not needed.

Write 15 and 23 [1]

KEY IDEAUse a count-controlled FOR loop when the number of repeats is known in advance.
TOTAL 11 marks

Official mark scheme

Mark scheme for 9618/22/O/N/21 question 4
VIDEO
▶ Whole paper

Video solution of the whole paper · by CS BY AQIB KHAN. 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.