SlideShare a Scribd company logo
Computer Science 9618
13- Data Representation
13.1 User-defined data types
Computer Science 9618 2
13.1 User-defined data types
Candidates should be able to:
• Show understanding of why user-defined types are
necessary
• Define and use non-composite data types
• Define and use composite data types
• Choose and design an appropriate user-defined data
type for a given problem
13.1 User-defined data types
Computer Science 9618 3
13.1 User-defined data types
A user-defined data type is a data type for which the programmer has
included the definition in the program. Once the data type has been
defined, variables can be created and associated with the user-defined
data type.
There are two categories of user defined data types.:
1. Non-composite data type
a. Enumerated data type
b. Pointer data type
2. Composite
a. Record data type
b. Set data type
c. Objects and classes
Computer Science 9618 4
User-defined datatypes:
Non-composite user-defined data type
Computer Science 9618 5
User-defined datatypes:
Non-composite user-defined data type
A non-composite data type is defined without referencing another data type.
They don’t combine different built-in data types in one data type.
Non-Composite data types are:
• Enumerated data type
• Pointers
Computer Science 9618 6
ENUMERATED DATATYPE
User-defined datatypes:
Non-composite user-defined data type
Computer Science 9618 7
ENUMERATED DATATYPE
User-defined datatypes:
Non-composite user-defined data type
Enumerated Datatype
An enumerated data type defines a list of possible values.
Computer Science 9618 8
ENUMERATED DATATYPE
User-defined datatypes:
Non-composite user-defined data type
Pseudocode of data Type for Working Days can be declared as TWdays:
Computer Science 9618 9
ENUMERATED DATATYPE
User-defined datatypes:
Non-composite user-defined data type
Variables can then be declared and assigned values, for example:
Computer Science 9618 10
ENUMERATED DATATYPE
User-defined datatypes:
Non-composite user-defined data type
It is important to note that the values of the enumerated type look like string values but they are
not. They must not be enclosed in quote marks. This makes the second example much more
useful because the ordering can be put to many uses in a program.
For example, a comparison statement can be used with the values and variables of the
enumerated data type:
Computer Science 9618 11
POINTER DATATYPE
User-defined datatypes:
Non-composite user-defined data type
Computer Science 9618 12
POINTER DATATYPE
User-defined datatypes:
Non-composite user-defined data type
• A pointer data type is used to reference a memory location. This data type needs to have
information about the type of data that will be stored in the memory location.
• In pseudocode the type definition has the following structure, in which ^ shows that the type
being declared is a pointer and <TYPENAME> is the type of data to be found in the memory
location:
• for example INTEGER or REAL: or any user-defined data type.
TYPE <pointer> = ^<Typename>
Computer Science 9618 13
POINTER DATATYPE
User-defined datatypes:
Non-composite user-defined data type
It could then be used as follows:
monthPointer ← ^ thisMonth
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:
DECLARE myMonth : Tmonth
myMonth ← monthPointer^
Computer Science 9618 14
• An example of the definition of a pointer type which requires only
the identification of a data type for which the pointer is to be
used.
TYPE TIntegerPointer ← ^Integer
• An example of the declaration of a variable of the pointer data
type which does not require the use of the caret (^) symbol.
DECLARE MyIntegerPointer : TIntegerPointer
• An example of the declaration of two ordinary variables of type
integer and the assignment of a value for one of them.
DECLARE Number1, Number2 : INTEGER
Number1 ← 100
POINTER DATATYPE
User-defined datatypes:
Non-composite user-defined data type
Computer Science 9618 15
• An example of an assignment to a pointer variable of a
value which is the address of a different variable.
MyIntegerPointer ← @Number1
• An example of an assignment which uses the
‘dereferenced’ value which has been stored at the
address defined by the pointer variable. This assigns the
value 200 to Number2.
Number2 ← MyIntegerPointer^ * 2
POINTER DATATYPE
User-defined datatypes:
Non-composite user-defined data type
Computer Science 9618 16
User-defined datatypes:
Composite user-defined data type
Computer Science 9618 17
RECORD DATATYPE
User-defined datatypes:
Composite user-defined data type
Computer Science 9618 18
RECORD DATATYPE
User-defined datatypes:
Composite user-defined data type
A record data type is the most useful and therefore most widely used. It allows the
programmer to collect together values with different data types when these form a
coherent whole.
As an example, a record could be used for a program using employee data. Pseudocode
for defining the type could be:
Computer Science 9618 19
RECORD DATATYPE
User-defined datatypes:
Composite user-defined data type
A variable can then be declared as follows:
individual data item can then be accessed using a dot notation:
A particular use of a record is for the implementation of a data structure
where one or possibly two of the variables defined are pointer variables.
Computer Science 9618 20
Record Data Type example
A Car Manufacturer and seller want to store details of cars. Details can be
stored in Records
RECORD DATATYPE
User-defined datatypes:
Composite user-defined data type
Computer Science 9618 21
SET DATATYPE
User-defined datatypes:
Composite user-defined data type
Computer Science 9618 22
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:
SET DATATYPE
User-defined datatypes:
Composite user-defined data type
TYPE <set-identifier>= SET OF <Base Type>
The variable definition for a set includes the elements of the set.
DEFINE <identifier> (value1, value2, value3, ... ) : <set-identifier>
Computer Science 9618 23
SET DATATYPE
User-defined datatypes:
Composite user-defined data type
A set of vowels could be declared as follows:
TYPE Sletter = SET OF CHAR
DEFINE vowel ('a', 'e', 'i', 'o', 'u') : Sletter
Or we can declare sets in Pseudocodes this way
Here is another example
TYPE Sizes = SET OF STRING
DEFINE SweaterSize (“XXL”,”XL”,”L”,”M”,”S”,”XS”): Sizes
OR
DEFINE Title : SET OF (“Mr”, “Mrs”,”Ms”,”Miss”,”Dr”)
Computer Science 9618 24
Set data type:
A set data type allows a program to create sets and to apply the mathematical
operations defined in set theory. The following is a representative list of the
operations to be expected:
• Union
• Difference
• Intersection
• include an element in the set
• exclude an element from the set
• Check whether an element is in a set.
SET DATATYPE
User-defined datatypes:
Composite user-defined data type
Computer Science 9618 25
CLASS DATATYPE
User-defined datatypes:
Composite user-defined data type
Computer Science 9618 26
CLASS DATATYPE
User-defined datatypes:
Composite user-defined data type
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 Paper 4 (Chapter 20)

