9618/22/M/J/23 question 5: worked solution (May/June 2023, paper 22)

Show as 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. Q44 9618/22/M/J/23 original Q5 Structured · 8 marks Worked solution (a) The procedure changes the value it is given, and the loop uses that same variable. Num is passed by reference (BYREF), but it should have been passed by value [1] So when DisplaySqrt() changes ThisNum (line 52), the original variable Num is changed too [1] The new value (the square root) is then used by the loop in lines 40 to 43, so Num no longer goes 1, 2, 3 ... [1] (b) The code does not break any rule of the language, so the compiler sees nothing wrong. Write: there are no syntax errors , the rules of the language have not been broken (it is a logic / design error) [1] (c) Write any three of these uses of an IDE: Set a breakpoint so the program stops at a chosen line [1] Single-step through the program one line or statement at a time [1] Check the value of Num or ThisNum in a watch / report window as it changes [1] (d) Write: turn the statement into a comment (put the comment symbol in front of it) [1] Another accepted way is to change it into a string literal that is assigned to a variable or output. KEY IDEA A BYREF parameter changes the caller's variable, so use BYREF only when you want the original changed; design errors compile fine. TOTAL 8 marks Official mark scheme VIDEO ▶ Starts at Q5 (31:40) Starts at Q5 (31:40) · by Pseudocode Pro. Tap the picture to open it on YouTube.