9618/23/M/J/22 question 5: worked solution (May/June 2022, paper 23)

Show as plain text

Cambridge AS Level Computer Science 9618 · 10.1 Data Types and Records Worked solution from the Data Types and Structures Paper 2 Problem-solving and Programming booklet, Part 1 of 4. Q2 9618/23/M/J/22 original Q5 Structured · 12 marks 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 IDEA A 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 VIDEO ▶ Whole paper Video solution of the whole paper · by Digify ID. Tap the picture to open it on YouTube.