A Level 9618 · Paper 3 · 13.1
User-defined data types
Why programmers build their own data types, and how to define them in pseudocode. Read the notes, try the past-paper questions, then check the mark scheme.
Past papers from June 2021 to June 202623 questions · 141 marks
In this subtopic
- Why user-defined data types are needed
- Non-composite types: enumerated and pointer
- Composite types: set, record and class (object)
- Choosing and designing the right type for a given problem
13.1 · 1 of 9Book page Contents
Built-in data types
Built-in data types are the data types that a programming language already has. They can be used straight away in a program, without the programmer having to create them. Every programming language has its own set of built-in data types.
In one line
- A built-in data type can be used directly by the programmer to declare and store variables in a program.
| Data type | Description | Pseudocode | Python |
|---|---|---|---|
| boolean | Logical values, True (1) and False (0) | BOOLEAN | bool |
| char | A single character | CHAR | none (a string of length 1) |
| date | A value that represents a date | DATE | datetime class |
| integer | A whole number, positive or negative | INTEGER | int |
| real | A number with a decimal point | REAL | float |
| string | A sequence of characters | STRING | str |
Used later in
13.1 · 2 of 9Book pages Contents
User-defined data types
A user-defined data type is a data type that the programmer designs for use within a program, as opposed to a built-in data type. It is built from other data types, which can be built-in or user-defined themselves.
What is a user-defined data type
- A data type constructed by a programmer, not a primitive (built-in) data type.
- A data type that references at least one other data type (the data types can be primitive or user-defined).
Purpose of user-defined data types
- To create a new data type from existing data types.
- To allow data types that are not available in a programming language to be constructed, or to extend the flexibility of the programming language.
- The programmer can specify a new data type that meets the exact requirements of the application.
Practise this: past-paper questions
13.1 · 3 of 9Book pages Contents
Non-composite and composite types
Builds on
User-defined data types come in two kinds:
- A non-composite data type is defined without reference to another data type. Enumerated and pointer types are non-composite.
- A composite data type is built from other data types: it holds several values, of the same or different types, under one declaration. Record data types, set data types and classes are composite.
| Examples | |
|---|---|
| Non-composite (user-defined) | Enumerated, pointer |
| Other non-composite types | Integer, real, Boolean, char, string |
| Composite (user-defined) | Record, set, class |
| Other composite types | Array, list, linked list, dictionary |
Practise this: past-paper questions
- June 2022 · Paper 31 · Q1(c)A record is a user-defined composite data type. Explain what is meant by a user-defined composite data type. Include an example of another…
- November 2023 · Paper 32 · Q2Describe what is meant by composite and non-composite data types. Composite Non-composite
- June 2024 · Paper 31 · Q3(a)Explain what is meant by non-composite and composite data types
- June 2024 · Paper 32 · Q3(a)Explain what is meant by the term non-composite data type and give an example of a non-composite data type. Example
Used later in
13.1 · 4 of 9Book pages Contents
Enumerated data types
An enumerated data type is a non-composite data type defined from an ordered list of values. Variables can be declared with this data type and assigned one of the values in the list.
This pseudocode declares an enumerated data type for months:
TYPE TMonth = (Jan, Feb, Mar, Apr, May, Jun, Jul, Aug, Sep, Oct, Nov, Dec)
// The TMonth data type is declared
DECLARE ThisMonth : TMonth
// A variable is declared with the TMonth enumerated data type
ThisMonth ← May
// The variable ThisMonth is given the value May
ThisMonth > Feb
// This is TRUE, as May is later in the list than FebNote The values in an enumerated data type are not strings, so do not put quotation marks around them.
Exam definition
- A user-defined non-composite data type with an ordered list of possible values.
Practise this: past-paper questions
- June 2021 · Paper 31 · Q2(b)(i)SchoolDay to hold data about the days students are usually in school
- June 2021 · Paper 31 · Q2(b)(ii)WeekEnd to hold data about the days that are not school days
- June 2021 · Paper 31 · Q2(c)Define, using pseudocode, the composite data type ClubMeet. This will hold data about club members that includes: • first name and last name • the…
- November 2021 · Paper 32 · Q3(a)Write pseudocode to create an enumerated type called Parts to include these parts sold in a computer shop: Monitor, CPU, SSD, HDD, LaserPrinter,…
Show 19 more
- June 2022 · Paper 32 · Q1(b)(i)Write the type declaration for BuildingType in pseudocode
- November 2022 · Paper 31 · Q3(a)State what is meant by the term enumerated data type
- November 2022 · Paper 31 · Q3(c)The months of the year are: January, February, March, April, May, June, July, August, September, October, November and December. Write the…
- November 2022 · Paper 32 · Q4(a)Write pseudocode statements to declare the enumerated data type Aircraft to hold data about the types of aircraft used for a flight. These types…
- November 2022 · Paper 32 · Q4(b)Write pseudocode statements to declare the composite data type Flight to hold data about flights to a specific destination. These include: •…
- November 2023 · Paper 31 · Q3Describe what is meant by enumerated and pointer data types. Enumerated Pointer
- June 2025 · Paper 31 · Q1(a)Write a pseudocode statement to declare the enumerated data type, Vehicle, to hold the identity code of each of the company’s taxis: M100, M230,…
- June 2025 · Paper 31 · Q1(b)Write pseudocode statements to declare the composite data type, Booking, to hold data about taxi bookings. The data required includes: • booking…
- June 2025 · Paper 32 · Q1(b)(i)Write a pseudocode statement to declare GateID to hold the identity codes for the airport gates: N01, N02, N03, W01, W02, W03, W04
- June 2025 · Paper 33 · Q1(b)Identify one field in VideoLibrary that could be an efficient enumerated data type and give a reason for your choice. Field ... Reason
- November 2025 · Paper 31 · Q1(b)(i)Write the pseudocode statement for the type declaration of Activity to hold the names of the available activities: Badminton, Football, Golf,…
- November 2025 · Paper 32 · Q1(b)(i)Write the pseudocode statement for the type declaration of Body to hold the names of the available choices: Convertible, Hatchback, Saloon, SUV
- November 2025 · Paper 33 · Q1(a)(i)Write the pseudocode statement for the type declaration of Spectrum to hold the names of the colours available: Red, Orange, Yellow, Green, Blue,…
- November 2025 · Paper 33 · Q1(a)(ii)Identify two characteristics of the list of values given in an enumerated data type declaration. 1 ... 2
- November 2025 · Paper 33 · Q1(b)ColourData is a composite data type to store definitions of colours. Write pseudocode statements to declare ColourData to hold the following…
- June 2026 · Paper 32 · Q1(a)Write the pseudocode statement to declare a non-composite data type, Animals, that holds the following data: Alpaca, Chicken, Donkey, Duck, Goat,…
- June 2026 · Paper 32 · Q1(b)(i)State the type of user-defined non-composite data type created in 1(a)
- June 2026 · Paper 32 · Q1(b)(ii)Give two features that would apply to any list used in the data type in 1(a)
- June 2026 · Paper 33 · Q1(b)Write the pseudocode statement to declare a non-composite data type, Fibonacci, that holds the following numbers: 0, 1, 2, 3, 5, 8, 13, 21
Used later in
13.1 · 5 of 9Book pages Contents
Pointer data types
A pointer data type is used to reference a memory location. It has to state the type of data that it points to.
This pseudocode declares a pointer data type and a pointer, and then uses the pointer:
TYPE TMyPointer = ^INTEGER
// TMyPointer is a pointer data type that points to integers
DECLARE IntegerPointer : TMyPointer
// A variable of the TMyPointer data type
DECLARE MyNum, YourNum : INTEGER
MyNum ← 23
// Two integer variables; one of them is given a value
IntegerPointer ← @MyNum
// IntegerPointer now holds the address of MyNum
YourNum ← IntegerPointer^
// Reads the value stored at the address IntegerPointer points to.
// This is called dereferencing.Pointers are used to build more complex data structures, such as linked lists and binary trees.
Exam definition
- A user-defined non-composite data type used to reference a memory location.
Practise this: past-paper questions
- November 2021 · Paper 32 · Q3(b)Write pseudocode to create a pointer type called SelectParts that will reference the memory location in which the current part name is stored
- November 2022 · Paper 31 · Q3(b)State what is meant by the term pointer data type
- June 2023 · Paper 31 · Q4(b)A data type to point to a day in the week, for example Monday
- November 2023 · Paper 31 · Q3Describe what is meant by enumerated and pointer data types. Enumerated Pointer
Used later in
13.1 · 6 of 9Book page Contents
Record data types
A record data type stores a collection of related data about one thing, like a record in a database. It is made of several fields, and each field has its own data type, so a record is a composite data type.
This pseudocode defines a record type for a student and then uses it:
TYPE TStudentRecord
DECLARE FirstName : STRING
DECLARE LastName : STRING
DECLARE Absences : INTEGER
DECLARE Class : STRING
ENDTYPE
DECLARE Student1 : TStudentRecord
// The variable is declared as a record
Student1.FirstName ← "Zain"
Student1.LastName ← "Merchant"
Student1.Absences ← 0
Student1.Class ← "A2 Level"
// Each field is reached using dot notationPractise this: past-paper questions
- June 2021 · Paper 31 · Q2(c)Define, using pseudocode, the composite data type ClubMeet. This will hold data about club members that includes: • first name and last name • the…
- June 2022 · Paper 31 · Q1(a)Write pseudocode statements to assign: • A Level Computer Science to Title of LibraryBook • FALSE to Fiction of LibraryBook
- June 2022 · Paper 31 · Q1(b)(i)The value for NumberOfCopies must be between 1 and 10 inclusive. Write the updated line of pseudocode from the type definition of LibraryRecord to…
- June 2022 · Paper 31 · Q1(b)(ii)Every copy of every book is now uniquely identified by an accession number, AccessionNumber, as it is added to the library. Each library record…
Show 27 more
- June 2022 · Paper 31 · Q1(c)A record is a user-defined composite data type. Explain what is meant by a user-defined composite data type. Include an example of another…
- June 2022 · Paper 32 · Q1(a)Write pseudocode statements to assign: • 1067 to the BuildingID of BuildingRegister • house to the BuildingGroup of BuildingRegister
- June 2022 · Paper 32 · Q1(b)(i)Write the type declaration for BuildingType in pseudocode
- June 2022 · Paper 32 · Q1(b)(ii)Write the new declaration for BuildingGroup in pseudocode
- June 2022 · Paper 32 · Q1(b)(iii)Write the new pseudocode statement to assign house to BuildingGroup of BuildingRegister
- November 2022 · Paper 31 · Q3(d)(i)Write the pseudocode statement to set up a variable for one record of the composite data type Pet
- November 2022 · Paper 31 · Q3(d)(ii)Write pseudocode to store the details of the following pet, in the variable you set up in part (d)(i). | PetName | AnimalType | PetAge | PetGender…
- November 2022 · Paper 32 · Q4(b)Write pseudocode statements to declare the composite data type Flight to hold data about flights to a specific destination. These include: •…
- November 2022 · Paper 32 · Q4(c)(i)Write the pseudocode statement to set up a variable for one record of the composite data type Flight
- November 2022 · Paper 32 · Q4(c)(ii)Write pseudocode to store the details of the following flight in the variable you set up in part (c)(i). | Field | Data | | flight number | XA782…
- June 2023 · Paper 32 · Q6(a)Write pseudocode statements to declare the composite data type, TAppointments, to hold data about patients for a dental clinic. It will include…
- June 2024 · Paper 31 · Q3(b)Write pseudocode statements to declare the record data type FootballClub to hold data about football clubs in a league, to include: • name of team…
- November 2024 · Paper 32 · Q3(a)Describe the user-defined data type record
- November 2024 · Paper 32 · Q3(b)A programmer defines a record, Order, to store the following data: • account number • order number • order price • order date. Write pseudocode…
- June 2025 · Paper 31 · Q1(b)Write pseudocode statements to declare the composite data type, Booking, to hold data about taxi bookings. The data required includes: • booking…
- June 2025 · Paper 32 · Q1(a)Write pseudocode to store the following details to Flight1: | Field | Data | | FlightNumber | SB2789 | | Destination | Dublin | | FlightDate |…
- June 2025 · Paper 32 · Q1(b)(i)Write a pseudocode statement to declare GateID to hold the identity codes for the airport gates: N01, N02, N03, W01, W02, W03, W04
- June 2025 · Paper 32 · Q1(b)(ii)Write the new pseudocode statement required to replace the declaration of Gate in Departure
- June 2025 · Paper 33 · Q1(a)Write pseudocode statements to declare the composite data type VideoLibrary to hold data about each video in the collection. This data includes: •…
- November 2025 · Paper 31 · Q1(a)(i)Write the pseudocode statement to set up a variable for one record of the composite data type, ClubMember
- November 2025 · Paper 31 · Q1(a)(ii)Write the pseudocode statements to assign the following values to the variable set up in part (a)(i): • 984632 to Code • TRUE to FeesPaid
- November 2025 · Paper 31 · Q1(b)(ii)Write the new pseudocode statement required to update the declaration of Choice in the definition of ClubMember
- November 2025 · Paper 32 · Q1(a)(i)Write the pseudocode statement to set up a variable for one record of the composite data type, Car
- November 2025 · Paper 32 · Q1(a)(ii)Write the pseudocode statements to assign the following values to the variable set up in part (a)(i): • "Blue" to Colour • 21/10/2025 to IntoStock
- November 2025 · Paper 32 · Q1(b)(ii)Write the new pseudocode statement required to update the declaration of BodyStyle in the definition of Car
- November 2025 · Paper 33 · Q1(b)ColourData is a composite data type to store definitions of colours. Write pseudocode statements to declare ColourData to hold the following…
- June 2026 · Paper 31 · Q1(a)A record data type is a type of composite user-defined data type. Identify two other types of composite user-defined data types. 1 ... 2
Used later in
13.1 · 7 of 9Book page Contents
Set data types
A set data type is a composite data type that lets a programmer use set operations on data. The values in a set have no order and no repeats. The operations usually include:
- union
- difference
- intersection
- including an element
- excluding an element
- checking whether an element is in a set
TYPE LetterSet = SET OF CHAR
// LetterSet is a set data type that holds characters
DEFINE Vowels ('A', 'E', 'I', 'O', 'U') : LetterSet
// Vowels is a set of type LetterSet with these valuesPractise this: past-paper questions
- June 2023 · Paper 31 · Q4(a)A data type to hold a set of prime numbers below 20. These prime numbers are: 2, 3, 5, 7, 11, 13, 17, 19
- June 2024 · Paper 32 · Q3(b)Write pseudocode statements to declare the set data type EvenNumbers to hold this set of even numbers between 2 and 12: 2, 4, 6, 8, 10, 12
- November 2024 · Paper 31 · Q6(a)Describe the user-defined data type set
- November 2024 · Paper 31 · Q6(b)Write pseudocode statements to declare the set data type, SymbolSet, to hold the following set of mathematical operators, using the variable…
13.1 · 8 of 9Book page Contents
Classes and objects
An object (or class) data type is a composite data type used in object-oriented programming. A class describes the data and the procedures that act on that data; an object is one instance of a class. In a way, objects are records with their own functions attached.
Used later in
13.1 · 9 of 9Book page Contents
Choosing a data type
Builds on
An exam question may describe a situation and ask you to choose a suitable data type, or to write the pseudocode that declares it. First list the data that has to be stored, then match each part to a type:
- Enumerated: a small, fixed, ordered list of named values, such as the days of the week.
- Record: several related items of different data types that belong together, such as the details of one book.
- Pointer: stores the memory address of another variable or data item, for example to link one node of a linked list to the next.
- Set: a collection of values with no order and no repeats, where you mainly need to check whether a value is in it.
Worked example
A library keeps these details for each book: its ISBN, its title, the date it was added, whether it is on loan, and its genre. The genre is always one of Fiction, Science, History or Art. Declare suitable data types.
- Step 1The genre can only take four fixed values, so it is an enumerated type.
TYPE TGenre = (Fiction, Science, History, Art) - Step 2The details of one book are different data types that belong together, so they form a record. The ISBN is a STRING, not an INTEGER, because it can start with 0 and is never used in a calculation.
TYPE TBook DECLARE ISBN : STRING DECLARE Title : STRING DECLARE DateAdded : DATE DECLARE OnLoan : BOOLEAN DECLARE Genre : TGenre ENDTYPE - Step 3
Practise this: past-paper questions
- November 2022 · Paper 32 · Q4(b)Write pseudocode statements to declare the composite data type Flight to hold data about flights to a specific destination. These include: •…
- June 2023 · Paper 32 · Q6(a)Write pseudocode statements to declare the composite data type, TAppointments, to hold data about patients for a dental clinic. It will include…
- June 2024 · Paper 31 · Q3(b)Write pseudocode statements to declare the record data type FootballClub to hold data about football clubs in a league, to include: • name of team…
- June 2025 · Paper 31 · Q1(b)Write pseudocode statements to declare the composite data type, Booking, to hold data about taxi bookings. The data required includes: • booking…
Show 2 more
- June 2025 · Paper 33 · Q1(a)Write pseudocode statements to declare the composite data type VideoLibrary to hold data about each video in the collection. This data includes: •…
- June 2025 · Paper 33 · Q1(b)Identify one field in VideoLibrary that could be an efficient enumerated data type and give a reason for your choice. Field ... Reason
Used later in
13.1
Concepts in 13.1
Every idea explained in 13.1, and where else in the notes it is used.
| Concept | In one line | Also used in |
|---|---|---|
| built-in data type | A data type the language already has, such as INTEGER or STRING. | 13.1 User-defined data types |
| class | A composite type that holds data and the procedures that act on it. | only here |
| composite data type | A data type built from other data types, holding several values, such as a record or set. | 13.1 Record data types, 13.1 Set data types, 13.1 Classes and objects |
| dereferencing | Reading the value stored at the address a pointer holds. | only here |
| enumerated data type | A non-composite data type with an ordered list of possible values. | 13.1 Non-composite and composite types, 13.1 Choosing a data type |
| non-composite data type | A data type defined without reference to another data type, such as enumerated or pointer. | 13.1 Enumerated data types, 13.1 Pointer data types |
| pointer data type | A non-composite data type used to reference a memory location. | 13.1 Non-composite and composite types, 13.1 Choosing a data type |
| record data type | A composite data type made of fields, each with its own data type. | 13.1 Non-composite and composite types, 13.1 Choosing a data type, 13.2 Files, records and fields |
| set data type | A composite data type holding values with no order and no repeats, used with set operations. | 13.1 Non-composite and composite types |
| user-defined data type | A data type the programmer designs, built from other data types. | 13.1 Non-composite and composite types |
Zain Merchant's notes, page by page, as printed in his book. The Notes tab has the same notes as text, with links.
Past-paper questions and mark schemes © Cambridge University Press & Assessment. Compiled for revision by Zain Merchant.
- June 2021 · Paper 31 · Q2Notes:User-defined data typesEnumerated data typesRecord data types
- November 2021 · Paper 32 · Q3Notes:Enumerated data typesPointer data types
- June 2022 · Paper 31 · Q1Notes:Non-composite and composite typesRecord data types
- June 2022 · Paper 32 · Q1Notes:Enumerated data typesRecord data types
- November 2022 · Paper 31 · Q3Notes:Enumerated data typesPointer data typesRecord data types
- November 2022 · Paper 32 · Q4Notes:Enumerated data typesRecord data typesChoosing a data type
- June 2023 · Paper 31 · Q4Notes:Pointer data typesSet data types
- June 2023 · Paper 32 · Q6Notes:Record data typesChoosing a data type
- November 2023 · Paper 31 · Q3Notes:Enumerated data typesPointer data types
- November 2023 · Paper 32 · Q2Notes:Non-composite and composite types
- June 2024 · Paper 31 · Q3Notes:Non-composite and composite typesRecord data typesChoosing a data type
- June 2024 · Paper 32 · Q3Notes:Non-composite and composite typesSet data types
- November 2024 · Paper 31 · Q6Notes:Set data types
- November 2024 · Paper 32 · Q3Notes:Record data types
- June 2025 · Paper 31 · Q1Notes:Enumerated data typesRecord data typesChoosing a data type
- June 2025 · Paper 32 · Q1Notes:Enumerated data typesRecord data types
- June 2025 · Paper 33 · Q1Notes:Enumerated data typesRecord data typesChoosing a data type
- November 2025 · Paper 31 · Q1Notes:Enumerated data typesRecord data types
- November 2025 · Paper 32 · Q1Notes:Enumerated data typesRecord data types
- November 2025 · Paper 33 · Q1Notes:Enumerated data typesRecord data types
- June 2026 · Paper 31 · Q1Notes:Non-composite and composite typesPointer data typesRecord data types
- June 2026 · Paper 32 · Q1Notes:Enumerated data types
- June 2026 · Paper 33 · Q1Notes:User-defined data typesEnumerated data types
Past-paper questions and mark schemes © Cambridge University Press & Assessment. Compiled for revision by Zain Merchant.
Try the questions first.
Write your answers, then check them against the mark scheme. Your choice is remembered on this device.