Cambridge O Level Computer Science 2210 · 7.7 Trace tables

Q64 · 2210/22/O/N/25 Q5

Worked solution from the Algorithm design and problem-solving Paper 2 Algorithms, Programming and Logic booklet, Part 6 of 8.

Q642210/22/O/N/25original Q5Structured · 13 marks
Question 5 from 2210/22/O/N/25

Worked solution

(a)

Follow the flowchart one input at a time. 7686 is stored in the first empty place. Face is already in CodeStore[3]. Speed has 5 characters. 432U fills the last place, then Count reaches 7.

CodeStoreCount[1][2][3][4][5][6]OUTPUT
aBcd1532Face63q8
7686FALSE1
2
3
4
TRUE57686
6
FaceFALSE1
2
3Code used before
SpeedLength must be 4
432UFALSE1
2
3
4
5
TRUE6432U
7CodeStore full

Code column correct [1]

Store column correct [1]

Count column correct [1]

CodeStore[1] to [4] left unchanged [1]

CodeStore[5] = 7686 and CodeStore[6] = 432U [1]

OUTPUT column correct (Code used before, Length must be 4, CodeStore full) [1]

(b)

Write three of these points:

It checks that the code input is 4 characters long [1]

It checks the code against the codes already in the array to see if it has been used before [1]

If it passes the checks, it stores the code in the lowest empty place in the array [1]

Also accepted: it checks that the code store is not full and outputs a message when it is full.

(c)

Declare the array and a counter, then use a loop to set all six places to the empty string.

DECLARE CodeStore : ARRAY[1:6] OF STRING
DECLARE Index : INTEGER
FOR Index ← 1 TO 6
    CodeStore[Index] ← ""
NEXT Index

Array declared with the correct name and data type [1]

Loop counter declared [1]

A loop that runs six times [1]

Every element set to "" using the counter as the index [1]

Any type of loop is accepted.

KEY IDEATrace a flowchart one box at a time, and use a loop with a counter to set up every element of an array.
TOTAL 13 marks

Official mark scheme

Mark scheme for 2210/22/O/N/25 question 5
VIDEO
▶ Whole paper

Video solution of the whole paper · by MAK CS. 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.