SLIDE 1
CSZone.co.uk
Click to advance · Arrow keys also work
CAIE 9618 · Paper 3 · Topic 3.1.1

User-Defined
Data Types

Enumerated · Pointer · Composite Types · Set · Abstract Data Types

CSZone Cambridge International AS & A Level Computer Science 9618
Why User-Defined Types?

Beyond the Built-in Primitives

Primitive types (INTEGER, REAL, BOOLEAN, CHAR, STRING) are limited. User-defined types let programmers create types that precisely model the real-world problem. Cambridge 9618 Paper 3 requires four user-defined type categories.
ENUMERATED
List of named constants. E.g. days of week, seasons, card suits. Improves readability over using integer codes.
POINTER
Stores a memory address. Points to another variable or node. Used in dynamic data structures (linked lists, trees).
COMPOSITE (RECORD)
Groups multiple fields of different types under one name. E.g. a Student record with name, age, grade fields.
SET
A collection of unique values of the same type. Supports set operations: union, intersection, difference.
Enumerated Types

Named Constants in a List

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

TYPE Direction = (North, South, East, West)
ENDTYPE

DECLARE currentSeason : Season
currentSeason <- Summer

IF currentSeason = Winter THEN
  OUTPUT "Wear a coat"
ENDIF
BENEFITS
Self-documenting: code reads naturally
Prevents invalid values (can't assign "Monsoon" to a Season)
Better than magic numbers (0=Spring, 1=Summer...)
Compiler can check for completeness in CASE statements
EXAM TIP
Values in enumerated types are ordered — you can compare them (Spring < Winter). The first value has implicit index 0 in many languages.
Pointer Types

Storing Memory Addresses

// Define a record type
TYPE Node
  DECLARE data : INTEGER
  DECLARE next : NodePtr
ENDTYPE

// Define a pointer type
TYPE NodePtr = ^Node
ENDTYPE

DECLARE p : NodePtr
NEW(p) // allocate memory
p^.data <- 42 // dereference with ^
DISPOSE(p) // free memory
KEY OPERATIONS
NEW(p) — allocate heap memory, p now points to it
DISPOSE(p) — deallocate heap memory, free it back
p^ — dereference: access the value p points to
NIL — null pointer (points to nothing); used as end marker
^ SYNTAX
TYPE NodePtr = ^Node means "pointer to a Node". p^.data means "the data field of the node that p points to".
Composite (Record) Types

Grouping Related Fields

TYPE Student
  DECLARE name : STRING
  DECLARE age : INTEGER
  DECLARE grade : CHAR
  DECLARE score : REAL
ENDTYPE

DECLARE s : Student
s.name <- "Amara"
s.age <- 17
s.grade <- 'A'
s.score <- 94.5

// Array of records
DECLARE class : ARRAY[1:30] OF Student
class[1].name <- "Ben"
KEY POINTS
TYPE ... ENDTYPE defines the structure (blueprint)
DECLARE varname : TypeName creates an instance
Access fields using dot notation: s.name
Can have arrays of records: class[i].grade
Fields can be any type — including other user-defined types
Can include pointer fields for linked structures
Exam Practice

Cambridge-style questions

Question 1
A programmer wants to store the suit of a playing card (Hearts, Diamonds, Clubs, Spades). Write the pseudocode to define a suitable user-defined type and declare a variable to store a card suit. [3]
TYPE Suit = (Hearts, Diamonds, Clubs, Spades)
ENDTYPE

DECLARE cardSuit : Suit
1
Correct use of TYPE ... = (...) ENDTYPE syntax
1
All four values listed inside parentheses, comma-separated
1
DECLARE variable with correct type name
Common Mistakes

Don't lose easy marks

1
Writing TYPE Season = Spring, Summer, Autumn, Winter — missing the parentheses. The CAIE pseudocode standard requires parentheses around the list: TYPE Season = (Spring, Summer, Autumn, Winter). Also missing ENDTYPE.
2
Forgetting ^ for dereference — if p is a pointer to a Node, p^.data accesses the data field. Writing p.data is wrong — that implies p is the record itself, not a pointer to one.
3
Using = instead of <- for assignment — in CAIE pseudocode, assignment is always <- not =. Writing s.name = "Amara" will lose marks. The equals sign = is used only for comparison.
Topic Summary — 3.1.1

What You Need to Know

ENUMERATED
TYPE Name = (val1, val2, val3) ENDTYPE
Use where finite set of named values needed
POINTER
TYPE PtrName = ^TypeName ENDTYPE
NEW(p) → allocate · DISPOSE(p) → free
p^.field → dereference · NIL → null
COMPOSITE / RECORD
TYPE Name
  DECLARE field : TYPE
ENDTYPE
Access: varname.fieldname
Arrays of records: arr[i].field
CSZone

Next Video

3.1.2
File Organisation & Access
Serial · Sequential · Random · Index Files
Head to CSZone.co.uk for the complete worksheet, quiz, and interactive tools