Cambridge AS Level Computer Science 9618 · 11.2 Constructs

Q42 · 9618/22/O/N/22 Q5

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

Q429618/22/O/N/22original Q5Structured · 4 marks
Question 5 from 9618/22/O/N/22

Worked solution

Work out when each CALL runs. Sub1 runs when A, B and C are all TRUE. Sub2 runs when A and B are TRUE and C is FALSE. Sub3 runs when A is FALSE and C is FALSE (B can be either, because both paths call Sub3). Sub4 runs when A is FALSE and C is TRUE. Write:

IF A AND B AND C THEN
    CALL Sub1()
ENDIF
IF A AND B AND NOT C THEN
    CALL Sub2()
ENDIF
IF NOT A AND NOT C THEN
    CALL Sub3()
ENDIF
IF NOT A AND C THEN
    CALL Sub4()
ENDIF

First IF...THEN...ENDIF correct: A AND B AND C calls Sub1() [1]

Second correct: (A AND B) AND NOT C calls Sub2() [1]

Third correct: (NOT A) AND (NOT C) calls Sub3(), with B left out because it does not matter [1]

Fourth correct: (NOT A) AND C calls Sub4(), with B left out [1]

KEY IDEATrace each CALL back to the conditions that reach it, then drop any variable that does not change the outcome.
TOTAL 4 marks

Official mark scheme

Mark scheme for 9618/22/O/N/22 question 5
VIDEO
▶ Whole paper

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