Skip to content
Cambridge AS & A Level9618

User-defined data types

Computer Science 9618 Chapter Notes

Last updated November 2026

ShareWhatsAppPost

User-defined data types notes as a printable PDF.

Read online free. Download a watermarked copy with a free account.

Read the notes

The full User-defined data types notes as text: skim, search, and jump between subtopics.

~15 min read

1. Why user-defined types are needed

A user-defined data type is one the programmer creates, rather than a type built into the language.

The purpose is to create a new data type (from existing data types). The language may not have the type the application needs, so the programmer builds it. A user-defined type holds a particular group of data under a single identifier, and it makes the code easier to understand.

A user-defined type is either non-composite or composite. Enumerated and pointer types are non-composite. Record, set and class/object types are composite.

Examiner insight

“Many candidates stated a use of the data type, rather than its purpose.”

Worked example 13 marks

User-defined data types may be created by programmers when writing software.

Explain the reasons why user-defined data types are needed.

  1. 1

    The programmer may require a data type for their application that doesn't exist within the programming language. [1]

  2. 2

    It lets them represent a particular group of data, a custom data structure, under a single identifier. [1]

  3. 3

    They can extend the types already there using composite data types, which makes the code easier to understand. [1]

2. Enumerated types

An enumerated data type is a user-defined non-composite data type. It holds a list of all possible values, and the list is ordered.

The list has no duplicate values, and its values cannot change after the type is declared. The statement starts with the keyword `TYPE`, then the name, then `=` and the values in brackets.

``` TYPE Season = (Spring, Summer, Autumn, Winter) ```

Examiner insight

“Many candidates did not use the correct pseudocode technique to define an enumerated data type, which would begin with the keyword TYPE.” “The vast majority of candidates identified that an enumerated data type is a non-composite data type, but they also needed to identify the unique aspect of this data type, i.e., that it includes an ordered list of possible values.”

Worked example 14 marks

An enumerated data type, Spectrum, is required to hold the names of colours.

(i) Write the pseudocode statement for the type declaration of Spectrum to hold the names of the colours available: Red, Orange, Yellow, Green, Blue, Indigo, Violet.

(ii) Identify two characteristics of the list of values given in an enumerated data type declaration.

  1. 1

    `TYPE Spectrum =` : the keyword TYPE, the name and `=`. [1]

  2. 2

    `(Red, Orange, Yellow, Green, Blue, Indigo, Violet)` : the values in brackets. [1]

  3. 3

    The list is ordered (ordinal). [1]

  4. 4

    The list contains all possible values. Other credited answers: no duplicate values, all values the same data type. [1]

3. Pointer types

A pointer data type is a user-defined non-composite data type. It stores addresses / memory locations only, and it indicates the type of data stored in the memory location.

The declaration puts `^` before the type of data. That type can be a built-in type or another type.

``` TYPE Word = ^STRING TYPE SelectParts = ^Parts ```

Examiner insight

“Candidates are advised not to use the name of a data type to describe it, for example, a pointer data type points to a memory location is not enough as it does not show understanding of the words ‘point’ or ‘pointer’.” “Candidates who noted that pointer data types stored or referred to a memory address achieved another mark.”

Worked example 13 marks

A pointer data type is a non-composite user-defined data type.

(i) State the purpose of a pointer user-defined data type.

(ii) Write the pseudocode statement to declare a pointer data type called Word to be used with STRING data.

  1. 1

    Purpose: to reference a memory location. [1]

  2. 2

    `TYPE Word` : the keyword and the name. [1]

  3. 3

    `= ^STRING` : the pointer symbol and the data type used. [1]

  4. 4

    ``` TYPE Word = ^STRING ```

4. Composite types and the record

A composite data type refers to other data types in its definition. It contains more than one data type. A non-composite type does not refer to other data types in its definition. The composite types are record, set and class/object.

A record is a composite type. It uses other data types in its definition to form a single new data type. It includes related items and a fixed number of items.

``` TYPE <name> DECLARE <field> : <data type> ENDTYPE ```

Examiner insight

“Most candidates described the composite data type referencing other data types, the non-composite data not needing to reference other data types, or both. However, few candidates expanded beyond this, for example, by stating that a composite data type is a collection of data that can consist of multiple elements grouped under a single identifier.”

