Cambridge A2 Level Computer Science 9618 · 13.1 User-defined data types

Q1 · 9618/31/M/J/21 Q2

Worked solution from the Data Representation Paper 3 Advanced Theory booklet, Part 1 of 3.

Q19618/31/M/J/21original Q2Structured · 8 marks
Question 2 from 9618/31/M/J/21

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 IDEAAn 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

Mark scheme for 9618/31/M/J/21 question 2
VIDEO
▶ Topic lesson

A lesson on this topic · by ZAINEMATICS. 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.