13,3user Defined Data Types
13,3user Defined Data Types
1 User-
defined data
types
Zain Merchant
Zain Merchant
Zain Merchant
Data Types
Built-in data types
Remember, for each built-in data type:
• the programming language defines the range of possible values that can
be assigned to a variable when its type has been chosen.
• the programming language defines the operations that are available for
manipulating values assigned to the variable.
For example, a data type for months of the year could be defined as:
Zain Merchant
Then the variables thisMonth and nextMonth of type Tmonth could be defined as:
For example, a pointer for months of the year could be defined as follows:
Zain Merchant
It could then be used as follows:
If the contents of the memory location are required rather than the address of the
memory location, then the pointer can be dereferenced. For example, myMonth
can be set to the value stored at the address monthPointer is pointing to:
Sets
A set is a given list of unordered elements that can use set theory operations such
as intersection and union. A set data type includes the type of data in the set. In
pseudocode, the type definition has this structure:
Zain Merchant
The variable definition for a set includes the elements of the set.
Classes
A class is a composite data type that includes variables of given data types and
methods (code routines that can be run by an object in that class). An object is
defined from a given class; several objects can be defined from the same class.
Classes and objects will be considered in more depth in later chapter. Try asking
me (Zain Merchant) in class, I just might explain during lecture of this chapter.
Zain Merchant