2210/22/M/J/23 question 11: worked solution (May/June 2023, paper 22)

Show as plain text

Cambridge O Level Computer Science 2210 · 8.1 Programming concepts Worked solution from the Programming Paper 2 Algorithms, Programming and Logic booklet, Part 1 of 3. Q21 2210/22/M/J/23 original Q11 Structured · 7 marks Worked solution (a) DECLARE P : STRING DECLARE Q : CHAR P ← "The world" Q ← 'W' Any two correct lines [2] (b) 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. (c) P becomes THE WORLD. T = 1, H = 2, E = 3, space = 4, W = 5. Write: 5 [1] KEY IDEA Loop through the string one character at a time with SUBSTRING and keep the counter when the character matches. TOTAL 7 marks Official mark scheme VIDEO ▶ Whole paper Video solution of the whole paper · by CS BY AQIB KHAN. Tap the picture to open it on YouTube.