Worked example 17 marks

(a) Describe the user-defined data type record.

(b) A programmer defines a record, Order, to store the following data: account number, order number, order price, order date.

Write pseudocode statements to define this record.

  1. 1

    A record is a composite data type. [1]

  2. 2

    It uses other data types in its definition to form a single new data type. [1]

  3. 3

    The data types may be primitive types or other user-defined types. [1]

  4. 4

    `TYPE Order` at the start and `ENDTYPE` at the end. [1]

  5. 5

    `DECLARE` used for every field. [1]

  6. 6

    Account number and order number as `INTEGER`. [1]

  7. 7

    Order price as `REAL` and order date as `DATE`. [1]

  8. 8

    ``` TYPE Order DECLARE AccountNumber : INTEGER DECLARE OrderNumber : INTEGER DECLARE OrderPrice : REAL DECLARE OrderDate : DATE ENDTYPE ```

5. Using a record variable

A record type is only a definition. To store data, declare a variable of that type. The type name goes after the colon.

Each field is reached with the variable name, a dot and the field name. A STRING value goes in quotation marks.

``` DECLARE Flight1 : Departure Flight1.Gate ← "N03" ```

Examiner insight

“Errors included candidates adding additional pseudocode keywords that were not required, such as DECLARE, candidates not using the given field names in their responses, or candidates assigning data of the wrong data type, such as strings or characters without quotation marks.”

Worked example 13 marks

The composite record data type, Departure, is used to represent flights from Cambridge Airport and is defined in pseudocode as:

``` TYPE Departure DECLARE FlightNumber : STRING DECLARE Destination : STRING DECLARE FlightDate : DATE DECLARE Gate : STRING DECLARE Airline : STRING ENDTYPE ```

A variable, Flight1, is declared in pseudocode as:

``` DECLARE Flight1 : Departure ```

Write pseudocode to store the following details to Flight1:

FieldData
FlightNumberSB2789
DestinationDublin
FlightDate30/07/2025
GateN03
AirlineCambridge Airways
  1. 1

    Use the variable Flight1 with the given field names, as in `Flight1.FlightNumber`. [1]

  2. 2

    ``` Flight1.FlightNumber ← "SB2789" Flight1.Destination ← "Dublin" Flight1.Gate ← "N03" Flight1.Airline ← "Cambridge Airways" ``` [1]

  3. 3

    `Flight1.FlightDate ← 30/07/2025` : the date value, with no quotation marks. [1]

6. Sets

A set is a composite data type. It includes a list of unordered elements, and all the elements are the same data type. Set theory operations, such as intersection and union, can be applied to the elements.

A set is written in two statements. `TYPE` names the set type and gives the data type of the elements. `DEFINE` gives the values and names the type with a colon.

``` TYPE Numbers = SET OF INTEGER DEFINE EvenNumbers (2, 4, 6, 8, 10, 12) : Numbers ```

Worked example 17 marks

(a) Describe the user-defined data type set.

(b) Write pseudocode statements to declare the set data type, SymbolSet, to hold the following set of mathematical operators, using the variable Operators.

+ – * / ^

  1. 1

    A set is a composite data type. [1]

  2. 2

    It includes a list of unordered elements. [1]

  3. 3

    Set theory operations, such as intersection and union, can be applied to the elements. [1]

  4. 4

    `TYPE SymbolSet = SET OF CHAR` : the type name and the data type of the elements. [2]

  5. 5

    `DEFINE Operators` : the set variable. [1]

  6. 6

    `('+', '-', '*', '/', '^')` : the values in brackets, then `: SymbolSet` to name the type. [1]

  7. 7

    ``` TYPE SymbolSet = SET OF CHAR DEFINE Operators ('+', '-', '*', '/', '^') : SymbolSet ```

7. Choosing a type for a problem

Choose the type from the data. A field with a fixed range of possible values can be an enumerated type. Data that belongs together, such as the details of one booking, is a record.

Choose the most appropriate type for each field. Use `STRING` for a booking number, an address or a telephone number, `DATE` for a date, `INTEGER` for a whole number, `REAL` for a number with decimal places and `BOOLEAN` for a yes or no.

Examiner insight

