9618/23/M/J/24 question 5: worked solution (May/June 2024, paper 23)
Show as plain textHide 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. Q52 9618/23/M/J/24 original Q5 Structured · 6 marks Worked solution (a) Write: a count-controlled loop (FOR ... NEXT) [1] because the number of iterations is known (1000) [1] (b) Explain the problem, then give the fix: The functions return the same value every time they are called [1] ...because Label does not change inside the loop, so almost all 1000 calls repeat the same work [1] Fix: before the loop, store FormatA(Label) and FormatB(Label) in two local variables [1] Use these variables in the CASE clauses in place of the function calls [1] KEY IDEA Do any calculation whose result never changes once, before the loop, and use the stored value inside it. TOTAL 6 marks Official mark scheme VIDEO ▶ Starts at Q5 (38:53) Starts at Q5 (38:53) · by Pseudocode Pro. Tap the picture to open it on YouTube.