User-defined data types
| English | Chinese | Pinyin |
|---|---|---|
| user-defined types | 用户定义类型 | yòng hù dìng yì lèi xíng |
| non-composite | 非组合 | fēi zǔ hé |
| composite | 组合 | zǔ hé |
| enumerated type | 枚举类型 | méi jǔ lèi xíng |
| pointer | 指针 | zhǐ zhēn |
| dereference | 解引用 | jiě yǐn yòng |
| set | 集合 | jí hé |
| class | 类 | lèi |
| attributes | 属性 | shǔ xìng |
| methods | 方法 | fāng fǎ |
Building your own data types
- The built-in types cover simple cases; richer problems need user-defined types 用户定义类型.
- They make code clearer and let the compiler catch more mistakes.
- They split into non-composite 非组合 (a single value) and composite 组合 (a group).
Programming concept lab
Connect examples to the programming idea they show.
Non-composite types
- An enumerated type 枚举类型 has values that are a fixed list of named constants:
TYPE Vehicle = (M100, M230, T101, T102)
DECLARE MyTaxi : Vehicle
MyTaxi ← T102 // cannot assign anything outside the list
- A pointer 指针 holds the memory address of another variable (or
NULL). To dereference 解引用 (p^) is to reach what it points to — used to build linked lists and trees.

User-defined types: an enumerated type is a fixed named list; a pointer holds an address
An enumerated type holds:
An enumerated type restricts a variable to one of a fixed set of named values (e.g. days of the week).
Match each user-defined type to what it holds.
Enumerated = fixed named values; pointer = an address; class = data + behaviour; set = unique unordered values.
A pointer stores the memory address of another variable, and dereferencing it (e.g. p^) reaches the variable it points to.
Pointers (with NULL marking "points to nothing") are how dynamic structures like linked lists and trees are built.
Composite types
- A record groups fields of different types (Topic 10).
- A set 集合 is an unordered collection of unique values, with add/remove/membership/union/intersection.
- A class 类/object combines data fields (attributes 属性) with operations on them (methods 方法); an object is an instance of a class.
CLASS Taxi
PRIVATE Capacity : INTEGER
PUBLIC FUNCTION GetCapacity() RETURNS INTEGER
RETURN Capacity
ENDFUNCTION
ENDCLASS

A record groups fields of different types under one name
A class combines:
A class bundles attributes and methods; an object is an instance of a class.
Composite vs non-composite
- A non-composite type is built in (integer, real, char, boolean).
- A composite (user-defined) type groups others together — a record, set, class or enumerated type.
- A composite data type (a user-defined data type) groups several values under one name.
For a variable that must be one of {Red, Green, Blue}, the best type is:
A fixed list of allowed values is exactly what an enumerated type is for.
You've got it
- enumerated = a value from a fixed named list; pointer = an address (dereference with
^) - record = fields of different types; set = unordered unique values
- a class/object combines attributes (data) and methods (behaviour)
- choose a class when you need state and behaviour together