9618/21/M/J/24 question 5: worked solution (May/June 2024, paper 21)
Show as plain textHide plain text
Cambridge AS Level Computer Science 9618 · 12.3 Program Testing and Maintenance Worked solution from the Software Development Paper 2 Problem-solving and Programming booklet, Part 3 of 3. Q48 9618/21/M/J/24 original Q5 Structured · 8 marks Worked solution (a) Dry run line by line. Format is "X3Y2W4", so Count is 1, 3 and 5. The first row shows the starting values. Count C L Index Result Data [1] Data [2] Data [3] " ** " "aaaaaa" "bbbbbb" "cccccc" 1 'X' 3 1 "AAAAAA" "AAA" 3 'Y' 2 2 "bbbbbb" "bb" 5 'W' 4 3 "bbbb" For W no CASE branch runs, so Result stays "bbbbbb" and Data [3] becomes the first 4 letters of it. Starting values row correct [1] Count column 1, 3, 5 correct [1] C column 'X', 'Y', 'W' correct [1] L and Index columns correct (3, 2, 4 and 1, 2, 3) [1] Result and Data [1] for Count = 1 correct [1] Result, Data [2] and Data [3] for Counts 3 and 5 correct [1] (b)(i) Write: OTHERWISE : CALL Error(C) [1] (b)(ii) Write: after the 'Z' clause and before ENDCASE [1] KEY IDEA Trace one line at a time and write a value only when it changes; OTHERWISE catches every value the other CASE branches miss. TOTAL 8 marks Official mark scheme VIDEO ▶ Starts at Q5 (40:00) Starts at Q5 (40:00) · by Pseudocode Pro. Tap the picture to open it on YouTube.