Cambridge O Level Computer Science 2210 · 8.2 Arrays

Q47 · 2210/23/O/N/22 Q2

Worked solution from the Programming Paper 2 Algorithms, Programming and Logic booklet, Part 2 of 3.

Q472210/23/O/N/22original Q2Structured · 9 marks
Question 2 from 2210/23/O/N/22

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 IDEATo 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

Mark scheme for 2210/23/O/N/22 question 2
VIDEO
▶ Topic lesson

A lesson on this topic · by Craig'n'Dave. Tap the picture to open it on YouTube.

Solutions follow the official Cambridge mark schemes; marks are shown in grey. Videos are from other YouTube channels. Paper codes read component / series / year: M/J = May/June, O/N = October/November. Past-paper questions © UCLES, reproduced for classroom practice.