Enumerated · Pointer · Composite Types · Set · Abstract Data Types
CSZoneCambridge 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.
// Array of records DECLAREclass : ARRAY[1:30] OFStudent 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]
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