9618/31/M/J/21 question 2: worked solution (May/June 2021, paper 31)

Show as plain text

Cambridge A2 Level Computer Science 9618 · 13.1 User-defined data types Worked solution from the Data Representation Paper 3 Advanced Theory booklet, Part 1 of 3. Q1 9618/31/M/J/21 original Q2 Structured · 8 marks Worked solution (a) Say what it is for: To create a new data type from existing data types [1] To allow data types that the language does not provide to be built, which makes the language more flexible [1] (b)(i) TYPE SchoolDay = (Monday, Tuesday, Wednesday, Thursday, Friday) Write the whole definition above [1] (b)(ii) TYPE WeekEnd = (Saturday, Sunday) Write the whole definition above [1] (c) A composite type groups several fields. Use the two enumerated types for the two days. TYPE ClubMeet DECLARE FirstName : STRING DECLARE LastName : STRING DECLARE Schoolday : SchoolDay DECLARE Weekend : WeekEnd ENDTYPE TYPE ClubMeet and ENDTYPE written correctly [1] FirstName and LastName declared with a correct data type (STRING) [1] A field for the school day declared with the type SchoolDay from part (b)(i) [1] A field for the weekend day declared with the type WeekEnd from part (b)(ii) [1] KEY IDEA An enumerated type lists its allowed values; a composite type groups fields, and its fields can use other user-defined types. TOTAL 8 marks Official mark scheme VIDEO ▶ Topic lesson A lesson on this topic · by ZAINEMATICS. Tap the picture to open it on YouTube.