9618/22/O/N/23 question 2: worked solution (October/November 2023, paper 22)
Show as plain textHide plain text
Cambridge AS Level Computer Science 9618 · 9.2 Algorithms Worked solution from the Algorithm Design and Problem-solving Paper 2 Problem-solving and Programming booklet, Part 2 of 2. Q31 9618/22/O/N/23 original Q2 Structured · 7 marks Worked solution (a) Draw the flowchart from START, using these shapes in order: Process box: set Total to 0 (and a flag or similar to show 27 has not been seen) [1] Input parallelogram: INPUT a number, then a decision diamond: is the number 27? If No, go back to the input. Only the first 27 switches summing on [1] After 27 is found, a loop that keeps going until 0 is input: INPUT Number, then decision: is Number = 0? [1] If No, a process box: Total ← Total + Number, then loop back to the input [1] If Yes (0 input), output parallelogram: OUTPUT Total, then END [1] (b) Name: a conditional loop (a pre-condition WHILE loop or a post-condition REPEAT loop) [1] Justification: the number of iterations is not known in advance, because the loop only stops when 0 is input [1] KEY IDEA When a loop ends because of a special input rather than a set count, use a conditional loop. TOTAL 7 marks Official mark scheme VIDEO ▶ Starts at Q2 (8:53) Starts at Q2 (8:53) · by Pseudocode Pro. Tap the picture to open it on YouTube.