Know what is meant by the term ‘user-defined data type’ and why they are needed.
Defines and use non-composite data types including enumerated and pointer.
Define and use composite data types including set and record.
Reminder - Abstract Data Types (ADT’s) including stacks, queues & linked lists (10.2)
ADT’s refer to a collection of data organised in some way & different operations that can be used to manipulate the date.
User-Defined Data Types (UDT’s) are custom data structures, were made as Stacks, Queues, lists aren’t available in some programming languages, so they must be made using other data structures that are built-in within the language.
Create a new data type (from exisiting data types)
Allow data types not available in that language to be constructed
Extend flexibility of the language.
Single data type that doesnt have a reference to another type
List needs to be done in order (called Ordinals) same data types but not string data types so no ““
User defined non-composite data type with an ordered list of possible values, should be declared as follows: (Type names usually begin with T - for recognition)
TYPE <identifier> = (value1, value2, value3…)
TYPE TSeason = (Spring, Summer, Autumn, Winter)
Once defined it can be used the same way as any other declared data type e.g.
DECLARE thisSeason : TSeason
thisSeason ← Summer
User-defined non composite data type that references memory location (like stacks, queues), should be declared as:
Type = <identifier> = ^<data type>
^ shows variable is a pointer and data type indicates type stored in the memory location e.g.
TYPE TIntPointer = ^INTEGER
Declaration of a variable of pointer type doesnt need ^ (Caret) e.g.
DECLARE MyPointer : TIntPointer
TYPE IntPointer = ^INTEGER
DECLARE number : INTEGER
DECLARE numberLocation : IntPointer
numberLocation ← ^number
Collection of data consisting of 1+ data types grouped under one identifier
Data type constructed by programmer
Data type that references at least one other data type
Primitive or user-defined
(Class & Object covered in topic 20)
Collection of related items which may have different data types, should be declared as follows:
TYPE <identifier>
// DECLARE <identifier> : <data type>
// DECLARE <identifier> : <data type>
ENDTYPE
e.g. TYPE StudentRecord
// DECLARE LastName : STRING
// DECLARE FirstName : STRING
// DECLARE DateOfBirth : DATE
// DECLARE YearGroup : INTEGER
// DECLARE FormGroup : CHAR
END TYPE
Once set up can be used same way as any other data type in declarations e.g.
DECLARE Pupil3 : StudentRecord
Pupil3.LastName ← “Johnson”
Pupil3.FirstName ← “Leroy”
Pupil3.DateOfBirth ← 01/01/2000
Pupil3.YearGroup ← 5
Pupil3.FormGroup ← ‘A’
Stores a finite number of different values with no order, should be declared as follows:
TYPE <identifier> = SET OF <data type>
DEFINE <identifier2> (value1, value2, value3…) : <identifier>
Once set defined it can be used in same way as any other data type in declarations e.g.
TYPE Letterset = SET OF CHAR
DEFINE Vowels (‘A’, ‘E’, ‘I’, ‘O’, ‘U’) : LetterSet