SlideShare a Scribd company logo
BY
KAUSHAL JHUNJHUNWALA-1BM15IS031
ANKIT SINHA-1BM15IS007
Juan Martin Carlés.
ENUMERATED DATA TYPES
WHAT IS ENUMERATED DATA TYPES?
Syntax for using enums.
Scoped and unscoped enums
Why enums are used in c++ programming.
How to use enums with flags.
Printing the string representation of enums.
TOPICS
WHAT IS ENUMERATED DATA TYPES?
ENUMER ATED DATA TYPES GIVES YOU AN OPPORTUNITY TO:
 INVENT YOUR OWN DATATYPE
 DEFINE WHAT VALUES OF THE VARIABLES THIS DATATYPE CAN TAKE
 REPLACE NUMBERS WITH WORDS
SYNTAX
enum enum_name {identifier list} enum_type;
example: Example:
enum BOOLEAN enum BOOLEAN
{TRUE,FALSE} {TRUE=0,FALSE=1}
b1,b2; b1,b2;
ANOTHER EXAMPLE
GUESS THE OUTPUT?
void main()
{
enum WeekDays
{Mon,Tues,Wed,Thurs,Fri,Sat,Sun}da
ys;
int i;
for(i=Mon;i<=Sun;i++)
{
cout<<i<<“ “;
}
}
output
Case 1: Mon=0
0 1 2 3 4 5 6
Case 2: Mon=32767
Error: Numeric constants too
large.
Case 3: Mon=2 Thurs=9
Sun=Mon+Wed
2 3 4 9 10 11 6
Case 4: Mon=32760
32760 32761 32762 32763
32764 32765 32766
SCOPED AND UNSCOPED ENUMS
SYNTAX
//unscoped enum: //scoped enum:
enum [identifier] [: type] enum [class] [struct]
{enum_list}; [identifier][: type]
{enum_list};
SAMPLE PROGRAM SNIPPET
Namespace card_scoped
{
enum class Suit
{Diamonds,Hearts,Clubs,Spades};
void play_card(Suit suit)
{
if(suit==Suit::Clubs)
{/* ……………*/}
}
}
//enumerator must be qualified by
enum type.
Namespace card_nonscoped
{
enum Suit
{Diamonds,Hearts,Clubs,Spades};
void play_card(Suit suit)
{
if(suit==Clubs)
{/* ……………*/}
}
}
//enumerator is visible without
qualification.
CASTING RULES
namespace ScopedEnumConversions
{ enum class Suit{Diamonds,Hearts,Clubs,Spades};
void attemptConversions()
{ Suit hands;
hands=Clubs; //error ‘Clubs’:undeclared idenifier
hands=Suit::Clubs; //correct
int a=135692;
hands=a; // error: cannot convert from ‘int’ to ‘Suit’
a=Suit::Hearts; //error: cannot convert from ‘suit’ to ‘int’
a=static_cast<int>(Suit::Hearts); // correct }
WHY ENUMS ARE USED?
enum variables take only one value out of many possible values.
#include<iostream>
enum suites{clubs=0,diamonds=10,hearts=20,spades=3}card;
int main()
{ card=club;
cout<<“size of enum variable=“<<sizeof(card);
return 0;
}
Output:
size of enum variable=4
This is because the size of an integer is 4 bytes.This makes enums a good choice to work with flags.
HOW TO USE ENUMS WITH FLAGS?
#include<stdio.h>
Enum designflags{Bold=1,Italics=2,Underline=4}button;
int main()
{ int mydesign=Bold|Underline; /*Bold=00000001
cout<<mydesign; Italics=00000010
return 0; Underline=00000100
} 00000010|00000100 */
Output:
5
Explanation: Suppose you are designing a button for Windows application.You cam set the flags Italics,Bold and
Underline to work with the text.There is a reason why all integral constants are chosen in powers of 2. Since the integral
constants are in powers of 2,we can combine two or more flags at once without overlapping using bitwise OR| operator.
The output 5 indicates both Bold and Underline flags are used.
PRINTING THE “STRING”
REPRESENTATION OF ENUMS
int main()
{ enum weekdays{Sun,Mon,Tues,Wed,Thurs,Fri,Sat}days;
const char* daynames[]={Sun,Mon,Tues,Wed,Thurs,Fri,Sat};
for(int i=Sun;i<=Sat,i++)
{ cout<<daynames[i]<<“ “;
}
return 0;
}
Explanation:To print the string associated with the enum values,we make use of
the above method.The trick is to create an array of strings and use the enums to index
the array.
AN ALTERNATIVE WAY...
void main()
{ enum fruits{apple,guava,orange}myFruit;
int i;0
cout<<“Enter your choice(0 to 2)””<<endl;
switch(i)
{ case apple: cout<<“Apple”; break;
case guava: cout<<“Guava”; break;
case orange: cout<<“Orange”; break; }
THANK YOU..

More Related Content

What's hot

Array in C
Array in CArray in C
Array in C
adityas29
 
Structure and Typedef
Structure and TypedefStructure and Typedef
Structure and Typedef
Acad
 
358 33 powerpoint-slides_1-introduction-c_chapter-1
358 33 powerpoint-slides_1-introduction-c_chapter-1358 33 powerpoint-slides_1-introduction-c_chapter-1
358 33 powerpoint-slides_1-introduction-c_chapter-1
sumitbardhan
 
Python Data Types (1).pdf
Python Data Types (1).pdfPython Data Types (1).pdf
Python Data Types (1).pdf
NehaSpillai1
 
Enumeration in c#
Enumeration in c#Enumeration in c#
Enumeration in c#
Dr.Neeraj Kumar Pandey
 
Chapter One
Chapter OneChapter One
Chapter One
bolovv
 
Strings,patterns and regular expressions in perl
Strings,patterns and regular expressions in perlStrings,patterns and regular expressions in perl
Strings,patterns and regular expressions in perl
sana mateen
 
Datatype in c++ unit 3 -topic 2
Datatype in c++ unit 3 -topic 2Datatype in c++ unit 3 -topic 2
Datatype in c++ unit 3 -topic 2
MOHIT TOMAR
 
Tokens expressionsin C++
Tokens expressionsin C++Tokens expressionsin C++
Tokens expressionsin C++
HalaiHansaika
 
Data types in C
Data types in CData types in C
Data types in C
Ansh Kashyap
 
Strings
StringsStrings
Strings
Mitali Chugh
 
Structure in C language
Structure in C languageStructure in C language
Structure in C language
CGC Technical campus,Mohali
 
C pointer
C pointerC pointer
The Art of Java Type Patterns
The Art of Java Type PatternsThe Art of Java Type Patterns
The Art of Java Type Patterns
Simon Ritter
 
Input processing and output in Python
Input processing and output in PythonInput processing and output in Python
Input processing and output in Python
Raajendra M
 
Structure c
Structure cStructure c
Structure c
thirumalaikumar3
 
Compiler design lab
Compiler design labCompiler design lab
Compiler design lab
ilias ahmed
 
C by balaguruswami - e.balagurusamy
C   by balaguruswami - e.balagurusamyC   by balaguruswami - e.balagurusamy
C by balaguruswami - e.balagurusamy
Srichandan Sobhanayak
 
Manipulation of Strings
Manipulation of StringsManipulation of Strings
Manipulation of Strings
Jancypriya M
 
Pointer in c
Pointer in cPointer in c
Pointer in c
Imamul Kadir
 

What's hot (20)

Array in C
Array in CArray in C
Array in C
 
Structure and Typedef
Structure and TypedefStructure and Typedef
Structure and Typedef
 
358 33 powerpoint-slides_1-introduction-c_chapter-1
358 33 powerpoint-slides_1-introduction-c_chapter-1358 33 powerpoint-slides_1-introduction-c_chapter-1
358 33 powerpoint-slides_1-introduction-c_chapter-1
 
Python Data Types (1).pdf
Python Data Types (1).pdfPython Data Types (1).pdf
Python Data Types (1).pdf
 
Enumeration in c#
Enumeration in c#Enumeration in c#
Enumeration in c#
 
Chapter One
Chapter OneChapter One
Chapter One
 
Strings,patterns and regular expressions in perl
Strings,patterns and regular expressions in perlStrings,patterns and regular expressions in perl
Strings,patterns and regular expressions in perl
 
Datatype in c++ unit 3 -topic 2
Datatype in c++ unit 3 -topic 2Datatype in c++ unit 3 -topic 2
Datatype in c++ unit 3 -topic 2
 
Tokens expressionsin C++
Tokens expressionsin C++Tokens expressionsin C++
Tokens expressionsin C++
 
Data types in C
Data types in CData types in C
Data types in C
 
Strings
StringsStrings
Strings
 
Structure in C language
Structure in C languageStructure in C language
Structure in C language
 
C pointer
C pointerC pointer
C pointer
 
The Art of Java Type Patterns
The Art of Java Type PatternsThe Art of Java Type Patterns
The Art of Java Type Patterns
 
Input processing and output in Python
Input processing and output in PythonInput processing and output in Python
Input processing and output in Python
 
Structure c
Structure cStructure c
Structure c
 
Compiler design lab
Compiler design labCompiler design lab
Compiler design lab
 
C by balaguruswami - e.balagurusamy
C   by balaguruswami - e.balagurusamyC   by balaguruswami - e.balagurusamy
C by balaguruswami - e.balagurusamy
 
Manipulation of Strings
Manipulation of StringsManipulation of Strings
Manipulation of Strings
 
Pointer in c
Pointer in cPointer in c
Pointer in c
 

Viewers also liked

eCommerce and online consumer behaviour Infographics
eCommerce and online consumer behaviour InfographicseCommerce and online consumer behaviour Infographics
eCommerce and online consumer behaviour Infographics
Dan Chen
 
Kristyna_Erbenova_-_Paul_Fierlinger
Kristyna_Erbenova_-_Paul_FierlingerKristyna_Erbenova_-_Paul_Fierlinger
Kristyna_Erbenova_-_Paul_FierlingerKristýna Erbenová
 
Viví un verano
Viví un veranoViví un verano
Viví un verano
alberto antagli
 
GICSA
GICSAGICSA
GICSA
gicsa12
 
Reeder-Bio
Reeder-BioReeder-Bio
Reeder-Bio
Joseph Reeder
 
85. transformando nuestro rincon de lecturas
85. transformando nuestro rincon de lecturas85. transformando nuestro rincon de lecturas
85. transformando nuestro rincon de lecturas
dec-admin
 
Tamás M. Kocsis - Hungarian case law FINAL
Tamás M. Kocsis - Hungarian case law FINALTamás M. Kocsis - Hungarian case law FINAL
Tamás M. Kocsis - Hungarian case law FINAL
Dr. Tamás M. Kocsis
 
Solo entre chavos
Solo entre chavosSolo entre chavos
Solo entre chavos
dec-admin
 
Normas de present. de trabajos de investig. 2016 6-16
Normas  de present. de trabajos de investig. 2016 6-16Normas  de present. de trabajos de investig. 2016 6-16
Normas de present. de trabajos de investig. 2016 6-16
marisol virguez
 
Metodos ll politicas de inclusion
Metodos ll politicas de inclusionMetodos ll politicas de inclusion
Metodos ll politicas de inclusion
edn1234
 
55. por una alimentación balanceada
55. por una alimentación balanceada55. por una alimentación balanceada
55. por una alimentación balanceada
dec-admin
 
Presentation BLOG
Presentation BLOGPresentation BLOG
Presentation BLOGrajivakram
 
Que los alumnos tengan buena alimentación
Que los alumnos tengan buena alimentaciónQue los alumnos tengan buena alimentación
Que los alumnos tengan buena alimentación
dec-admin
 
44.el daño irreparable a nuestro planeta
44.el daño irreparable a nuestro planeta44.el daño irreparable a nuestro planeta
44.el daño irreparable a nuestro planeta
dec-admin
 
272. mejorando mi ambiente
272. mejorando mi ambiente272. mejorando mi ambiente
272. mejorando mi ambiente
dec-admin
 
Aslam CV
Aslam CVAslam CV
Aslam CV
Mohammad Aslam
 
Осінній марафон
Осінній марафонОсінній марафон
Осінній марафон
Sarcasm Sector
 
The Heart of Jesus (Part 2) Separate Yourself For Battle: John 17:6-19
The Heart of Jesus (Part 2) Separate Yourself For Battle: John 17:6-19The Heart of Jesus (Part 2) Separate Yourself For Battle: John 17:6-19
The Heart of Jesus (Part 2) Separate Yourself For Battle: John 17:6-19
David Turner
 
192.calentamiento global
192.calentamiento global192.calentamiento global
192.calentamiento global
dec-admin
 

Viewers also liked (19)

eCommerce and online consumer behaviour Infographics
eCommerce and online consumer behaviour InfographicseCommerce and online consumer behaviour Infographics
eCommerce and online consumer behaviour Infographics
 
Kristyna_Erbenova_-_Paul_Fierlinger
Kristyna_Erbenova_-_Paul_FierlingerKristyna_Erbenova_-_Paul_Fierlinger
Kristyna_Erbenova_-_Paul_Fierlinger
 
Viví un verano
Viví un veranoViví un verano
Viví un verano
 
GICSA
GICSAGICSA
GICSA
 
Reeder-Bio
Reeder-BioReeder-Bio
Reeder-Bio
 
85. transformando nuestro rincon de lecturas
85. transformando nuestro rincon de lecturas85. transformando nuestro rincon de lecturas
85. transformando nuestro rincon de lecturas
 
Tamás M. Kocsis - Hungarian case law FINAL
Tamás M. Kocsis - Hungarian case law FINALTamás M. Kocsis - Hungarian case law FINAL
Tamás M. Kocsis - Hungarian case law FINAL
 
Solo entre chavos
Solo entre chavosSolo entre chavos
Solo entre chavos
 
Normas de present. de trabajos de investig. 2016 6-16
Normas  de present. de trabajos de investig. 2016 6-16Normas  de present. de trabajos de investig. 2016 6-16
Normas de present. de trabajos de investig. 2016 6-16
 
Metodos ll politicas de inclusion
Metodos ll politicas de inclusionMetodos ll politicas de inclusion
Metodos ll politicas de inclusion
 
55. por una alimentación balanceada
55. por una alimentación balanceada55. por una alimentación balanceada
55. por una alimentación balanceada
 
Presentation BLOG
Presentation BLOGPresentation BLOG
Presentation BLOG
 
Que los alumnos tengan buena alimentación
Que los alumnos tengan buena alimentaciónQue los alumnos tengan buena alimentación
Que los alumnos tengan buena alimentación
 
44.el daño irreparable a nuestro planeta
44.el daño irreparable a nuestro planeta44.el daño irreparable a nuestro planeta
44.el daño irreparable a nuestro planeta
 
272. mejorando mi ambiente
272. mejorando mi ambiente272. mejorando mi ambiente
272. mejorando mi ambiente
 
Aslam CV
Aslam CVAslam CV
Aslam CV
 
Осінній марафон
Осінній марафонОсінній марафон
Осінній марафон
 
The Heart of Jesus (Part 2) Separate Yourself For Battle: John 17:6-19
The Heart of Jesus (Part 2) Separate Yourself For Battle: John 17:6-19The Heart of Jesus (Part 2) Separate Yourself For Battle: John 17:6-19
The Heart of Jesus (Part 2) Separate Yourself For Battle: John 17:6-19
 
192.calentamiento global
192.calentamiento global192.calentamiento global
192.calentamiento global
 

Similar to Enumerated data types

Chapter1.pptx
Chapter1.pptxChapter1.pptx
Chapter1.pptx
WondimuBantihun1
 
Intermediate code generation1
Intermediate code generation1Intermediate code generation1
Intermediate code generation1
Shashwat Shriparv
 
Enums in c
Enums in cEnums in c
Introduction to programming - class 11
Introduction to programming - class 11Introduction to programming - class 11
Introduction to programming - class 11
Paul Brebner
 
02a fundamental c++ types, arithmetic
02a   fundamental c++ types, arithmetic 02a   fundamental c++ types, arithmetic
02a fundamental c++ types, arithmetic
Manzoor ALam
 
POLITEKNIK MALAYSIA
POLITEKNIK MALAYSIAPOLITEKNIK MALAYSIA
POLITEKNIK MALAYSIA
Aiman Hud
 
02. Primitive Data Types and Variables
02. Primitive Data Types and Variables02. Primitive Data Types and Variables
02. Primitive Data Types and Variables
Intro C# Book
 
lecture 2.pptx
lecture 2.pptxlecture 2.pptx
lecture 2.pptx
Anonymous9etQKwW
 
23UCACC11 Python Programming (MTNC) (BCA)
23UCACC11 Python Programming (MTNC) (BCA)23UCACC11 Python Programming (MTNC) (BCA)
23UCACC11 Python Programming (MTNC) (BCA)
ssuser7f90ae
 
Pseudocode
PseudocodePseudocode
Pseudocode
Harsha Madushanka
 
C++ Tutorial.docx
C++ Tutorial.docxC++ Tutorial.docx
C++ Tutorial.docx
PinkiVats1
 
keyword
keywordkeyword
keyword
teach4uin
 
keyword
keywordkeyword
keyword
teach4uin
 
CPP Homework Help
CPP Homework HelpCPP Homework Help
CPP Homework Help
C++ Homework Help
 
C++ programming
C++ programmingC++ programming
C++ programming
Anshul Mahale
 
Arrays In General
Arrays In GeneralArrays In General
Arrays In General
martha leon
 
ENUM - make u r names as data types
ENUM - make u r names as data typesENUM - make u r names as data types
ENUM - make u r names as data types
Ajay Chimmani
 
Visual Basic Review - ICA
Visual Basic Review - ICAVisual Basic Review - ICA
Visual Basic Review - ICA
emtrajano
 
Diving in OOP (Day 6): Understanding Enums in C# (A Practical Approach)
Diving in OOP (Day 6): Understanding Enums in C# (A Practical Approach)Diving in OOP (Day 6): Understanding Enums in C# (A Practical Approach)
Diving in OOP (Day 6): Understanding Enums in C# (A Practical Approach)
Akhil Mittal
 
Write a C code to perform the following tasks In main Define an arr.pdf
Write a C code to perform the following tasks In main Define an arr.pdfWrite a C code to perform the following tasks In main Define an arr.pdf
Write a C code to perform the following tasks In main Define an arr.pdf
fabmallkochi
 

Similar to Enumerated data types (20)

Chapter1.pptx
Chapter1.pptxChapter1.pptx
Chapter1.pptx
 
Intermediate code generation1
Intermediate code generation1Intermediate code generation1
Intermediate code generation1
 
Enums in c
Enums in cEnums in c
Enums in c
 
Introduction to programming - class 11
Introduction to programming - class 11Introduction to programming - class 11
Introduction to programming - class 11
 
02a fundamental c++ types, arithmetic
02a   fundamental c++ types, arithmetic 02a   fundamental c++ types, arithmetic
02a fundamental c++ types, arithmetic
 
POLITEKNIK MALAYSIA
POLITEKNIK MALAYSIAPOLITEKNIK MALAYSIA
POLITEKNIK MALAYSIA
 
02. Primitive Data Types and Variables
02. Primitive Data Types and Variables02. Primitive Data Types and Variables
02. Primitive Data Types and Variables
 
lecture 2.pptx
lecture 2.pptxlecture 2.pptx
lecture 2.pptx
 
23UCACC11 Python Programming (MTNC) (BCA)
23UCACC11 Python Programming (MTNC) (BCA)23UCACC11 Python Programming (MTNC) (BCA)
23UCACC11 Python Programming (MTNC) (BCA)
 
Pseudocode
PseudocodePseudocode
Pseudocode
 
C++ Tutorial.docx
C++ Tutorial.docxC++ Tutorial.docx
C++ Tutorial.docx
 
keyword
keywordkeyword
keyword
 
keyword
keywordkeyword
keyword
 
CPP Homework Help
CPP Homework HelpCPP Homework Help
CPP Homework Help
 
C++ programming
C++ programmingC++ programming
C++ programming
 
Arrays In General
Arrays In GeneralArrays In General
Arrays In General
 
ENUM - make u r names as data types
ENUM - make u r names as data typesENUM - make u r names as data types
ENUM - make u r names as data types
 
Visual Basic Review - ICA
Visual Basic Review - ICAVisual Basic Review - ICA
Visual Basic Review - ICA
 
Diving in OOP (Day 6): Understanding Enums in C# (A Practical Approach)
Diving in OOP (Day 6): Understanding Enums in C# (A Practical Approach)Diving in OOP (Day 6): Understanding Enums in C# (A Practical Approach)
Diving in OOP (Day 6): Understanding Enums in C# (A Practical Approach)
 
Write a C code to perform the following tasks In main Define an arr.pdf
Write a C code to perform the following tasks In main Define an arr.pdfWrite a C code to perform the following tasks In main Define an arr.pdf
Write a C code to perform the following tasks In main Define an arr.pdf
 

Recently uploaded

LORRAINE ANDREI_LEQUIGAN_HOW TO USE ZOOM
LORRAINE ANDREI_LEQUIGAN_HOW TO USE ZOOMLORRAINE ANDREI_LEQUIGAN_HOW TO USE ZOOM
LORRAINE ANDREI_LEQUIGAN_HOW TO USE ZOOM
lorraineandreiamcidl
 
Transform Your Communication with Cloud-Based IVR Solutions
Transform Your Communication with Cloud-Based IVR SolutionsTransform Your Communication with Cloud-Based IVR Solutions
Transform Your Communication with Cloud-Based IVR Solutions
TheSMSPoint
 
Microservice Teams - How the cloud changes the way we work
Microservice Teams - How the cloud changes the way we workMicroservice Teams - How the cloud changes the way we work
Microservice Teams - How the cloud changes the way we work
Sven Peters
 
2024 eCommerceDays Toulouse - Sylius 2.0.pdf
2024 eCommerceDays Toulouse - Sylius 2.0.pdf2024 eCommerceDays Toulouse - Sylius 2.0.pdf
2024 eCommerceDays Toulouse - Sylius 2.0.pdf
Łukasz Chruściel
 
Hand Rolled Applicative User Validation Code Kata
Hand Rolled Applicative User ValidationCode KataHand Rolled Applicative User ValidationCode Kata
Hand Rolled Applicative User Validation Code Kata
Philip Schwarz
 
Using Query Store in Azure PostgreSQL to Understand Query Performance
Using Query Store in Azure PostgreSQL to Understand Query PerformanceUsing Query Store in Azure PostgreSQL to Understand Query Performance
Using Query Store in Azure PostgreSQL to Understand Query Performance
Grant Fritchey
 
Top Benefits of Using Salesforce Healthcare CRM for Patient Management.pdf
Top Benefits of Using Salesforce Healthcare CRM for Patient Management.pdfTop Benefits of Using Salesforce Healthcare CRM for Patient Management.pdf
Top Benefits of Using Salesforce Healthcare CRM for Patient Management.pdf
VALiNTRY360
 
Atelier - Innover avec l’IA Générative et les graphes de connaissances
Atelier - Innover avec l’IA Générative et les graphes de connaissancesAtelier - Innover avec l’IA Générative et les graphes de connaissances
Atelier - Innover avec l’IA Générative et les graphes de connaissances
Neo4j
 
Empowering Growth with Best Software Development Company in Noida - Deuglo
Empowering Growth with Best Software  Development Company in Noida - DeugloEmpowering Growth with Best Software  Development Company in Noida - Deuglo
Empowering Growth with Best Software Development Company in Noida - Deuglo
Deuglo Infosystem Pvt Ltd
 
E-Invoicing Implementation: A Step-by-Step Guide for Saudi Arabian Companies
E-Invoicing Implementation: A Step-by-Step Guide for Saudi Arabian CompaniesE-Invoicing Implementation: A Step-by-Step Guide for Saudi Arabian Companies
E-Invoicing Implementation: A Step-by-Step Guide for Saudi Arabian Companies
Quickdice ERP
 
E-commerce Development Services- Hornet Dynamics
E-commerce Development Services- Hornet DynamicsE-commerce Development Services- Hornet Dynamics
E-commerce Development Services- Hornet Dynamics
Hornet Dynamics
 
GreenCode-A-VSCode-Plugin--Dario-Jurisic
GreenCode-A-VSCode-Plugin--Dario-JurisicGreenCode-A-VSCode-Plugin--Dario-Jurisic
GreenCode-A-VSCode-Plugin--Dario-Jurisic
Green Software Development
 
8 Best Automated Android App Testing Tool and Framework in 2024.pdf
8 Best Automated Android App Testing Tool and Framework in 2024.pdf8 Best Automated Android App Testing Tool and Framework in 2024.pdf
8 Best Automated Android App Testing Tool and Framework in 2024.pdf
kalichargn70th171
 
Odoo ERP Vs. Traditional ERP Systems – A Comparative Analysis
Odoo ERP Vs. Traditional ERP Systems – A Comparative AnalysisOdoo ERP Vs. Traditional ERP Systems – A Comparative Analysis
Odoo ERP Vs. Traditional ERP Systems – A Comparative Analysis
Envertis Software Solutions
 
SQL Accounting Software Brochure Malaysia
SQL Accounting Software Brochure MalaysiaSQL Accounting Software Brochure Malaysia
SQL Accounting Software Brochure Malaysia
GohKiangHock
 
Requirement Traceability in Xen Functional Safety
Requirement Traceability in Xen Functional SafetyRequirement Traceability in Xen Functional Safety
Requirement Traceability in Xen Functional Safety
Ayan Halder
 
How Can Hiring A Mobile App Development Company Help Your Business Grow?
How Can Hiring A Mobile App Development Company Help Your Business Grow?How Can Hiring A Mobile App Development Company Help Your Business Grow?
How Can Hiring A Mobile App Development Company Help Your Business Grow?
ToXSL Technologies
 
Introducing Crescat - Event Management Software for Venues, Festivals and Eve...
Introducing Crescat - Event Management Software for Venues, Festivals and Eve...Introducing Crescat - Event Management Software for Venues, Festivals and Eve...
Introducing Crescat - Event Management Software for Venues, Festivals and Eve...
Crescat
 
Energy consumption of Database Management - Florina Jonuzi
Energy consumption of Database Management - Florina JonuziEnergy consumption of Database Management - Florina Jonuzi
Energy consumption of Database Management - Florina Jonuzi
Green Software Development
 
Vitthal Shirke Java Microservices Resume.pdf
Vitthal Shirke Java Microservices Resume.pdfVitthal Shirke Java Microservices Resume.pdf
Vitthal Shirke Java Microservices Resume.pdf
Vitthal Shirke
 

Recently uploaded (20)

LORRAINE ANDREI_LEQUIGAN_HOW TO USE ZOOM
LORRAINE ANDREI_LEQUIGAN_HOW TO USE ZOOMLORRAINE ANDREI_LEQUIGAN_HOW TO USE ZOOM
LORRAINE ANDREI_LEQUIGAN_HOW TO USE ZOOM
 
Transform Your Communication with Cloud-Based IVR Solutions
Transform Your Communication with Cloud-Based IVR SolutionsTransform Your Communication with Cloud-Based IVR Solutions
Transform Your Communication with Cloud-Based IVR Solutions
 
Microservice Teams - How the cloud changes the way we work
Microservice Teams - How the cloud changes the way we workMicroservice Teams - How the cloud changes the way we work
Microservice Teams - How the cloud changes the way we work
 
2024 eCommerceDays Toulouse - Sylius 2.0.pdf
2024 eCommerceDays Toulouse - Sylius 2.0.pdf2024 eCommerceDays Toulouse - Sylius 2.0.pdf
2024 eCommerceDays Toulouse - Sylius 2.0.pdf
 
Hand Rolled Applicative User Validation Code Kata
Hand Rolled Applicative User ValidationCode KataHand Rolled Applicative User ValidationCode Kata
Hand Rolled Applicative User Validation Code Kata
 
Using Query Store in Azure PostgreSQL to Understand Query Performance
Using Query Store in Azure PostgreSQL to Understand Query PerformanceUsing Query Store in Azure PostgreSQL to Understand Query Performance
Using Query Store in Azure PostgreSQL to Understand Query Performance
 
Top Benefits of Using Salesforce Healthcare CRM for Patient Management.pdf
Top Benefits of Using Salesforce Healthcare CRM for Patient Management.pdfTop Benefits of Using Salesforce Healthcare CRM for Patient Management.pdf
Top Benefits of Using Salesforce Healthcare CRM for Patient Management.pdf
 
Atelier - Innover avec l’IA Générative et les graphes de connaissances
Atelier - Innover avec l’IA Générative et les graphes de connaissancesAtelier - Innover avec l’IA Générative et les graphes de connaissances
Atelier - Innover avec l’IA Générative et les graphes de connaissances
 
Empowering Growth with Best Software Development Company in Noida - Deuglo
Empowering Growth with Best Software  Development Company in Noida - DeugloEmpowering Growth with Best Software  Development Company in Noida - Deuglo
Empowering Growth with Best Software Development Company in Noida - Deuglo
 
E-Invoicing Implementation: A Step-by-Step Guide for Saudi Arabian Companies
E-Invoicing Implementation: A Step-by-Step Guide for Saudi Arabian CompaniesE-Invoicing Implementation: A Step-by-Step Guide for Saudi Arabian Companies
E-Invoicing Implementation: A Step-by-Step Guide for Saudi Arabian Companies
 
E-commerce Development Services- Hornet Dynamics
E-commerce Development Services- Hornet DynamicsE-commerce Development Services- Hornet Dynamics
E-commerce Development Services- Hornet Dynamics
 
GreenCode-A-VSCode-Plugin--Dario-Jurisic
GreenCode-A-VSCode-Plugin--Dario-JurisicGreenCode-A-VSCode-Plugin--Dario-Jurisic
GreenCode-A-VSCode-Plugin--Dario-Jurisic
 
8 Best Automated Android App Testing Tool and Framework in 2024.pdf
8 Best Automated Android App Testing Tool and Framework in 2024.pdf8 Best Automated Android App Testing Tool and Framework in 2024.pdf
8 Best Automated Android App Testing Tool and Framework in 2024.pdf
 
Odoo ERP Vs. Traditional ERP Systems – A Comparative Analysis
Odoo ERP Vs. Traditional ERP Systems – A Comparative AnalysisOdoo ERP Vs. Traditional ERP Systems – A Comparative Analysis
Odoo ERP Vs. Traditional ERP Systems – A Comparative Analysis
 
SQL Accounting Software Brochure Malaysia
SQL Accounting Software Brochure MalaysiaSQL Accounting Software Brochure Malaysia
SQL Accounting Software Brochure Malaysia
 
Requirement Traceability in Xen Functional Safety
Requirement Traceability in Xen Functional SafetyRequirement Traceability in Xen Functional Safety
Requirement Traceability in Xen Functional Safety
 
How Can Hiring A Mobile App Development Company Help Your Business Grow?
How Can Hiring A Mobile App Development Company Help Your Business Grow?How Can Hiring A Mobile App Development Company Help Your Business Grow?
How Can Hiring A Mobile App Development Company Help Your Business Grow?
 
Introducing Crescat - Event Management Software for Venues, Festivals and Eve...
Introducing Crescat - Event Management Software for Venues, Festivals and Eve...Introducing Crescat - Event Management Software for Venues, Festivals and Eve...
Introducing Crescat - Event Management Software for Venues, Festivals and Eve...
 
Energy consumption of Database Management - Florina Jonuzi
Energy consumption of Database Management - Florina JonuziEnergy consumption of Database Management - Florina Jonuzi
Energy consumption of Database Management - Florina Jonuzi
 
Vitthal Shirke Java Microservices Resume.pdf
Vitthal Shirke Java Microservices Resume.pdfVitthal Shirke Java Microservices Resume.pdf
Vitthal Shirke Java Microservices Resume.pdf
 

Enumerated data types

  • 2. WHAT IS ENUMERATED DATA TYPES? Syntax for using enums. Scoped and unscoped enums Why enums are used in c++ programming. How to use enums with flags. Printing the string representation of enums. TOPICS
  • 3. WHAT IS ENUMERATED DATA TYPES? ENUMER ATED DATA TYPES GIVES YOU AN OPPORTUNITY TO:  INVENT YOUR OWN DATATYPE  DEFINE WHAT VALUES OF THE VARIABLES THIS DATATYPE CAN TAKE  REPLACE NUMBERS WITH WORDS
  • 4. SYNTAX enum enum_name {identifier list} enum_type; example: Example: enum BOOLEAN enum BOOLEAN {TRUE,FALSE} {TRUE=0,FALSE=1} b1,b2; b1,b2;
  • 5. ANOTHER EXAMPLE GUESS THE OUTPUT? void main() { enum WeekDays {Mon,Tues,Wed,Thurs,Fri,Sat,Sun}da ys; int i; for(i=Mon;i<=Sun;i++) { cout<<i<<“ “; } } output Case 1: Mon=0 0 1 2 3 4 5 6 Case 2: Mon=32767 Error: Numeric constants too large. Case 3: Mon=2 Thurs=9 Sun=Mon+Wed 2 3 4 9 10 11 6 Case 4: Mon=32760 32760 32761 32762 32763 32764 32765 32766
  • 6. SCOPED AND UNSCOPED ENUMS SYNTAX //unscoped enum: //scoped enum: enum [identifier] [: type] enum [class] [struct] {enum_list}; [identifier][: type] {enum_list};
  • 7. SAMPLE PROGRAM SNIPPET Namespace card_scoped { enum class Suit {Diamonds,Hearts,Clubs,Spades}; void play_card(Suit suit) { if(suit==Suit::Clubs) {/* ……………*/} } } //enumerator must be qualified by enum type. Namespace card_nonscoped { enum Suit {Diamonds,Hearts,Clubs,Spades}; void play_card(Suit suit) { if(suit==Clubs) {/* ……………*/} } } //enumerator is visible without qualification.
  • 8. CASTING RULES namespace ScopedEnumConversions { enum class Suit{Diamonds,Hearts,Clubs,Spades}; void attemptConversions() { Suit hands; hands=Clubs; //error ‘Clubs’:undeclared idenifier hands=Suit::Clubs; //correct int a=135692; hands=a; // error: cannot convert from ‘int’ to ‘Suit’ a=Suit::Hearts; //error: cannot convert from ‘suit’ to ‘int’ a=static_cast<int>(Suit::Hearts); // correct }
  • 9. WHY ENUMS ARE USED? enum variables take only one value out of many possible values. #include<iostream> enum suites{clubs=0,diamonds=10,hearts=20,spades=3}card; int main() { card=club; cout<<“size of enum variable=“<<sizeof(card); return 0; } Output: size of enum variable=4 This is because the size of an integer is 4 bytes.This makes enums a good choice to work with flags.
  • 10. HOW TO USE ENUMS WITH FLAGS? #include<stdio.h> Enum designflags{Bold=1,Italics=2,Underline=4}button; int main() { int mydesign=Bold|Underline; /*Bold=00000001 cout<<mydesign; Italics=00000010 return 0; Underline=00000100 } 00000010|00000100 */ Output: 5 Explanation: Suppose you are designing a button for Windows application.You cam set the flags Italics,Bold and Underline to work with the text.There is a reason why all integral constants are chosen in powers of 2. Since the integral constants are in powers of 2,we can combine two or more flags at once without overlapping using bitwise OR| operator. The output 5 indicates both Bold and Underline flags are used.
  • 11. PRINTING THE “STRING” REPRESENTATION OF ENUMS int main() { enum weekdays{Sun,Mon,Tues,Wed,Thurs,Fri,Sat}days; const char* daynames[]={Sun,Mon,Tues,Wed,Thurs,Fri,Sat}; for(int i=Sun;i<=Sat,i++) { cout<<daynames[i]<<“ “; } return 0; } Explanation:To print the string associated with the enum values,we make use of the above method.The trick is to create an array of strings and use the enums to index the array.
  • 12. AN ALTERNATIVE WAY... void main() { enum fruits{apple,guava,orange}myFruit; int i;0 cout<<“Enter your choice(0 to 2)””<<endl; switch(i) { case apple: cout<<“Apple”; break; case guava: cout<<“Guava”; break; case orange: cout<<“Orange”; break; }