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

Q48 · 9618/21/M/J/24 Q5

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

Q489618/21/M/J/24original Q5Structured · 8 marks
Question 5 from 9618/21/M/J/24

Worked solution

(a)

Dry run line by line. Format is "X3Y2W4", so Count is 1, 3 and 5. The first row shows the starting values.

CountCLIndexResultData[1]Data[2]Data[3]
"**""aaaaaa""bbbbbb""cccccc"
1'X'31
"AAAAAA""AAA"
3'Y'22
"bbbbbb""bb"
5'W'43
"bbbb"

For W no CASE branch runs, so Result stays "bbbbbb" and Data[3] becomes the first 4 letters of it.

Starting values row correct [1]

Count column 1, 3, 5 correct [1]

C column 'X', 'Y', 'W' correct [1]

L and Index columns correct (3, 2, 4 and 1, 2, 3) [1]

Result and Data[1] for Count = 1 correct [1]

Result, Data[2] and Data[3] for Counts 3 and 5 correct [1]

(b)(i)

Write: OTHERWISE : CALL Error(C) [1]

(b)(ii)

Write: after the 'Z' clause and before ENDCASE [1]

KEY IDEATrace one line at a time and write a value only when it changes; OTHERWISE catches every value the other CASE branches miss.
TOTAL 8 marks

Official mark scheme

Mark scheme for 9618/21/M/J/24 question 5
VIDEO
▶ Starts at Q5 (40:00)

Starts at Q5 (40:00) · by Pseudocode Pro. 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.