2210/23/O/N/22 question 2: worked solution (October/November 2022, paper 23)
Show as plain textHide plain text
Cambridge O Level Computer Science 2210 · 8.2 Arrays Worked solution from the Programming Paper 2 Algorithms, Programming and Logic booklet, Part 2 of 3. Q47 2210/23/O/N/22 original Q2 Structured · 9 marks Worked solution (a) Fill each gap so the code does what the bullet points say. Line 01: 50 (the array has 50 elements, so the loop must reach 50) [1] Line 08: Value > 50 (the valid range is 35 to 50, so reject anything above 50) [1] Line 12: Reading[Value] + 1 (add 1 to the count for this value) [1] Line 18: INPUT Value (read the next reading inside the loop) [1] Line 23: Reading[Count] (output how many times this value was input) [1] Line 24: Count + 1 (move on to the next value) [1] (b) Count down from the highest value instead of up from the lowest. Change these places: Line 21: set Count to 50 instead of 35 [1] Line 24: subtract 1 from Count (Count ← Count - 1) [1] Line 25: change the end test to UNTIL Count < 35 (or Count = 34) [1] A FOR loop from 50 TO 35 STEP -1 (with lines 22 and 24 removed) also scores. KEY IDEA To go from the highest value down, start the counter at the top, subtract 1 each time and stop below the lowest value. TOTAL 9 marks Official mark scheme VIDEO ▶ Topic lesson A lesson on this topic · by Craig'n'Dave. Tap the picture to open it on YouTube.