More Related Content

What's hot

form view
form viewform view
form view
AbiMurugan2
 
Python exception handling
Python   exception handlingPython   exception handling
Python exception handling
Mohammed Sikander
 
SQL Join Basic
SQL Join BasicSQL Join Basic
SQL Join Basic
Naimul Arif
 
Lesson 1: Introduction to DBMS
Lesson 1: Introduction to DBMSLesson 1: Introduction to DBMS
Lesson 1: Introduction to DBMS
Amrit Kaur
 
Python - Control Structures
Python - Control StructuresPython - Control Structures
Python - Control Structures
LasithNiro
 
NUMPY
NUMPY NUMPY
Functions in python
Functions in pythonFunctions in python
Functions in python
colorsof
 
Text mining
Text miningText mining
Text mining
Koshy Geoji
 
Python Scipy Numpy
Python Scipy NumpyPython Scipy Numpy
Python Scipy Numpy
Girish Khanzode
 
Data frame operations
Data frame operationsData frame operations
Data frame operations
19MSS011dhanyatha
 
Introduction to Cryptography
Introduction to CryptographyIntroduction to Cryptography
Introduction to Cryptography
Adri Jovin
 
Password cracking and brute force
Password cracking and brute forcePassword cracking and brute force
Password cracking and brute force
vishalgohel12195
 
SQL Views
SQL ViewsSQL Views
Cryptography.ppt
Cryptography.pptCryptography.ppt
Cryptography.ppt
kusum sharma
 
Arrays In Python | Python Array Operations | Edureka
Arrays In Python | Python Array Operations | EdurekaArrays In Python | Python Array Operations | Edureka
Arrays In Python | Python Array Operations | Edureka
Edureka!
 
Transposition Cipher
Transposition CipherTransposition Cipher
Transposition Cipher
daniyalqureshi712
 
Python variables and data types.pptx
Python variables and data types.pptxPython variables and data types.pptx
Python variables and data types.pptx
AkshayAggarwal79
 
database language ppt.pptx
database language ppt.pptxdatabase language ppt.pptx
database language ppt.pptx
Anusha sivakumar
 
Array Of Pointers
Array Of PointersArray Of Pointers
Array Of Pointers
Sharad Dubey
 
Templates in C++
Templates in C++Templates in C++
Templates in C++
Tech_MX
 

What's hot (20)

form view
form viewform view
form view
 
Python exception handling
Python   exception handlingPython   exception handling
Python exception handling
 
SQL Join Basic
SQL Join BasicSQL Join Basic
SQL Join Basic
 
Lesson 1: Introduction to DBMS
Lesson 1: Introduction to DBMSLesson 1: Introduction to DBMS
Lesson 1: Introduction to DBMS
 
Python - Control Structures
Python - Control StructuresPython - Control Structures
Python - Control Structures
 
NUMPY
NUMPY NUMPY
NUMPY
 
Functions in python
Functions in pythonFunctions in python
Functions in python
 
Text mining
Text miningText mining
Text mining
 
Python Scipy Numpy
Python Scipy NumpyPython Scipy Numpy
Python Scipy Numpy
 
