Cambridge AS Level Computer Science 9618 · 10.1 Data Types and Records

Q2 · 9618/23/M/J/22 Q5

Worked solution from the Data Types and Structures Paper 2 Problem-solving and Programming booklet, Part 1 of 4.

Q29618/23/M/J/22original Q5Structured · 12 marks
Question 5 from 9618/23/M/J/22

Worked solution

(a)(i)

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
ENDTYPE

TYPE Employee and ENDTYPE [1]

Fields EmployeeNumber (INTEGER), Name (STRING) and Department (STRING) [1]

Field Born (DATE) [1]

Field Attendance (REAL) [1]

(a)(ii)

DECLARE Staff : ARRAY[1:500] OF Employee

ARRAY[1:500] (500 elements) [1]

OF Employee (the record type) [1]

(b)(i)

Write: so that unused elements can be recognised when processing or searching, otherwise they may hold old or unexpected data. [1]

(b)(ii)

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]

(c)

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
ENDPROCEDURE

Procedure 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]

KEY IDEAA record type groups different data types under one name, and an array of records is searched with dot notation like Staff[Index].Attendance.
TOTAL 12 marks

Official mark scheme

Mark scheme for 9618/23/M/J/22 question 5
VIDEO
▶ 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.