9618/22/O/N/21 question 3: worked solution (October/November 2021, 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. Q1 9618/22/O/N/21 original Q3 Structured · 14 marks Worked solution (a)(i) 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 ENDTYPE TYPE and ENDTYPE [1] StudentID and Email declared as STRING [1] All three Club fields declared as INTEGER [1] (a)(ii) Declare an array of 3000 elements of the record type: DECLARE Membership : ARRAY[1:3000] OF Student ARRAY[1:3000] [1] OF Student [1] (a)(iii) 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] (a)(iv) Write: store a number outside the range 1 to 99 , for example 0 [1] (b) 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" ENDPROCEDURE Count 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. KEY IDEA Use dot notation to reach record fields inside an array element, and test every club field of each student. TOTAL 14 marks Official mark scheme VIDEO ▶ Whole paper Video solution of the whole paper · by CS BY AQIB KHAN. Tap the picture to open it on YouTube.