Data frame operations
Data frame operationsData frame operations
Data frame operations
 
Introduction to Cryptography
Introduction to CryptographyIntroduction to Cryptography
Introduction to Cryptography
 
Password cracking and brute force
Password cracking and brute forcePassword cracking and brute force
Password cracking and brute force
 
SQL Views
SQL ViewsSQL Views
SQL Views
 
Cryptography.ppt
Cryptography.pptCryptography.ppt
Cryptography.ppt
 
Arrays In Python | Python Array Operations | Edureka
Arrays In Python | Python Array Operations | EdurekaArrays In Python | Python Array Operations | Edureka
Arrays In Python | Python Array Operations | Edureka
 
Transposition Cipher
Transposition CipherTransposition Cipher
Transposition Cipher
 
Python variables and data types.pptx
Python variables and data types.pptxPython variables and data types.pptx
Python variables and data types.pptx
 
database language ppt.pptx
database language ppt.pptxdatabase language ppt.pptx
database language ppt.pptx
 
Array Of Pointers
Array Of PointersArray Of Pointers
Array Of Pointers
 
Templates in C++
Templates in C++Templates in C++
Templates in C++
 

Similar to 13.1 User-defined data types.pptx

chapter 1 Introduction to Ds and Algorithm Anyasis.pptx
chapter 1 Introduction to Ds and Algorithm Anyasis.pptxchapter 1 Introduction to Ds and Algorithm Anyasis.pptx
chapter 1 Introduction to Ds and Algorithm Anyasis.pptx
AmrutaNavale2
 
Data structure Definitions
Data structure DefinitionsData structure Definitions
Data structure Definitions
NiveMurugan1
 
Data types in c++
Data types in c++Data types in c++
Data types in c++
Venkata.Manish Reddy
 
Float Data Type in C.pdf
Float Data Type in C.pdfFloat Data Type in C.pdf
Float Data Type in C.pdf
SudhanshiBakre1
 
Lecture04 abap on line
Lecture04 abap on lineLecture04 abap on line
Lecture04 abap on line
Milind Patil
 
data types in C programming
data types in C programmingdata types in C programming
data types in C programming
Harshita Yadav
 
cassignmentii-170424105623.pdf
cassignmentii-170424105623.pdfcassignmentii-170424105623.pdf
cassignmentii-170424105623.pdf
YRABHI
 
Introduction to Data Science With R Notes
Introduction to Data Science With R NotesIntroduction to Data Science With R Notes
Introduction to Data Science With R Notes
LakshmiSarvani6
 
Data Types in C++-Primary or Built-in or Fundamental data type Derived data t...
Data Types in C++-Primary or Built-in or Fundamental data type Derived data t...Data Types in C++-Primary or Built-in or Fundamental data type Derived data t...
Data Types in C++-Primary or Built-in or Fundamental data type Derived data t...
ssuser5610081
 
Chapter 2.datatypes and operators
Chapter 2.datatypes and operatorsChapter 2.datatypes and operators
Chapter 2.datatypes and operators
Jasleen Kaur (Chandigarh University)
 
DATA CAPTURING TRAINING_FINAL.pptx
DATA CAPTURING TRAINING_FINAL.pptxDATA CAPTURING TRAINING_FINAL.pptx
DATA CAPTURING TRAINING_FINAL.pptx
scokoye
 
Data Structures & Algorithms
Data Structures & AlgorithmsData Structures & Algorithms
Data Structures & Algorithms
Ain-ul-Moiz Khawaja
 
Enumerated data types in C
Enumerated data types in CEnumerated data types in C
Enumerated data types in C
Arpana shree
 
Introduction to Data Abstraction
Introduction to Data AbstractionIntroduction to Data Abstraction
Introduction to Data Abstraction
Dennis Gajo
 
Fundamental of C Programming (Data Types)
Fundamental of C Programming (Data Types)Fundamental of C Programming (Data Types)
Fundamental of C Programming (Data Types)
jimmy majumder
 
UNIT II.docx
UNIT II.docxUNIT II.docx
UNIT II.docx
Revathiparamanathan
 
Ch-3(b) - Variables and Data types in C++.pptx
Ch-3(b) - Variables and Data types in C++.pptxCh-3(b) - Variables and Data types in C++.pptx
Ch-3(b) - Variables and Data types in C++.pptx
ChereLemma2
 
Concept of c data types
Concept of c data typesConcept of c data types
Concept of c data types
Manisha Keim
 
Lecture 1 IntroductionToDataStructures_coursematerial_Draft0.01.ppt
Lecture 1 IntroductionToDataStructures_coursematerial_Draft0.01.pptLecture 1 IntroductionToDataStructures_coursematerial_Draft0.01.ppt
Lecture 1 IntroductionToDataStructures_coursematerial_Draft0.01.ppt
iamsallauddin
 
