Cambridge AS Level Computer Science 9618 · 12.3 Program Testing and Maintenance

Q33 · 9618/21/M/J/21 Q4

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

Q339618/21/M/J/21original Q4Structured · 10 marks
Question 4 from 9618/21/M/J/21

Worked solution

(a)

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.

NameFlagIndexNewNameThisChar
"∇in∇a∇∇Cup"
TRUE1""
'∇'
"∇"
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"
FALSE11"∇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]

(b)

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]

(c)(i)

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.

(c)(ii)

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]

KEY IDEAIn a trace table update one row per loop pass and only write the values that change; a loop with a known number of repeats should be a FOR loop.
TOTAL 10 marks

Official mark scheme

Mark scheme for 9618/21/M/J/21 question 4
VIDEO
▶ 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.