9618/23/O/N/24 question 2: worked solution (October/November 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. Q57 9618/23/O/N/24 original Q2 Structured · 7 marks Worked solution (a) Use a loop that runs 100 times, add a number to the total only when it is above zero, and output the total after the loop. DECLARE Count, Total, NextNumber : INTEGER Total ← 0 FOR Count ← 1 TO 100 OUTPUT "Input an integer value" INPUT NextNumber IF NextNumber > 0 THEN Total ← Total + NextNumber ENDIF NEXT Count OUTPUT Total All variables declared [1] Loop that runs 100 times [1] Prompt and input a value inside the loop [1] Test for the value being greater than 0 inside the loop [1] Total updated by adding the value inside the loop [1] The output of Total after the loop also scores. Any five of the six points get the 5 marks. (b) Write: Construct: iteration (repetition) [1] Use: to loop through all 100 inputs, so the code runs 100 times [1] Alternative: selection , used to test whether each value input is positive. KEY IDEA A count-controlled loop with a selection inside it, adding to a total that was set to zero first. TOTAL 7 marks Official mark scheme VIDEO ▶ Whole paper Video solution of the whole paper · by Zafar Ali Khan (ZAK). Tap the picture to open it on YouTube.