Data Structure and its Fundamentals
Data Structure and its FundamentalsData Structure and its Fundamentals
Data Structure and its Fundamentals
Hitesh Mohapatra
 

Similar to 13.1 User-defined data types.pptx (20)

chapter 1 Introduction to Ds and Algorithm Anyasis.pptx
chapter 1 Introduction to Ds and Algorithm Anyasis.pptxchapter 1 Introduction to Ds and Algorithm Anyasis.pptx
chapter 1 Introduction to Ds and Algorithm Anyasis.pptx
 
Data structure Definitions
Data structure DefinitionsData structure Definitions
Data structure Definitions
 
Data types in c++
Data types in c++Data types in c++
Data types in c++
 
Float Data Type in C.pdf
Float Data Type in C.pdfFloat Data Type in C.pdf
Float Data Type in C.pdf
 
Lecture04 abap on line
Lecture04 abap on lineLecture04 abap on line
Lecture04 abap on line
 
data types in C programming
data types in C programmingdata types in C programming
data types in C programming
 
cassignmentii-170424105623.pdf
cassignmentii-170424105623.pdfcassignmentii-170424105623.pdf
cassignmentii-170424105623.pdf
 
Introduction to Data Science With R Notes
Introduction to Data Science With R NotesIntroduction to Data Science With R Notes
Introduction to Data Science With R Notes
 
Data Types in C++-Primary or Built-in or Fundamental data type Derived data t...
Data Types in C++-Primary or Built-in or Fundamental data type Derived data t...Data Types in C++-Primary or Built-in or Fundamental data type Derived data t...
Data Types in C++-Primary or Built-in or Fundamental data type Derived data t...
 
Chapter 2.datatypes and operators
Chapter 2.datatypes and operatorsChapter 2.datatypes and operators
Chapter 2.datatypes and operators
 
DATA CAPTURING TRAINING_FINAL.pptx
DATA CAPTURING TRAINING_FINAL.pptxDATA CAPTURING TRAINING_FINAL.pptx
DATA CAPTURING TRAINING_FINAL.pptx
 
Data Structures & Algorithms
Data Structures & AlgorithmsData Structures & Algorithms
Data Structures & Algorithms
 
Enumerated data types in C
Enumerated data types in CEnumerated data types in C
Enumerated data types in C
 
Introduction to Data Abstraction
Introduction to Data AbstractionIntroduction to Data Abstraction
Introduction to Data Abstraction
 
Fundamental of C Programming (Data Types)
Fundamental of C Programming (Data Types)Fundamental of C Programming (Data Types)
Fundamental of C Programming (Data Types)
 
UNIT II.docx
UNIT II.docxUNIT II.docx
UNIT II.docx
 
Ch-3(b) - Variables and Data types in C++.pptx
Ch-3(b) - Variables and Data types in C++.pptxCh-3(b) - Variables and Data types in C++.pptx
Ch-3(b) - Variables and Data types in C++.pptx
 
Concept of c data types
Concept of c data typesConcept of c data types
Concept of c data types
 
Lecture 1 IntroductionToDataStructures_coursematerial_Draft0.01.ppt
Lecture 1 IntroductionToDataStructures_coursematerial_Draft0.01.pptLecture 1 IntroductionToDataStructures_coursematerial_Draft0.01.ppt
Lecture 1 IntroductionToDataStructures_coursematerial_Draft0.01.ppt
 
Data Structure and its Fundamentals
Data Structure and its FundamentalsData Structure and its Fundamentals
Data Structure and its Fundamentals
 

More from Sooraj Rajmohan

9.1.2 Structured Query Language-Database
9.1.2  Structured Query Language-Database9.1.2  Structured Query Language-Database
9.1.2 Structured Query Language-Database
Sooraj Rajmohan
 
smart work and hard work presentation ppt
smart work and hard work presentation pptsmart work and hard work presentation ppt
smart work and hard work presentation ppt
Sooraj Rajmohan
 
prejudice and discrimination seminar presentation
prejudice and discrimination seminar presentationprejudice and discrimination seminar presentation
prejudice and discrimination seminar presentation
Sooraj Rajmohan
 
Body image and self esteem-Seminar presentation
Body image and self esteem-Seminar presentationBody image and self esteem-Seminar presentation
Body image and self esteem-Seminar presentation
Sooraj Rajmohan
 
CAI Examination Lab Instructions 2023-2024
CAI Examination Lab Instructions 2023-2024CAI Examination Lab Instructions 2023-2024
CAI Examination Lab Instructions 2023-2024
Sooraj Rajmohan
 
STRESS-MANAGEMENT presentation for seminars
STRESS-MANAGEMENT presentation for seminarsSTRESS-MANAGEMENT presentation for seminars
STRESS-MANAGEMENT presentation for seminars
Sooraj Rajmohan
 
