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

Q36 · 9618/22/M/J/22 Q5

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

Q369618/22/M/J/22original Q5Structured · 10 marks
Question 5 from 9618/22/M/J/22

Worked solution

(a)

The loop is WHILE … ENDWHILE, so the test is at the start.

Type: pre-condition loop (a WHILE loop) [1]

Condition: the loop ends when the input value (ThisNum) is equal to zero [1]

(b)

Run each input through the loop. Only write the values that change.

ThisNumThisCharCountACountBFlagOUTPUT
010TRUE
12'1'1
24'2'
57'5'"Ignored"
43'4'9FALSE
56'5'4
22'2'TRUE"Flip"
31'3'8
32'3'7
47'4'6FALSE
99'9'TRUE"Flip"
04

Columns ThisNum and ThisChar correct [1]

Rows for 12, 24 and 57 correct (CountA 1, then "Ignored") [1]

Rows for 43 and 56 correct (CountB 9, Flag FALSE, CountA 4) [1]

Rows for 22 and 31 correct (Flag TRUE, "Flip", CountB 8) [1]

Rows for 32 and 47 correct (CountB 7, then 6, Flag FALSE) [1]

Rows for 99 and 0 correct (Flag TRUE, "Flip", final OUTPUT 4) [1]

(c)

Integration testing means:

Modules that have already been tested individually [1]

are combined into one (sub) program which is then tested as a whole [1]

KEY IDEADry run one input at a time, updating only the variables that change, and remember that a WHILE loop tests its condition before each pass.
TOTAL 10 marks

Official mark scheme

Mark scheme for 9618/22/M/J/22 question 5
VIDEO
▶ Whole paper

Video solution of the whole paper · by Awab Aqib. 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.