9618/23/O/N/25 question 5: worked solution (October/November 2025, paper 23)

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. Q64 9618/23/O/N/25 original Q5 Structured · 8 marks Worked solution (a) Run the procedure one line at a time. Index goes 1, 2, 3, 4, 7, 4, 1, 3, 4. At CaseVar 5 the OTHERWISE sets Count to 20. The loop ends when Count reaches 22. Index CaseVar Count Num [1] Num [2] Num [3] Num [4] 1 0 1 2 5 3 1 2 1 2 3 5 20 4 3 7 19 6 4 6 20 1 2 3 22 3 4 First three rows correct: starting values, CaseVar 1, then Index 2, Count 1 and Num [1] = 2 [1] Index column correct from Index 3 downwards [1] CaseVar column correct from 5 downwards [1] Count column correct from 20 downwards [1] Num [4] = 6 when Index is 7, and Num [1] = 3 when Index is 3 the second time [1] (b)(i) Clauses for CaseVar 1 and 2 . [1] (b)(ii) Both clauses add Index to the element. The only difference is the step, which equals CaseVar, so use CaseVar instead of the numbers: 1 TO 2 : Num[Index] ← Num[Index] + Index Index ← Index + CaseVar Count ← Count + CaseVar CaseVar used instead of the fixed numbers 1 and 2 [1] Whole clause correct [1] KEY IDEA Trace one line at a time and write a value only when it changes; clauses that differ only by a number can be merged using the variable. TOTAL 8 marks Official mark scheme VIDEO ▶ Topic lesson A lesson on this topic · by ZAINEMATICS. Tap the picture to open it on YouTube.