SlideShare a Scribd company logo
1 of 26
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 (20)

Object Oriented Programming Using C++
Object Oriented Programming Using C++Object Oriented Programming Using C++
Object Oriented Programming Using C++
 
7.data types in c#
7.data types in c#7.data types in c#
7.data types in c#
 
358 33 powerpoint-slides_5-arrays_chapter-5
358 33 powerpoint-slides_5-arrays_chapter-5358 33 powerpoint-slides_5-arrays_chapter-5
358 33 powerpoint-slides_5-arrays_chapter-5
 
Python - Numpy/Pandas/Matplot Machine Learning Libraries
Python - Numpy/Pandas/Matplot Machine Learning LibrariesPython - Numpy/Pandas/Matplot Machine Learning Libraries
Python - Numpy/Pandas/Matplot Machine Learning Libraries
 
Swift vs Objective-C
Swift vs Objective-CSwift vs Objective-C
Swift vs Objective-C
 
Seaborn.pptx
Seaborn.pptxSeaborn.pptx
Seaborn.pptx
 
Data types in c++
Data types in c++Data types in c++
Data types in c++
 
Pointers
PointersPointers
Pointers
 
Pointer in C++
Pointer in C++Pointer in C++
Pointer in C++
 
NUMPY-2.pptx
NUMPY-2.pptxNUMPY-2.pptx
NUMPY-2.pptx
 
What is a DATA DICTIONARY?
What is a DATA DICTIONARY?What is a DATA DICTIONARY?
What is a DATA DICTIONARY?
 
Data Science Process.pptx
Data Science Process.pptxData Science Process.pptx
Data Science Process.pptx
 
pandas: Powerful data analysis tools for Python
pandas: Powerful data analysis tools for Pythonpandas: Powerful data analysis tools for Python
pandas: Powerful data analysis tools for Python
 
data Structure
data Structuredata Structure
data Structure
 
Type casting in java
Type casting in javaType casting in java
Type casting in java
 
Object Oriented Programming Lecture Notes
Object Oriented Programming Lecture NotesObject Oriented Programming Lecture Notes
Object Oriented Programming Lecture Notes
 
02. Primitive Data Types and Variables
02. Primitive Data Types and Variables02. Primitive Data Types and Variables
02. Primitive Data Types and Variables
 
MySQL Data types
MySQL Data typesMySQL Data types
MySQL Data types
 
Data dictionaries
Data dictionariesData dictionaries
Data dictionaries
 
Controls in asp.net
Controls in asp.netControls in asp.net
Controls in asp.net
 

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.pptxAmrutaNavale2
 
Data structure Definitions
Data structure DefinitionsData structure Definitions
Data structure DefinitionsNiveMurugan1
 
Float Data Type in C.pdf
Float Data Type in C.pdfFloat Data Type in C.pdf
Float Data Type in C.pdfSudhanshiBakre1
 
Lecture04 abap on line
Lecture04 abap on lineLecture04 abap on line
Lecture04 abap on lineMilind Patil
 
cassignmentii-170424105623.pdf
cassignmentii-170424105623.pdfcassignmentii-170424105623.pdf
cassignmentii-170424105623.pdfYRABHI
 
data types in C programming
data types in C programmingdata types in C programming
data types in C programmingHarshita Yadav
 
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 NotesLakshmiSarvani6
 
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
 
DATA CAPTURING TRAINING_FINAL.pptx
DATA CAPTURING TRAINING_FINAL.pptxDATA CAPTURING TRAINING_FINAL.pptx
DATA CAPTURING TRAINING_FINAL.pptxscokoye
 
Enumerated data types in C
Enumerated data types in CEnumerated data types in C
Enumerated data types in CArpana shree
 
Introduction to Data Abstraction
Introduction to Data AbstractionIntroduction to Data Abstraction
Introduction to Data AbstractionDennis 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
 
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++.pptxChereLemma2
 
Concept of c data types
Concept of c data typesConcept of c data types
Concept of c data typesManisha 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.pptiamsallauddin
 
Data Structure and its Fundamentals
Data Structure and its FundamentalsData Structure and its Fundamentals
Data Structure and its FundamentalsHitesh 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
 
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
 
cassignmentii-170424105623.pdf
cassignmentii-170424105623.pdfcassignmentii-170424105623.pdf
cassignmentii-170424105623.pdf
 
data types in C programming
data types in C programmingdata types in C programming
data types in C programming
 
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
 
Data types in C
Data types in CData types in C
Data types in C
 

More from 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 pptSooraj Rajmohan
 
prejudice and discrimination seminar presentation
prejudice and discrimination seminar presentationprejudice and discrimination seminar presentation
prejudice and discrimination seminar presentationSooraj 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 presentationSooraj Rajmohan
 
CAI Examination Lab Instructions 2023-2024
CAI Examination Lab Instructions 2023-2024CAI Examination Lab Instructions 2023-2024
CAI Examination Lab Instructions 2023-2024Sooraj Rajmohan
 
STRESS-MANAGEMENT presentation for seminars
STRESS-MANAGEMENT presentation for seminarsSTRESS-MANAGEMENT presentation for seminars
STRESS-MANAGEMENT presentation for seminarsSooraj Rajmohan
 
