What is meant by user defined datatype?
- Derived from one or more existing datatype.
- Used to extend the built-in data types.
- To meet programmer's requirement.
Explain why user defined datatype are necessary?
- No suitable data type is provided by the language used.
- If a programmer needs specific datatype.
- that meets programmer's requirements.
Data Types
Non-composite Datatype: A single datatype that does not refer to another data type.
(Enumerated, Pointer, Real, String, Char, Boolean, Integer)
Composite Datatype: A data type that refers to other data types. Data type constructed from another data type.
Record: Collection of related items which may have different data types.
List: An indexed collection that can have different data types.
Set: Supports mathematical operations.
Array: Collection of items with the same data type.
Class: Gives properties and methods for an object.
Enumerated Data Type
- Non-composite
- Defined by a given list of all possible values
- In an order
Pseudocode to Declare an Enumerated Data Type
Type ____ = ( __, __)
Q. Declare a variable currentmonth of data type Months.
DECLARE Currentmonth: Months
Q. Declare a variable nextmonth and print nextmonth.
DECLARE Nextmonth: Months
Nextmonth <-- Currentmonth + 1
PRINT Nextmonth
Pointer Data Type
- Non-composite
- Used to reference a memory location.
^ : This symbol represents pointer.
@ : This symbol represents, the address is required not the value.
Pseudocode to Declare Pointer Data Type
Type ___ = ^___
Dereferencing: You have the address and you want the value on that address.
Num2 <--- myintpointer^
Records Data Type
- Composite Data type
- Group of multiple data types
Pseudocode to Create a Record Data Type
TYPE
DECLARE ____:____
DECLARE ____:_____
ENDTYPE
Declaring a Range
DECLARE Number: 0, 1, 2, 3 ....
DECLARE Name: ("Alizan", "Junior Tanol", "Samona")
Specific Data Type in Array
DECLARE Names: ARRAY[1:3] OF STRING
DECLARE Num: ARRAY[1:3] OF ["1", "2", "3"]
Arrays --> Multiple --> Specific Data types with Quotation Marks
Variable --> Single --> Enumerated without Quotation Marks