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

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. Q55 9618/22/O/N/24 original Q4 Structured · 6 marks 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 IDEA Convert the time to milliseconds, add it to Tick, then loop until Tick reaches each target value. TOTAL 6 marks Official mark scheme VIDEO ▶ Whole paper Video solution of the whole paper · by Papersdock. Tap the picture to open it on YouTube.