“Candidates who included all the required data with correct data types, such as the use of STRING for the telephone number, as well as correct key words such as TYPE, ENDTYPE and DECLARE, all formatted correctly, achieved the highest marks.”

Worked example 16 marks

A programmer is writing a program to manage a video library. They require a user-defined data type.

(a) Write pseudocode statements to declare the composite data type VideoLibrary to hold data about each video in the collection. This data includes: identity code (any combination of letters and numbers), title, year released, date purchased, format (for example DVD, Blu-ray, 4K, MP4), running time (minutes). Use the most appropriate data type in each case.

(b) Identify one field in VideoLibrary that could be an efficient enumerated data type and give a reason for your choice.

  1. 1

    `TYPE VideoLibrary` and `ENDTYPE` correct. [1]

  2. 2

    `DECLARE` used correctly for every field. [1]

  3. 3

    The three STRING fields: identity code, title and format. [1]

  4. 4

    The remaining three: year released `INTEGER`, date purchased `DATE`, running time `INTEGER`. [1]

  5. 5

    ``` TYPE VideoLibrary DECLARE VideoID : STRING DECLARE Title : STRING DECLARE ReleaseYear : INTEGER DECLARE PurchaseDate : DATE DECLARE VideoFormat : STRING DECLARE RunningTime : INTEGER ENDTYPE ```

  6. 6

    Field: VideoFormat. [1]

  7. 7

    Reason: the field can have a fixed range of possible values. [1]

Recap

  • A user-defined type is created by the programmer: it makes a new data type from existing ones under a single identifier.
  • Non-composite: enumerated (ordered list of all possible values) and pointer (stores a memory location, with the type of data stored there).
  • Composite: record, set and class/object. A composite type refers to other data types in its definition.
  • Enumerated starts `TYPE Name = (values)`. Pointer is `TYPE Name = ^DataType`.
  • Record: `TYPE` ... `DECLARE` each field ... `ENDTYPE`. Use it with `DECLARE Var : TypeName` and `Var.Field ← value`.
  • Set: `TYPE Name = SET OF type`, then `DEFINE Var (values) : Name`. Elements are unordered and of one data type.
  • Match each field to the most appropriate type: STRING for telephone numbers and codes, an enumerated type for a fixed range of values.

End-of-chapter exercise