Stressless Presentation for seminars. Example
Stressless Presentation for seminars. ExampleStressless Presentation for seminars. Example
Stressless Presentation for seminars. Example
Sooraj Rajmohan
 
Searching.pdf
Searching.pdfSearching.pdf
Searching.pdf
Sooraj Rajmohan
 
Looping Lecture.pdf
Looping Lecture.pdfLooping Lecture.pdf
Looping Lecture.pdf
Sooraj Rajmohan
 
Algorithms-1.pdf
Algorithms-1.pdfAlgorithms-1.pdf
Algorithms-1.pdf
Sooraj Rajmohan
 

More from Sooraj Rajmohan (10)

9.1.2 Structured Query Language-Database
9.1.2  Structured Query Language-Database9.1.2  Structured Query Language-Database
9.1.2 Structured Query Language-Database
 
smart work and hard work presentation ppt
smart work and hard work presentation pptsmart work and hard work presentation ppt
smart work and hard work presentation ppt
 
prejudice and discrimination seminar presentation
prejudice and discrimination seminar presentationprejudice and discrimination seminar presentation
prejudice and discrimination seminar presentation
 
Body image and self esteem-Seminar presentation
Body image and self esteem-Seminar presentationBody image and self esteem-Seminar presentation
Body image and self esteem-Seminar presentation
 
CAI Examination Lab Instructions 2023-2024
CAI Examination Lab Instructions 2023-2024CAI Examination Lab Instructions 2023-2024
CAI Examination Lab Instructions 2023-2024
 
STRESS-MANAGEMENT presentation for seminars
STRESS-MANAGEMENT presentation for seminarsSTRESS-MANAGEMENT presentation for seminars
STRESS-MANAGEMENT presentation for seminars
 
Stressless Presentation for seminars. Example
Stressless Presentation for seminars. ExampleStressless Presentation for seminars. Example
Stressless Presentation for seminars. Example
 
Searching.pdf
Searching.pdfSearching.pdf
Searching.pdf
 
Looping Lecture.pdf
Looping Lecture.pdfLooping Lecture.pdf
Looping Lecture.pdf
 
Algorithms-1.pdf
Algorithms-1.pdfAlgorithms-1.pdf
Algorithms-1.pdf
 

Recently uploaded

PIMS Job Advertisement 2024.pdf Islamabad
PIMS Job Advertisement 2024.pdf IslamabadPIMS Job Advertisement 2024.pdf Islamabad
PIMS Job Advertisement 2024.pdf Islamabad
AyyanKhan40
 
Community pharmacy- Social and preventive pharmacy UNIT 5
Community pharmacy- Social and preventive pharmacy UNIT 5Community pharmacy- Social and preventive pharmacy UNIT 5
Community pharmacy- Social and preventive pharmacy UNIT 5
sayalidalavi006
 
DRUGS AND ITS classification slide share
DRUGS AND ITS classification slide shareDRUGS AND ITS classification slide share
DRUGS AND ITS classification slide share
taiba qazi
 
How to Manage Your Lost Opportunities in Odoo 17 CRM
How to Manage Your Lost Opportunities in Odoo 17 CRMHow to Manage Your Lost Opportunities in Odoo 17 CRM
How to Manage Your Lost Opportunities in Odoo 17 CRM
Celine George
 
Chapter 4 - Islamic Financial Institutions in Malaysia.pptx
Chapter 4 - Islamic Financial Institutions in Malaysia.pptxChapter 4 - Islamic Financial Institutions in Malaysia.pptx
Chapter 4 - Islamic Financial Institutions in Malaysia.pptx
Mohd Adib Abd Muin, Senior Lecturer at Universiti Utara Malaysia
 
MARY JANE WILSON, A “BOA MÃE” .
MARY JANE WILSON, A “BOA MÃE”           .MARY JANE WILSON, A “BOA MÃE”           .
MARY JANE WILSON, A “BOA MÃE” .
Colégio Santa Teresinha
 
Pride Month Slides 2024 David Douglas School District
Pride Month Slides 2024 David Douglas School DistrictPride Month Slides 2024 David Douglas School District
Pride Month Slides 2024 David Douglas School District
David Douglas School District
 
BBR 2024 Summer Sessions Interview Training
BBR  2024 Summer Sessions Interview TrainingBBR  2024 Summer Sessions Interview Training
BBR 2024 Summer Sessions Interview Training
Katrina Pritchard
 
ANATOMY AND BIOMECHANICS OF HIP JOINT.pdf
ANATOMY AND BIOMECHANICS OF HIP JOINT.pdfANATOMY AND BIOMECHANICS OF HIP JOINT.pdf
ANATOMY AND BIOMECHANICS OF HIP JOINT.pdf
Priyankaranawat4
 
