Worked solution from the Software Development Paper 2 Problem-solving and Programming booklet, Part 3 of 3.
Dry run the function one loop at a time. Flag is TRUE at the start, so the first character is made upper case. Flag becomes FALSE after a letter and TRUE again after a space.
| Name | Flag | Index | NewName | ThisChar |
|---|---|---|---|---|
| "∇in∇a∇∇Cup" | ||||
| TRUE | 1 | "" | ||
| '∇' | ||||
| "∇" | ||||
| 2 | 'i' | |||
| FALSE | "∇I" | |||
| 3 | 'n' | |||
| "∇In" | ||||
| 4 | '∇' | |||
| TRUE | "∇In∇" | |||
| 5 | 'a' | |||
| FALSE | "∇In∇A" | |||
| 6 | '∇' | |||
| TRUE | "∇In∇A∇" | |||
| 7 | '∇' | |||
| "∇In∇A∇∇" | ||||
| 8 | 'C' | |||
| FALSE | "∇In∇A∇∇C" | |||
| 9 | 'u' | |||
| "∇In∇A∇∇Cu" | ||||
| 10 | 'p' | |||
| "∇In∇A∇∇Cup" | ||||
| FALSE | 11 | "∇In∇A∇∇Cup" | 'p' |
Flag column correct [1]
Index column correct [1]
NewName column correct [1]
ThisChar column correct [1]
Final row correct, including Index 11 [1]
The loop runs once for every character in Name, so the number of repeats is known before it starts.
Count-controlled loop (a FOR … NEXT loop) [1]
Justification: the number of iterations is known (it is LENGTH(Name)) [1]
Make the character lower case when it is added after the first letter. Change line 24 (or line 31):
ThisChar ← LCASE(MID(Name, Index, 1))
Modified line that uses LCASE on the character (either line 24 or line 31 version scores) [1]
Accepted alternative: NewName ← NewName & LCASE(ThisChar) on line 31.
Line 26 adds the character to NewName when Flag is TRUE, even when it is another space. Move it inside the IF ThisChar <> SPACECHAR block, so extra spaces met while Flag is TRUE are skipped.
Line number: 26 [1]
New position: move it to after line 27 / after line 28 (inside the IF ThisChar <> SPACECHAR block) [1]
▶ Whole paper
Video solution of the whole paper · by Papersdock. 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.