9618/21/O/N/24 question 2: worked solution (October/November 2024, paper 21)

Show as plain text

Cambridge AS Level Computer Science 9618 · 11.2 Constructs Worked solution from the Programming Paper 2 Problem-solving and Programming booklet, Part 2 of 3. Q54 9618/21/O/N/24 original Q2 Structured · 6 marks 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 IDEA Nested IF tests carry a count over into the next unit when it reaches its limit. TOTAL 6 marks Official mark scheme VIDEO ▶ Whole paper Video solution of the whole paper · by Pseudocode Pro. Tap the picture to open it on YouTube.