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

Q51 · 9618/22/O/N/24 Q5

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

Q519618/22/O/N/24original Q5Structured · 7 marks
Question 5 from 9618/22/O/N/24

Worked solution

(a)

Any three of these four statements, each with its reason:

Statement: Count ← INT(100 / Number) can fail if Number is 0, which is a divide by zero [1]

Statement: Index ← Data[Number] can fail if Number is outside the array range 1 to 100 (or the lower bound) [1]

Statement: ReturnValue ← TO_UPPER(RIGHT(Label, Count)) can fail if Count is negative or larger than the length of Label [1]

Another accepted statement: RETURN RetVal fails because RetVal does not exist (the variable is called ReturnValue). Only three marks at most.

(b)

Write:

Construct: a loop (pre-condition or post-condition, such as WHILE or REPEAT) [1]

Explanation: the condition to end the loop is never met, so it repeats forever [1]

(c)

Use one IF statement. Index MOD 2 is 0 or 1, so ELSE covers 1:

IF Index MOD 2 = 0 THEN
    ReturnValue ← TO_UPPER(RIGHT(Label, Count))
ELSE
    ReturnValue ← "****"
ENDIF

IF ... THEN ... ELSE ... ENDIF structure [1]

Correct test and both assignments in the right branches [1]

KEY IDEARun-time errors come from impossible actions, such as dividing by zero or using an index outside an array, and endless loops freeze a program.
TOTAL 7 marks

Official mark scheme

Mark scheme for 9618/22/O/N/24 question 5
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.