Stressless Presentation for seminars. Example
Stressless Presentation for seminars. ExampleStressless Presentation for seminars. Example
Stressless Presentation for seminars. ExampleSooraj Rajmohan
 

More from Sooraj Rajmohan (9)

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

Sanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfSanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfsanyamsingh5019
 
EPANDING THE CONTENT OF AN OUTLINE using notes.pptx
EPANDING THE CONTENT OF AN OUTLINE using notes.pptxEPANDING THE CONTENT OF AN OUTLINE using notes.pptx
EPANDING THE CONTENT OF AN OUTLINE using notes.pptxRaymartEstabillo3
 
Science lesson Moon for 4th quarter lesson
Science lesson Moon for 4th quarter lessonScience lesson Moon for 4th quarter lesson
Science lesson Moon for 4th quarter lessonJericReyAuditor
 
Pharmacognosy Flower 3. Compositae 2023.pdf
Pharmacognosy Flower 3. Compositae 2023.pdfPharmacognosy Flower 3. Compositae 2023.pdf
Pharmacognosy Flower 3. Compositae 2023.pdfMahmoud M. Sallam
 
Blooming Together_ Growing a Community Garden Worksheet.docx
Blooming Together_ Growing a Community Garden Worksheet.docxBlooming Together_ Growing a Community Garden Worksheet.docx
Blooming Together_ Growing a Community Garden Worksheet.docxUnboundStockton
 
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions  for the students and aspirants of Chemistry12th.pptxOrganic Name Reactions  for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions for the students and aspirants of Chemistry12th.pptxVS Mahajan Coaching Centre
 
Final demo Grade 9 for demo Plan dessert.pptx
Final demo Grade 9 for demo Plan dessert.pptxFinal demo Grade 9 for demo Plan dessert.pptx
Final demo Grade 9 for demo Plan dessert.pptxAvyJaneVismanos
 
Biting mechanism of poisonous snakes.pdf
Biting mechanism of poisonous snakes.pdfBiting mechanism of poisonous snakes.pdf
Biting mechanism of poisonous snakes.pdfadityarao40181
 
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdfssuser54595a
 
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️9953056974 Low Rate Call Girls In Saket, Delhi NCR
 
CARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxCARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxGaneshChakor2
 
भारत-रोम व्यापार.pptx, Indo-Roman Trade,
भारत-रोम व्यापार.pptx, Indo-Roman Trade,भारत-रोम व्यापार.pptx, Indo-Roman Trade,
भारत-रोम व्यापार.pptx, Indo-Roman Trade,Virag Sontakke
 
internship ppt on smartinternz platform as salesforce developer
internship ppt on smartinternz platform as salesforce developerinternship ppt on smartinternz platform as salesforce developer
internship ppt on smartinternz platform as salesforce developerunnathinaik
 
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17Celine George
 
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...Marc Dusseiller Dusjagr
 
The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13Steve Thomason
 
Employee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxEmployee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxNirmalaLoungPoorunde1
 
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Sapana Sha
 
Solving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptxSolving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptxOH TEIK BIN
 

Recently uploaded (20)

Sanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfSanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdf
 
EPANDING THE CONTENT OF AN OUTLINE using notes.pptx
EPANDING THE CONTENT OF AN OUTLINE using notes.pptxEPANDING THE CONTENT OF AN OUTLINE using notes.pptx
EPANDING THE CONTENT OF AN OUTLINE using notes.pptx
 
Science lesson Moon for 4th quarter lesson
Science lesson Moon for 4th quarter lessonScience lesson Moon for 4th quarter lesson
Science lesson Moon for 4th quarter lesson
 
Pharmacognosy Flower 3. Compositae 2023.pdf
Pharmacognosy Flower 3. Compositae 2023.pdfPharmacognosy Flower 3. Compositae 2023.pdf
Pharmacognosy Flower 3. Compositae 2023.pdf
 
Blooming Together_ Growing a Community Garden Worksheet.docx
Blooming Together_ Growing a Community Garden Worksheet.docxBlooming Together_ Growing a Community Garden Worksheet.docx
Blooming Together_ Growing a Community Garden Worksheet.docx
 
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions  for the students and aspirants of Chemistry12th.pptxOrganic Name Reactions  for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
 
Final demo Grade 9 for demo Plan dessert.pptx
Final demo Grade 9 for demo Plan dessert.pptxFinal demo Grade 9 for demo Plan dessert.pptx
Final demo Grade 9 for demo Plan dessert.pptx
 
Biting mechanism of poisonous snakes.pdf
Biting mechanism of poisonous snakes.pdfBiting mechanism of poisonous snakes.pdf
Biting mechanism of poisonous snakes.pdf
 
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
 
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
 
CARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxCARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptx
 
भारत-रोम व्यापार.pptx, Indo-Roman Trade,
भारत-रोम व्यापार.pptx, Indo-Roman Trade,भारत-रोम व्यापार.pptx, Indo-Roman Trade,
भारत-रोम व्यापार.pptx, Indo-Roman Trade,
 
internship ppt on smartinternz platform as salesforce developer
internship ppt on smartinternz platform as salesforce developerinternship ppt on smartinternz platform as salesforce developer
internship ppt on smartinternz platform as salesforce developer
 
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
 
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
 
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
 
The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13
 
Employee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxEmployee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptx
 
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
 
Solving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptxSolving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptx
 

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