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

Q21 · 9618/33/O/N/25 Q1

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

Q219618/33/O/N/25original Q1Structured · 8 marks
Question 1 from 9618/33/O/N/25

Worked solution

(a)(i)

TYPE Spectrum = (Red, Orange, Yellow, Green, Blue, Indigo, Violet)

TYPE Spectrum = [1]

All seven colours in brackets, separated by commas [1]

(a)(ii)

Write any two of these:

The list is ordered (each value has a position, so values can be compared) [1]

The list holds all the possible values the type can take [1]

Other points that score: there are no duplicate values, and all the values are of the same data type.

(b)

Start with TYPE and the name, DECLARE each field with the most suitable type, and end with ENDTYPE.

TYPE ColourData
    DECLARE ColourCode : STRING
    DECLARE Colour : Spectrum
    DECLARE Wavelength : INTEGER
    DECLARE Frequency : REAL
    DECLARE PrimaryColour : BOOLEAN
ENDTYPE

TYPE ColourData and ENDTYPE [1]

DECLARE used for every field [1]

Colour declared with the type Spectrum [1]

ColourCode as STRING, Wavelength as INTEGER, Frequency as REAL, PrimaryColour as BOOLEAN [1]

KEY IDEAAn enumerated type lists every allowed value in brackets, and a record type groups fields, each with the most suitable data type.
TOTAL 8 marks

Official mark scheme

Mark scheme for 9618/33/O/N/25 question 1
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.