Main Java[All of the Base Concepts}.docx
Main Java[All of the Base Concepts}.docxMain Java[All of the Base Concepts}.docx
Main Java[All of the Base Concepts}.docx
adhitya5119
 
The Diamonds of 2023-2024 in the IGRA collection
The Diamonds of 2023-2024 in the IGRA collectionThe Diamonds of 2023-2024 in the IGRA collection
The Diamonds of 2023-2024 in the IGRA collection
Israel Genealogy Research Association
 
Smart-Money for SMC traders good time and ICT
Smart-Money for SMC traders good time and ICTSmart-Money for SMC traders good time and ICT
Smart-Money for SMC traders good time and ICT
simonomuemu
 
How to Build a Module in Odoo 17 Using the Scaffold Method
How to Build a Module in Odoo 17 Using the Scaffold MethodHow to Build a Module in Odoo 17 Using the Scaffold Method
How to Build a Module in Odoo 17 Using the Scaffold Method
Celine George
 
How to Add Chatter in the odoo 17 ERP Module
How to Add Chatter in the odoo 17 ERP ModuleHow to Add Chatter in the odoo 17 ERP Module
How to Add Chatter in the odoo 17 ERP Module
Celine George
 
The basics of sentences session 6pptx.pptx
The basics of sentences session 6pptx.pptxThe basics of sentences session 6pptx.pptx
The basics of sentences session 6pptx.pptx
heathfieldcps1
 
Azure Interview Questions and Answers PDF By ScholarHat
Azure Interview Questions and Answers PDF By ScholarHatAzure Interview Questions and Answers PDF By ScholarHat
Azure Interview Questions and Answers PDF By ScholarHat
Scholarhat
 
The History of Stoke Newington Street Names
The History of Stoke Newington Street NamesThe History of Stoke Newington Street Names
The History of Stoke Newington Street Names
History of Stoke Newington
 
Digital Artefact 1 - Tiny Home Environmental Design
Digital Artefact 1 - Tiny Home Environmental DesignDigital Artefact 1 - Tiny Home Environmental Design
Digital Artefact 1 - Tiny Home Environmental Design
amberjdewit93
 
বাংলাদেশ অর্থনৈতিক সমীক্ষা (Economic Review) ২০২৪ UJS App.pdf
বাংলাদেশ অর্থনৈতিক সমীক্ষা (Economic Review) ২০২৪ UJS App.pdfবাংলাদেশ অর্থনৈতিক সমীক্ষা (Economic Review) ২০২৪ UJS App.pdf
বাংলাদেশ অর্থনৈতিক সমীক্ষা (Economic Review) ২০২৪ UJS App.pdf
eBook.com.bd (প্রয়োজনীয় বাংলা বই)
 
clinical examination of hip joint (1).pdf
clinical examination of hip joint (1).pdfclinical examination of hip joint (1).pdf
clinical examination of hip joint (1).pdf
Priyankaranawat4
 

Recently uploaded (20)

PIMS Job Advertisement 2024.pdf Islamabad
PIMS Job Advertisement 2024.pdf IslamabadPIMS Job Advertisement 2024.pdf Islamabad
PIMS Job Advertisement 2024.pdf Islamabad
 
Community pharmacy- Social and preventive pharmacy UNIT 5
Community pharmacy- Social and preventive pharmacy UNIT 5Community pharmacy- Social and preventive pharmacy UNIT 5
Community pharmacy- Social and preventive pharmacy UNIT 5
 
DRUGS AND ITS classification slide share
DRUGS AND ITS classification slide shareDRUGS AND ITS classification slide share
DRUGS AND ITS classification slide share
 
How to Manage Your Lost Opportunities in Odoo 17 CRM
How to Manage Your Lost Opportunities in Odoo 17 CRMHow to Manage Your Lost Opportunities in Odoo 17 CRM
How to Manage Your Lost Opportunities in Odoo 17 CRM
 
Chapter 4 - Islamic Financial Institutions in Malaysia.pptx
Chapter 4 - Islamic Financial Institutions in Malaysia.pptxChapter 4 - Islamic Financial Institutions in Malaysia.pptx
Chapter 4 - Islamic Financial Institutions in Malaysia.pptx
 
MARY JANE WILSON, A “BOA MÃE” .
MARY JANE WILSON, A “BOA MÃE”           .MARY JANE WILSON, A “BOA MÃE”           .
MARY JANE WILSON, A “BOA MÃE” .
 
Pride Month Slides 2024 David Douglas School District
Pride Month Slides 2024 David Douglas School DistrictPride Month Slides 2024 David Douglas School District
Pride Month Slides 2024 David Douglas School District
 
BBR 2024 Summer Sessions Interview Training
BBR  2024 Summer Sessions Interview TrainingBBR  2024 Summer Sessions Interview Training
BBR 2024 Summer Sessions Interview Training
 
