Cambridge AS Level Computer Science 9618 · 11.2 Constructs

Q54 · 9618/21/O/N/24 Q2

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

Q549618/21/O/N/24original Q2Structured · 6 marks
Question 2 from 9618/21/O/N/24

Worked solution

Add 1 to the seconds. When the seconds reach 60, reset them and carry into the minutes, then the hours:

PROCEDURE Tick()
    SS ← SS + 1
    IF SS = 60 THEN
        SS ← 0
        MM ← MM + 1
        IF MM = 60 THEN
            MM ← 0
            HH ← HH + 1
            IF HH = 24 THEN
                HH ← 0
                CALL NewDay()
            ENDIF
        ENDIF
        CALL CheckAlarm()
    ENDIF
ENDPROCEDURE

SS increased by 1 each call [1]

CheckAlarm() called when SS has just been set to 0 [1]

Test for SS = 60 [1]

SS set to 0 and MM increased by 1 [1]

When MM reaches 60, MM set to 0 and HH increased by 1 [1]

When HH reaches 24, HH set to 0 and NewDay() called [1]

KEY IDEANested IF tests carry a count over into the next unit when it reaches its limit.
TOTAL 6 marks

Official mark scheme

Mark scheme for 9618/21/O/N/24 question 2
VIDEO
▶ Whole paper

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