Cambridge AS Level Computer Science 9618 · 11.2 Constructs

Q55 · 9618/22/O/N/24 Q4

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

Q559618/22/O/N/24original Q4Structured · 6 marks
Question 4 from 9618/22/O/N/24

Worked solution

Tick goes up by 1000 every second. Work out the Tick values for the warning time and the end time, then wait for each one with a loop.

PROCEDURE Timer(Mins, Secs : INTEGER)
    DECLARE WarningTick, EndTick : INTEGER
    EndTick ← Tick + 1000 * ((Mins * 60) + Secs)
    WarningTick ← EndTick - (30 * 1000)
    REPEAT
        //do nothing
    UNTIL Tick = WarningTick
    OUTPUT "30 seconds to go"
    REPEAT
        //do nothing
    UNTIL Tick = EndTick
    OUTPUT "The time is up!"
ENDPROCEDURE

Procedure heading with the two parameters, and ENDPROCEDURE [1]

Attempt to work out the total time / EndTick / WarningTick from Tick [1]

Correct calculation of both EndTick and WarningTick (minutes × 60 + seconds, × 1000, 30 seconds earlier for the warning) [1]

A sensible design: two separate loops (warning time, then end time), or one loop with an IF for the warning [1]

The loop design is completely correct (warning message comes first, only once, then the final message) [1]

Both messages output: "30 seconds to go" and "The time is up!" [1]

KEY IDEAConvert the time to milliseconds, add it to Tick, then loop until Tick reaches each target value.
TOTAL 6 marks

Official mark scheme

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