ANATOMY AND BIOMECHANICS OF HIP JOINT.pdf
ANATOMY AND BIOMECHANICS OF HIP JOINT.pdfANATOMY AND BIOMECHANICS OF HIP JOINT.pdf
ANATOMY AND BIOMECHANICS OF HIP JOINT.pdf
 
Main Java[All of the Base Concepts}.docx
Main Java[All of the Base Concepts}.docxMain Java[All of the Base Concepts}.docx
Main Java[All of the Base Concepts}.docx
 
The Diamonds of 2023-2024 in the IGRA collection
The Diamonds of 2023-2024 in the IGRA collectionThe Diamonds of 2023-2024 in the IGRA collection
The Diamonds of 2023-2024 in the IGRA collection
 
Smart-Money for SMC traders good time and ICT
Smart-Money for SMC traders good time and ICTSmart-Money for SMC traders good time and ICT
Smart-Money for SMC traders good time and ICT
 
How to Build a Module in Odoo 17 Using the Scaffold Method
How to Build a Module in Odoo 17 Using the Scaffold MethodHow to Build a Module in Odoo 17 Using the Scaffold Method
How to Build a Module in Odoo 17 Using the Scaffold Method
 
How to Add Chatter in the odoo 17 ERP Module
How to Add Chatter in the odoo 17 ERP ModuleHow to Add Chatter in the odoo 17 ERP Module
How to Add Chatter in the odoo 17 ERP Module
 
The basics of sentences session 6pptx.pptx
The basics of sentences session 6pptx.pptxThe basics of sentences session 6pptx.pptx
The basics of sentences session 6pptx.pptx
 
Azure Interview Questions and Answers PDF By ScholarHat
Azure Interview Questions and Answers PDF By ScholarHatAzure Interview Questions and Answers PDF By ScholarHat
Azure Interview Questions and Answers PDF By ScholarHat
 
The History of Stoke Newington Street Names
The History of Stoke Newington Street NamesThe History of Stoke Newington Street Names
The History of Stoke Newington Street Names
 
Digital Artefact 1 - Tiny Home Environmental Design
Digital Artefact 1 - Tiny Home Environmental DesignDigital Artefact 1 - Tiny Home Environmental Design
Digital Artefact 1 - Tiny Home Environmental Design
 
বাংলাদেশ অর্থনৈতিক সমীক্ষা (Economic Review) ২০২৪ UJS App.pdf
বাংলাদেশ অর্থনৈতিক সমীক্ষা (Economic Review) ২০২৪ UJS App.pdfবাংলাদেশ অর্থনৈতিক সমীক্ষা (Economic Review) ২০২৪ UJS App.pdf
বাংলাদেশ অর্থনৈতিক সমীক্ষা (Economic Review) ২০২৪ UJS App.pdf
 
clinical examination of hip joint (1).pdf
clinical examination of hip joint (1).pdfclinical examination of hip joint (1).pdf
clinical examination of hip joint (1).pdf
 