Test yourself on the whole chapter. Work through these before moving on.

  1. A programmer is writing a program for a zoo. Explain why a programmer may need to define a new data type rather than use only the built-in types.3 marks
    Answer
    1. The language may not have a data type that the application needs. (1 mark)
    2. A user-defined type can represent a particular group of data under a single identifier. (1 mark)
    3. It makes the code easier to read and understand. (1 mark)

    Trap: Giving a use, such as "to store animal names", instead of the purpose. Examiners reported this.

  2. Write the pseudocode statement to declare the enumerated type Squares to hold the numbers 1, 4, 9, 16 and 25.2 marks
    Answer
    1. `TYPE Squares =` (1 mark).
    2. `(1, 4, 9, 16, 25)` (1 mark).
    3. ``` TYPE Squares = (1, 4, 9, 16, 25) ```

    Trap: Starting with `DECLARE` instead of `TYPE`. Examiners reported this.

  3. (a) Write the pseudocode statement to declare a pointer type, ScorePtr, to be used with INTEGER data. [2] (b) State what a variable of type ScorePtr stores. [1]3 marks
    Answer
    1. (a)
    2. `TYPE ScorePtr` (1 mark), `= ^INTEGER` (1 mark).
    3. ``` TYPE ScorePtr = ^INTEGER ```
    4. (b)
    5. It stores a memory location (an address) of an INTEGER value (1 mark).

    Trap: Giving another enumerated type instead of a pointer, which examiners reported, or leaving out the data type after `^`.

  4. For each user-defined data type, state whether it is composite or non-composite: (a) enumerated, (b) record, (c) pointer, (d) set.4 marks
    Answer
    1. Enumerated: non-composite. (1 mark)
    2. Record: composite. (1 mark)
    3. Pointer: non-composite. (1 mark)
    4. Set: composite. (1 mark)

    Trap: Treating every user-defined type as composite. Enumerated and pointer types are user-defined but non-composite.

  5. A library stores, for each member: full name, telephone number, date joined and the number of books on loan (a whole number). Write the pseudocode statements to define the record type LibraryMember.4 marks
    Answer
    1. `TYPE LibraryMember` and `ENDTYPE` correct (1 mark).
    2. `DECLARE` used for every field (1 mark).
    3. Name and telephone number as `STRING` (1 mark). Date joined as `DATE` and books on loan as `INTEGER` (1 mark).
    4. ``` TYPE LibraryMember DECLARE FullName : STRING DECLARE Telephone : STRING DECLARE DateJoined : DATE DECLARE BooksOnLoan : INTEGER ENDTYPE ```

    Trap: Giving the telephone number as `INTEGER`. Examiners credit `STRING`.

  6. The record type Pupil is defined as: ``` TYPE Pupil DECLARE Name : STRING DECLARE Prefect : BOOLEAN ENDTYPE ``` (a) Write the statement to set up a variable, Pupil1, to hold one record of this type. [1] (b) Write the statements to store "Asha" in Name and TRUE in Prefect. [2]3 marks
    Answer
    1. (a)
    2. `DECLARE Pupil1 : Pupil` (1 mark).
    3. (b)
    4. `Pupil1.Name ← "Asha"` (1 mark), with the quotation marks. `Pupil1.Prefect ← TRUE` (1 mark).
    5. ``` Pupil1.Name ← "Asha" Pupil1.Prefect ← TRUE ```

    Trap: Swapping the variable and the data type (`DECLARE Pupil : Pupil1`), or writing Asha without quotation marks. Examiners reported both.

  7. (a) State one way in which the elements of a set differ from the values of an enumerated type. [1] (b) Write the pseudocode statements to declare a set type, LetterSet, of CHAR data, and to define the set Vowels holding a, e, i, o, u. [4]5 marks
    Answer
    1. (a)
    2. The elements of a set are unordered. The values of an enumerated type are an ordered list. (1 mark)
    3. (b)
    4. `TYPE LetterSet = SET OF CHAR` (2 marks).
    5. `DEFINE Vowels` (1 mark), then the values and the type name (1 mark).
    6. ``` TYPE LetterSet = SET OF CHAR DEFINE Vowels ('a', 'e', 'i', 'o', 'u') : LetterSet ```

    Trap: Writing the set like an enumerated type, `TYPE Vowels = ('a', 'e', 'i', 'o', 'u')`. A set needs `SET OF`, `DEFINE` and the type name after the colon.

  8. Name the most suitable user-defined data type for each requirement: (a) the six sizes of a T-shirt, XS to XXL; (b) the name, age and address of one customer, held together; (c) a collection of INTEGER lottery numbers, in no particular order; (d) the memory location of an INTEGER value.4 marks
    Answer
    1. (a) Enumerated: a fixed, ordered list of values. (1 mark)
    2. (b) Record: related items of different data types. (1 mark)
    3. (c) Set: unordered elements of one data type. (1 mark)
    4. (d) Pointer: stores a memory location. (1 mark)

    Trap: Answering enumerated for (d), which examiners reported, or for (c). An enumerated list is ordered, a set is not.

  9. A school records, for each pupil: a pupil code made of letters and digits (for example A1042); the pupil's house, which is always Falcon, Heron, Kestrel or Osprey; the age in whole years; and the fees owed in pounds and pence. Write the pseudocode statements to declare the enumerated type House and the record type PupilData. Use the most appropriate data type in each case.5 marks
    Answer
    1. `TYPE House = (Falcon, Heron, Kestrel, Osprey)` (1 mark).
    2. `TYPE PupilData` and `ENDTYPE` correct (1 mark).
    3. The pupil code as `STRING` (1 mark).
    4. The house field uses the type `House` (1 mark).
    5. Age as `INTEGER` and fees owed as `REAL` (1 mark).
    6. ``` TYPE House = (Falcon, Heron, Kestrel, Osprey) TYPE PupilData DECLARE PupilCode : STRING DECLARE HouseName : House DECLARE Age : INTEGER DECLARE FeesOwed : REAL ENDTYPE ```

    Trap: Giving the pupil code as `INTEGER` because it contains digits. It also contains letters, so it is `STRING`.

  10. A weather station stores each reading with: a station code of letters and digits (for example ST07); the date of the reading; the wind direction, which is always one of N, NE, E, SE, S, SW, W or NW; the temperature in °C to one decimal place; and whether it rained (yes or no). (a) Write the pseudocode statement to declare an enumerated type, Direction, for the wind direction. [2] (b) Write the pseudocode statements to declare the record type Reading. Use the most appropriate data type for each field, including Direction. [4] (c) Set up a variable, Today, for one reading. Store the station code ST07, the date 14/03/2026 and the fact that it did not rain. [4] (d) Write the pseudocode statement to declare a pointer type, ReadingPtr, to reference the memory location of a Reading. [2]12 marks
    Answer
    1. (a)
    2. `TYPE Direction =` (1 mark), `(N, NE, E, SE, S, SW, W, NW)` (1 mark).
    3. (b)
    4. `TYPE Reading` and `ENDTYPE` correct (1 mark). `DECLARE` used for every field (1 mark).
    5. Station code as `STRING`, date as `DATE` and the wind field as `Direction` (1 mark). Temperature as `REAL` and rain as `BOOLEAN` (1 mark).
    6. ``` TYPE Reading DECLARE StationCode : STRING DECLARE ReadingDate : DATE DECLARE Wind : Direction DECLARE Temperature : REAL DECLARE Rained : BOOLEAN ENDTYPE ```
    7. (c)
    8. `DECLARE Today : Reading` (1 mark). `"ST07"` in quotation marks (1 mark). The date with no quotation marks (1 mark). `FALSE` for the rain field (1 mark).
    9. ``` DECLARE Today : Reading Today.StationCode ← "ST07" Today.ReadingDate ← 14/03/2026 Today.Rained ← FALSE ```
    10. (d)
    11. `TYPE ReadingPtr` (1 mark), `= ^Reading` (1 mark).
    12. ``` TYPE ReadingPtr = ^Reading ```

    Trap: Swapping the variable and the type (`DECLARE Reading : Today`), or storing ST07 without quotation marks and the rain as "No" instead of FALSE. Examiners reported both kinds of error.

