9618/22/M/J/24 question 3: worked solution (May/June 2024, paper 22)
Show as plain textHide 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. Q7 9618/22/M/J/24 original Q3 Structured · 9 marks Worked solution (a)(i) Write the record type with one DECLARE for each field. Use the type that suits each example value: TYPE Component DECLARE Item_Num : INTEGER DECLARE Reject : BOOLEAN DECLARE Stage : CHAR DECLARE Limit_1 : REAL DECLARE Limit_2 : REAL ENDTYPE TYPE and ENDTYPE statements [1] Item_Num as INTEGER and Reject as BOOLEAN [1] Stage as CHAR [1] Limit_1 and Limit_2 as REAL [1] (a)(ii) Declare a 1D array with 2000 elements of the record type: DECLARE Item : ARRAY[1:2000] OF Component ARRAY with 2000 elements (for example [1:2000] or [0:1999]) [1] Element type is Component [1] (b) Write any three of these: Allows the program to use a loop to go through all the records [1] A record can be reached directly using an index , for example Item [1] .Stage [1] The code is simpler and has less repeated code, so it is easier to write, understand, maintain, test or debug [1] Other accepted point: the records are easier to search, sort or change. KEY IDEA An array of records holds many items of mixed data under one name, and a loop can work through them all. TOTAL 9 marks Official mark scheme VIDEO ▶ Starts at Q3 (23:43) Starts at Q3 (23:43) · by Pseudocode Pro. Tap the picture to open it on YouTube.