13.1 User-defined data types.pptx

  • 1. Computer Science 9618 13- Data Representation 13.1 User-defined data types
  • 2. Computer Science 9618 2 13.1 User-defined data types Candidates should be able to: • Show understanding of why user-defined types are necessary • Define and use non-composite data types • Define and use composite data types • Choose and design an appropriate user-defined data type for a given problem 13.1 User-defined data types
  • 3. Computer Science 9618 3 13.1 User-defined data types A user-defined data type is a data type for which the programmer has included the definition in the program. Once the data type has been defined, variables can be created and associated with the user-defined data type. There are two categories of user defined data types.: 1. Non-composite data type a. Enumerated data type b. Pointer data type 2. Composite a. Record data type b. Set data type c. Objects and classes
  • 4. Computer Science 9618 4 User-defined datatypes: Non-composite user-defined data type
  • 5. Computer Science 9618 5 User-defined datatypes: Non-composite user-defined data type A non-composite data type is defined without referencing another data type. They don’t combine different built-in data types in one data type. Non-Composite data types are: • Enumerated data type • Pointers
  • 6. Computer Science 9618 6 ENUMERATED DATATYPE User-defined datatypes: Non-composite user-defined data type
  • 7. Computer Science 9618 7 ENUMERATED DATATYPE User-defined datatypes: Non-composite user-defined data type Enumerated Datatype An enumerated data type defines a list of possible values.
  • 8. Computer Science 9618 8 ENUMERATED DATATYPE User-defined datatypes: Non-composite user-defined data type Pseudocode of data Type for Working Days can be declared as TWdays:
  • 9. Computer Science 9618 9 ENUMERATED DATATYPE User-defined datatypes: Non-composite user-defined data type Variables can then be declared and assigned values, for example:
  • 10. Computer Science 9618 10 ENUMERATED DATATYPE User-defined datatypes: Non-composite user-defined data type It is important to note that the values of the enumerated type look like string values but they are not. They must not be enclosed in quote marks. This makes the second example much more useful because the ordering can be put to many uses in a program. For example, a comparison statement can be used with the values and variables of the enumerated data type:
  • 11. Computer Science 9618 11 POINTER DATATYPE User-defined datatypes: Non-composite user-defined data type
  • 12. Computer Science 9618 12 POINTER DATATYPE User-defined datatypes: Non-composite user-defined data type • A pointer data type is used to reference a memory location. This data type needs to have information about the type of data that will be stored in the memory location. • In pseudocode the type definition has the following structure, in which ^ shows that the type being declared is a pointer and <TYPENAME> is the type of data to be found in the memory location: • for example INTEGER or REAL: or any user-defined data type. TYPE <pointer> = ^<Typename>
  • 13. Computer Science 9618 13 POINTER DATATYPE User-defined datatypes: Non-composite user-defined data type It could then be used as follows: monthPointer ← ^ thisMonth 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: DECLARE myMonth : Tmonth myMonth ← monthPointer^
  • 14. Computer Science 9618 14 • An example of the definition of a pointer type which requires only the identification of a data type for which the pointer is to be used. TYPE TIntegerPointer ← ^Integer • An example of the declaration of a variable of the pointer data type which does not require the use of the caret (^) symbol. DECLARE MyIntegerPointer : TIntegerPointer • An example of the declaration of two ordinary variables of type integer and the assignment of a value for one of them. DECLARE Number1, Number2 : INTEGER Number1 ← 100 POINTER DATATYPE User-defined datatypes: Non-composite user-defined data type
  • 15. Computer Science 9618 15 • An example of an assignment to a pointer variable of a value which is the address of a different variable. MyIntegerPointer ← @Number1 • An example of an assignment which uses the ‘dereferenced’ value which has been stored at the address defined by the pointer variable. This assigns the value 200 to Number2. Number2 ← MyIntegerPointer^ * 2 POINTER DATATYPE User-defined datatypes: Non-composite user-defined data type
  • 16. Computer Science 9618 16 User-defined datatypes: Composite user-defined data type
  • 17. Computer Science 9618 17 RECORD DATATYPE User-defined datatypes: Composite user-defined data type
  • 18. Computer Science 9618 18 RECORD DATATYPE User-defined datatypes: Composite user-defined data type A record data type is the most useful and therefore most widely used. It allows the programmer to collect together values with different data types when these form a coherent whole. As an example, a record could be used for a program using employee data. Pseudocode for defining the type could be:
  • 19. Computer Science 9618 19 RECORD DATATYPE User-defined datatypes: Composite user-defined data type A variable can then be declared as follows: individual data item can then be accessed using a dot notation: A particular use of a record is for the implementation of a data structure where one or possibly two of the variables defined are pointer variables.
  • 20. Computer Science 9618 20 Record Data Type example A Car Manufacturer and seller want to store details of cars. Details can be stored in Records RECORD DATATYPE User-defined datatypes: Composite user-defined data type
  • 21. Computer Science 9618 21 SET DATATYPE User-defined datatypes: Composite user-defined data type
  • 22. Computer Science 9618 22 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: SET DATATYPE User-defined datatypes: Composite user-defined data type TYPE <set-identifier>= SET OF <Base Type> The variable definition for a set includes the elements of the set. DEFINE <identifier> (value1, value2, value3, ... ) : <set-identifier>
  • 23. Computer Science 9618 23 SET DATATYPE User-defined datatypes: Composite user-defined data type A set of vowels could be declared as follows: TYPE Sletter = SET OF CHAR DEFINE vowel ('a', 'e', 'i', 'o', 'u') : Sletter Or we can declare sets in Pseudocodes this way Here is another example TYPE Sizes = SET OF STRING DEFINE SweaterSize (“XXL”,”XL”,”L”,”M”,”S”,”XS”): Sizes OR DEFINE Title : SET OF (“Mr”, “Mrs”,”Ms”,”Miss”,”Dr”)
  • 24. Computer Science 9618 24 Set data type: A set data type allows a program to create sets and to apply the mathematical operations defined in set theory. The following is a representative list of the operations to be expected: • Union • Difference • Intersection • include an element in the set • exclude an element from the set • Check whether an element is in a set. SET DATATYPE User-defined datatypes: Composite user-defined data type
  • 25. Computer Science 9618 25 CLASS DATATYPE User-defined datatypes: Composite user-defined data type
  • 26. Computer Science 9618 26 CLASS DATATYPE User-defined datatypes: Composite user-defined data type 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 Paper 4 (Chapter 20)

Editor's Notes

  1. ID=d924773e-9a16-4d6d-9803-8cb819e99682 Recipe=text_billboard Type=TextOnly Variant=0 FamilyID=AccentBoxWalbaum_Zero