Worked solution from the Programming Paper 2 Algorithms, Programming and Logic booklet, Part 1 of 3.
DECLARE P : STRING DECLARE Q : CHAR P ← "The world" Q ← 'W'
Any two correct lines [2]
Change P to upper case, then check each character in turn until Q is found.
P ← UCASE(P)
Counter ← 1
Position ← 0
REPEAT
IF SUBSTRING(P, Counter, 1) = Q
THEN
Position ← Counter
ENDIF
Counter ← Counter + 1
UNTIL Position <> 0 OR Counter > LENGTH(P)P converted to upper case with UCASE [1]
Length of P found with LENGTH [1]
Loop that checks each position in turn [1]
SUBSTRING used and the counter stored in Position when found [1]
Other correct loops score too.
P becomes THE WORLD. T = 1, H = 2, E = 3, space = 4, W = 5.
Write: 5 [1]
▶ 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.