Worked solution from the Data Types and Structures Paper 2 Problem-solving and Programming booklet, Part 1 of 4.
Declare a record with one field for each row of the table. Use DATE for Born and REAL for Attendance.
TYPE Employee
DECLARE EmployeeNumber : INTEGER
DECLARE Name : STRING
DECLARE Department : STRING
DECLARE Born : DATE
DECLARE Attendance : REAL
ENDTYPETYPE Employee and ENDTYPE [1]
Fields EmployeeNumber (INTEGER), Name (STRING) and Department (STRING) [1]
Field Born (DATE) [1]
Field Attendance (REAL) [1]
DECLARE Staff : ARRAY[1:500] OF Employee
ARRAY[1:500] (500 elements) [1]
OF Employee (the record type) [1]
Write: so that unused elements can be recognised when processing or searching, otherwise they may hold old or unexpected data. [1]
Write one: set a field to an impossible value, for example EmployeeNumber = -1 (or less than 1), an empty string for Name, or an attendance below 0. [1]
Loop through all 500 records, skip unused ones, test Attendance and output two fields.
PROCEDURE Absentees()
DECLARE Index : INTEGER
FOR Index ← 1 TO 500
IF Staff[Index].EmployeeNumber <> -1 THEN
IF Staff[Index].Attendance <= 90.00 THEN
OUTPUT Staff[Index].EmployeeNumber
OUTPUT Staff[Index].Name
ENDIF
ENDIF
NEXT Index
ENDPROCEDUREProcedure heading and ending, and the loop counter declared [1]
Loop through the 500 elements, with an attempt to skip unused records [1]
Attendance tested with <= 90 inside the loop [1]
If so, EmployeeNumber and Name output [1]
▶ Whole paper
Video solution of the whole paper · by Digify ID. 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.