Worked solution from the Data Types and Structures Paper 2 Problem-solving and Programming booklet, Part 1 of 4.
Declare a TYPE with a field for each row of the table. StudentID and Email are strings, the clubs are integers:
TYPE Student
DECLARE StudentID : STRING
DECLARE Email : STRING
DECLARE Club_1 : INTEGER
DECLARE Club_2 : INTEGER
DECLARE Club_3 : INTEGER
ENDTYPETYPE and ENDTYPE [1]
StudentID and Email declared as STRING [1]
All three Club fields declared as INTEGER [1]
Declare an array of 3000 elements of the record type:
DECLARE Membership : ARRAY[1:3000] OF Student
ARRAY[1:3000] [1]
OF Student [1]
Write: put a value outside the normal range in a field, for example an empty string in StudentID (or Email), or a club number outside 1 to 99 [1]
Write: store a number outside the range 1 to 99, for example 0 [1]
Prompt and input the club number, loop through all 3000 elements, and test all three club fields:
PROCEDURE GetIDs()
DECLARE Index, ThisClub, Count : INTEGER
OUTPUT "Please input the club number: "
INPUT ThisClub
Count ← 0
FOR Index ← 1 TO 3000
IF Membership[Index].Club_1 = ThisClub OR Membership[Index].Club_2 = ThisClub OR Membership[Index].Club_3 = ThisClub THEN
Count ← Count + 1
OUTPUT Membership[Index].StudentID
ENDIF
NEXT Index
OUTPUT "There are ", Count, " students in the club"
ENDPROCEDURECount declared and set to 0 [1]
Prompt and input of the club number before the loop [1]
Loop through all 3000 elements [1]
Compares one club field with the number input [1]
Compares all three club fields with the number input [1]
If found, StudentID output and Count increased [1]
Final count output after the loop [1]
Only 6 marks can be scored if the procedure heading and ending are missing or wrong.
▶ Whole paper
Video solution of the whole paper · by CS BY AQIB KHAN. 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.