Say this, not that

Wording that loses the mark, against the wording the mark scheme credits.

Loses the markGets the mark
A pointer data type points to a memory location.A pointer stores an address / memory location and indicates the type of data stored there.
A user-defined data type is used to store the days of the week. (a use, not the purpose)The purpose is to create a new data type (from existing data types).
`DECLARE Parts = (Monitor, CPU, SSD)``TYPE Parts = (Monitor, CPU, SSD)` : an enumerated type starts with TYPE.
`Flight1.Gate ← N03``Flight1.Gate ← "N03"` : a STRING value goes in quotation marks.

Frequently asked questions

What is the purpose of a user-defined data type?
The purpose is to create a new data type from existing data types. The language may not have the type the application needs, so the programmer builds it. A user-defined type holds a group of data under a single identifier, which makes the code easier to understand.
What is the difference between composite and non-composite data types?
A composite data type refers to other data types in its definition, and it contains more than one data type. Record, set and class/object types are composite. Enumerated and pointer types are non-composite, because they do not refer to other data types in their definition.
How do you declare an enumerated type in pseudocode?
An enumerated type starts with the keyword TYPE, then the name, then = and the values in brackets. For example, TYPE Season = (Spring, Summer, Autumn, Winter). The list holds all possible values and is ordered, with no duplicate values.
How do you declare a record and use it?
A record is defined between TYPE and ENDTYPE, with DECLARE for each field. Declare a variable of that type, such as DECLARE Flight1 : Departure, then reach each field with a dot and the field name, such as Flight1.Gate ← N03. A STRING value goes in quotation marks.
Which data type should hold a telephone number?
Use STRING for a telephone number, a booking number or an address, and DATE for a date. An enumerated type suits a field with a fixed range of possible values. A record suits data that belongs together, such as the details of one booking.
Is DECLARE the correct keyword for defining an enumerated type?
No. Writing DECLARE Parts = (Monitor, CPU, SSD) is wrong, because an enumerated type starts with the keyword TYPE. Examiners reported this mistake. DECLARE is used for each field inside a record, and for variables that hold a value.

Free notes are just the start.

Unlock every Workbook and Chapter at a Glance, and generate your own worksheets and predicted papers.

Explore plans

Related chapters