SlideShare a Scribd company logo
1 of 7
Download to read offline
Keywords – II
Enum :
An enum type is a special data type that enables for a variable to be
a set of predefined constants. The variable must be equal to one of the values
that have been predefined for it.
The syntax is :
enum Tag_name {Variables_names}
For example:
enum tag_name{ value1, value2,...,valueN };
Here, tag_name is the name of enumerated data type. And value1,
value2,....,valueN are values of type tag_name.
• If the first enumerator does not have an initializer (if it is not initialized
by the user), the associated value is zero. For any other enumerator
whose definition does not have an initializer, the associated value is the
value of the previous enumerator plus one.
• Enum variables are the same size as an int variable. This is because each
enumerator is automatically assigned an integer value based on it’s
position in the enumeration list
In the above exapmle, By default, value1 will be equal to 0, value2
will be 1 and so on... But, the programmer can change the default values to
Also See more posts : www.comsciguide.blogspot.com
their own values.
//Changing the default value of enum elements
enum numbers { zero = 0,
five = 5,
twentyone = 21,
thirty = 30 };
cout<<zero<<endl; //output = 0
cout<<five<<endl; //output = 5
cout<<twentyone<<endl; //output = 21
cout<<thirty<<endl; //output = 30
enum months { january = 1, february, march, april,
may, june, july, august,
september, october, november, december};
By creating the enum months, you have also created a new data type
called months. You can use this new data type as you might any other data
type. For example:
months jan ;
jan = january;
• At the declaration time, we can also initialize the values with the
primitive operators(only a few).
enum Letters { A, B, C=-10, D, E=1, F, G=F+C};
//A=0, B=1, C=-10, D=-9, E=1, F=2, G=12
• The enum constants can be assigned to other enumerators.
enum color { red, yellow, green = 20, blue };
Also See more posts : www.comsciguide.blogspot.com
color col = red;
int n = blue; // n == 21
cout<<col; // output =0;
• Already declared enumerators can't be reassigned explicitly.
enum color { red = 0, yellow, green, blue };
color red = 11; // compilation error
However, the compiler will not implicitly cast an integer to an enumerated
value. The following will produce a compiler error:
enum color { red = 0, yellow, green, blue };
color red1 = 11; // compilation error
• But there is one way to change enumerators values.This can be done
using the static_cast operator by forcing the compiler to put the value in
the enumerated data types.
enum color { red = 0, yellow, green, blue };
color red = static_cast<color>(11); // error
color red1 = static_cast<color>(11) // no error
• Assigning between enumerators can be done but between integers and
enumerators results in compilation error. And enum also should be of the
same type.
enum color { red = 0, yellow, green, blue };
color red1 = 11; // compilation error
color red1 = red; // no error
Also See more posts : www.comsciguide.blogspot.com
enum color { red = 0, yellow, green, blue };
enum color1 {violet ,orange, black ,white };
color red1 = white; // compilation error
• Enumerated types are incredibly useful for code documentation and
readability purposes when you need to represent a specific number of
states.
enum Pincode
{ hyd = 500001,
krnl = 518001,
kdp = 516001,
jmd = 516434
};
Pincode getpincode()
{
if(city == ”hyderabad”)
return hyd;
if(city == ”kurnool”)
return krnl;
if(city == ”kadapa”)
return kdp;
if(city == ”jammalamadugu”)
return jmd;
}
This will be much easier to read than returning the number values.
Enumerators with class :
In gerenal, Enumerators are implicitly converted into the int data type. It
is also possible to have char, float etc thus preserving data type safety. They are
declared with enum class (or enum struct) instead of just enum.
Also See more posts : www.comsciguide.blogspot.com
For example :
enum class biodata{ name, age, place, dob };
• Each enum value is scoped with the name of the enum class. In other
words, to access the enum values, you must write:
enum class Colors {black, blue, green, cyan};
Colors mycolor;
mycolor = Colors::blue;
if (mycolor == Colors::green)
cout<<”the color is green”;
Enumerated types declared with enum class also have more control
over their underlying type. It may be any integral data type, such as
char, short or unsigned int, which essentially serves to determine the size of
the type. This is specified by a colon and the underlying type following the
enumerated type.
For example:
enum class biodata : int { dob, age};
enum class biodata : char{ name, place};
Try urself :
1.
#include<iostream>
using namespace std;
class s
{
Also See more posts : www.comsciguide.blogspot.com
public:
enum Pincode
{ hyd = 500001,
krnl = 518001,
kdp = 516001,
jmd = 516434
};
Pincode getpincode(string city)
{
if(city=="hyderabad")
return hyd;
if(city=="kurnool")
return krnl;
if(city=="kadapa")
return kdp;
if(city=="jammalamadugu")
return jmd;
}
};
int main()
{
s aa;
string p = "kurnool";
int a = aa.getpincode(p);
cout<<a;
return 0;
}
2.
#include<iostream>
using namespace std;
int main()
{
enum Color { RED, GREEN, BLUE};
Color r = RED;
switch(r)
Also See more posts : www.comsciguide.blogspot.com
{
case RED : std::cout << "redn"; break;
case GREEN : std::cout << "greenn"; break;
case BLUE : std::cout << "bluen"; break;
}
return 0;
}
Also See more posts : www.comsciguide.blogspot.com

More Related Content

What's hot

What's hot (14)

Huffman Algorithm By Shuhin
Huffman Algorithm By ShuhinHuffman Algorithm By Shuhin
Huffman Algorithm By Shuhin
 
Strings in c language
Strings in  c languageStrings in  c language
Strings in c language
 
Strings
StringsStrings
Strings
 
Handling of character strings C programming
Handling of character strings C programmingHandling of character strings C programming
Handling of character strings C programming
 
Huffman Student
Huffman StudentHuffman Student
Huffman Student
 
Structures
StructuresStructures
Structures
 
F sharp _vs2010_beta2
F sharp _vs2010_beta2F sharp _vs2010_beta2
F sharp _vs2010_beta2
 
Strings
StringsStrings
Strings
 
Huffman coding
Huffman coding Huffman coding
Huffman coding
 
C programming - String
C programming - StringC programming - String
C programming - String
 
Chapter16 pointer
Chapter16 pointerChapter16 pointer
Chapter16 pointer
 
Unit 8. Pointers
Unit 8. PointersUnit 8. Pointers
Unit 8. Pointers
 
Strings IN C
Strings IN CStrings IN C
Strings IN C
 
function, storage class and array and strings
 function, storage class and array and strings function, storage class and array and strings
function, storage class and array and strings
 

Similar to ENUM - make u r names as data types

Object Oriented Programming with C++
Object Oriented Programming with C++Object Oriented Programming with C++
Object Oriented Programming with C++
Rokonuzzaman Rony
 
What kind of a variable or ADT can be modelled with an enum -SolutionA.docx
What kind of a variable or ADT can be modelled with an enum -SolutionA.docxWhat kind of a variable or ADT can be modelled with an enum -SolutionA.docx
What kind of a variable or ADT can be modelled with an enum -SolutionA.docx
SUKHI5
 
User defined data type
User defined data typeUser defined data type
User defined data type
Amit Kapoor
 
Java căn bản - Chapter3
Java căn bản - Chapter3Java căn bản - Chapter3
Java căn bản - Chapter3
Vince Vo
 
5 structured programming
5 structured programming 5 structured programming
5 structured programming
hccit
 
Csharp4 operators and_casts
Csharp4 operators and_castsCsharp4 operators and_casts
Csharp4 operators and_casts
Abed Bukhari
 

Similar to ENUM - make u r names as data types (20)

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)
 
Enums in c
Enums in cEnums in c
Enums in c
 
Basic of c &c++
Basic of c &c++Basic of c &c++
Basic of c &c++
 
Object Oriented Programming with C++
Object Oriented Programming with C++Object Oriented Programming with C++
Object Oriented Programming with C++
 
Chapter1.pptx
Chapter1.pptxChapter1.pptx
Chapter1.pptx
 
Enumerated data types
Enumerated data typesEnumerated data types
Enumerated data types
 
Lecture 8
Lecture 8Lecture 8
Lecture 8
 
What kind of a variable or ADT can be modelled with an enum -SolutionA.docx
What kind of a variable or ADT can be modelled with an enum -SolutionA.docxWhat kind of a variable or ADT can be modelled with an enum -SolutionA.docx
What kind of a variable or ADT can be modelled with an enum -SolutionA.docx
 
23UCACC11 Python Programming (MTNC) (BCA)
23UCACC11 Python Programming (MTNC) (BCA)23UCACC11 Python Programming (MTNC) (BCA)
23UCACC11 Python Programming (MTNC) (BCA)
 
User defined data type
User defined data typeUser defined data type
User defined data type
 
Java căn bản - Chapter3
Java căn bản - Chapter3Java căn bản - Chapter3
Java căn bản - Chapter3
 
Java: Primitive Data Types
Java: Primitive Data TypesJava: Primitive Data Types
Java: Primitive Data Types
 
02a fundamental c++ types, arithmetic
02a   fundamental c++ types, arithmetic 02a   fundamental c++ types, arithmetic
02a fundamental c++ types, arithmetic
 
Daa chapter 1
Daa chapter 1Daa chapter 1
Daa chapter 1
 
Computer programming 2 Lesson 10
Computer programming 2  Lesson 10Computer programming 2  Lesson 10
Computer programming 2 Lesson 10
 
5 structured programming
5 structured programming 5 structured programming
5 structured programming
 
UNIT-II VISUAL BASIC.NET | BCA
UNIT-II VISUAL BASIC.NET | BCAUNIT-II VISUAL BASIC.NET | BCA
UNIT-II VISUAL BASIC.NET | BCA
 
C programming enumeration
C programming enumerationC programming enumeration
C programming enumeration
 
Csharp4 operators and_casts
Csharp4 operators and_castsCsharp4 operators and_casts
Csharp4 operators and_casts
 
COM1407: Type Casting, Command Line Arguments and Defining Constants
COM1407: Type Casting, Command Line Arguments and Defining Constants COM1407: Type Casting, Command Line Arguments and Defining Constants
COM1407: Type Casting, Command Line Arguments and Defining Constants
 

More from Ajay Chimmani

More from Ajay Chimmani (20)

24 standard interview puzzles - Secret mail puzzle
24 standard interview puzzles - Secret mail puzzle24 standard interview puzzles - Secret mail puzzle
24 standard interview puzzles - Secret mail puzzle
 
24 standard interview puzzles - The pot of beans
24 standard interview puzzles - The pot of beans24 standard interview puzzles - The pot of beans
24 standard interview puzzles - The pot of beans
 
24 standard interview puzzles - How strog is an egg
24 standard interview puzzles - How strog is an egg24 standard interview puzzles - How strog is an egg
24 standard interview puzzles - How strog is an egg
 
24 standard interview puzzles - 4 men in hats
24 standard interview puzzles - 4 men in hats24 standard interview puzzles - 4 men in hats
24 standard interview puzzles - 4 men in hats
 
Aptitude Training - TIME AND DISTANCE 3
Aptitude Training - TIME AND DISTANCE 3Aptitude Training - TIME AND DISTANCE 3
Aptitude Training - TIME AND DISTANCE 3
 
Aptitude Training - PIPES AND CISTERN
Aptitude Training - PIPES AND CISTERNAptitude Training - PIPES AND CISTERN
Aptitude Training - PIPES AND CISTERN
 
Aptitude Training - PROFIT AND LOSS
Aptitude Training - PROFIT AND LOSSAptitude Training - PROFIT AND LOSS
Aptitude Training - PROFIT AND LOSS
 
Aptitude Training - SOLID GEOMETRY 1
Aptitude Training - SOLID GEOMETRY 1Aptitude Training - SOLID GEOMETRY 1
Aptitude Training - SOLID GEOMETRY 1
 
Aptitude Training - SIMPLE AND COMPOUND INTEREST
Aptitude Training - SIMPLE AND COMPOUND INTERESTAptitude Training - SIMPLE AND COMPOUND INTEREST
Aptitude Training - SIMPLE AND COMPOUND INTEREST
 
Aptitude Training - TIME AND DISTANCE 4
Aptitude Training - TIME AND DISTANCE 4Aptitude Training - TIME AND DISTANCE 4
Aptitude Training - TIME AND DISTANCE 4
 
Aptitude Training - TIME AND DISTANCE 1
Aptitude Training - TIME AND DISTANCE 1Aptitude Training - TIME AND DISTANCE 1
Aptitude Training - TIME AND DISTANCE 1
 
Aptitude Training - PROBLEMS ON CUBES
Aptitude Training - PROBLEMS ON CUBESAptitude Training - PROBLEMS ON CUBES
Aptitude Training - PROBLEMS ON CUBES
 
Aptitude Training - RATIO AND PROPORTION 1
Aptitude Training - RATIO AND PROPORTION 1Aptitude Training - RATIO AND PROPORTION 1
Aptitude Training - RATIO AND PROPORTION 1
 
Aptitude Training - PROBABILITY
Aptitude Training - PROBABILITYAptitude Training - PROBABILITY
Aptitude Training - PROBABILITY
 
Aptitude Training - RATIO AND PROPORTION 4
Aptitude Training - RATIO AND PROPORTION 4Aptitude Training - RATIO AND PROPORTION 4
Aptitude Training - RATIO AND PROPORTION 4
 
Aptitude Training - NUMBERS
Aptitude Training - NUMBERSAptitude Training - NUMBERS
Aptitude Training - NUMBERS
 
Aptitude Training - RATIO AND PROPORTION 2
Aptitude Training - RATIO AND PROPORTION 2Aptitude Training - RATIO AND PROPORTION 2
Aptitude Training - RATIO AND PROPORTION 2
 
Aptitude Training - PERMUTATIONS AND COMBINATIONS 2
Aptitude Training - PERMUTATIONS AND COMBINATIONS 2Aptitude Training - PERMUTATIONS AND COMBINATIONS 2
Aptitude Training - PERMUTATIONS AND COMBINATIONS 2
 
Aptitude Training - PERCENTAGE 2
Aptitude Training - PERCENTAGE 2Aptitude Training - PERCENTAGE 2
Aptitude Training - PERCENTAGE 2
 
Aptitude Training - PERCENTAGE 1
Aptitude Training - PERCENTAGE 1Aptitude Training - PERCENTAGE 1
Aptitude Training - PERCENTAGE 1
 

Recently uploaded

The basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxThe basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptx
heathfieldcps1
 
Gardella_Mateo_IntellectualProperty.pdf.
Gardella_Mateo_IntellectualProperty.pdf.Gardella_Mateo_IntellectualProperty.pdf.
Gardella_Mateo_IntellectualProperty.pdf.
MateoGardella
 
An Overview of Mutual Funds Bcom Project.pdf
An Overview of Mutual Funds Bcom Project.pdfAn Overview of Mutual Funds Bcom Project.pdf
An Overview of Mutual Funds Bcom Project.pdf
SanaAli374401
 
Beyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactBeyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global Impact
PECB
 
Gardella_PRCampaignConclusion Pitch Letter
Gardella_PRCampaignConclusion Pitch LetterGardella_PRCampaignConclusion Pitch Letter
Gardella_PRCampaignConclusion Pitch Letter
MateoGardella
 
1029-Danh muc Sach Giao Khoa khoi 6.pdf
1029-Danh muc Sach Giao Khoa khoi  6.pdf1029-Danh muc Sach Giao Khoa khoi  6.pdf
1029-Danh muc Sach Giao Khoa khoi 6.pdf
QucHHunhnh
 

Recently uploaded (20)

INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptxINDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
 
SECOND SEMESTER TOPIC COVERAGE SY 2023-2024 Trends, Networks, and Critical Th...
SECOND SEMESTER TOPIC COVERAGE SY 2023-2024 Trends, Networks, and Critical Th...SECOND SEMESTER TOPIC COVERAGE SY 2023-2024 Trends, Networks, and Critical Th...
SECOND SEMESTER TOPIC COVERAGE SY 2023-2024 Trends, Networks, and Critical Th...
 
Unit-V; Pricing (Pharma Marketing Management).pptx
Unit-V; Pricing (Pharma Marketing Management).pptxUnit-V; Pricing (Pharma Marketing Management).pptx
Unit-V; Pricing (Pharma Marketing Management).pptx
 
Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"
Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"
Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"
 
Key note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfKey note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdf
 
The basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxThe basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptx
 
microwave assisted reaction. General introduction
microwave assisted reaction. General introductionmicrowave assisted reaction. General introduction
microwave assisted reaction. General introduction
 
Gardella_Mateo_IntellectualProperty.pdf.
Gardella_Mateo_IntellectualProperty.pdf.Gardella_Mateo_IntellectualProperty.pdf.
Gardella_Mateo_IntellectualProperty.pdf.
 
An Overview of Mutual Funds Bcom Project.pdf
An Overview of Mutual Funds Bcom Project.pdfAn Overview of Mutual Funds Bcom Project.pdf
An Overview of Mutual Funds Bcom Project.pdf
 
psychiatric nursing HISTORY COLLECTION .docx
psychiatric  nursing HISTORY  COLLECTION  .docxpsychiatric  nursing HISTORY  COLLECTION  .docx
psychiatric nursing HISTORY COLLECTION .docx
 
Beyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactBeyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global Impact
 
fourth grading exam for kindergarten in writing
fourth grading exam for kindergarten in writingfourth grading exam for kindergarten in writing
fourth grading exam for kindergarten in writing
 
Application orientated numerical on hev.ppt
Application orientated numerical on hev.pptApplication orientated numerical on hev.ppt
Application orientated numerical on hev.ppt
 
PROCESS RECORDING FORMAT.docx
PROCESS      RECORDING        FORMAT.docxPROCESS      RECORDING        FORMAT.docx
PROCESS RECORDING FORMAT.docx
 
Gardella_PRCampaignConclusion Pitch Letter
Gardella_PRCampaignConclusion Pitch LetterGardella_PRCampaignConclusion Pitch Letter
Gardella_PRCampaignConclusion Pitch Letter
 
1029-Danh muc Sach Giao Khoa khoi 6.pdf
1029-Danh muc Sach Giao Khoa khoi  6.pdf1029-Danh muc Sach Giao Khoa khoi  6.pdf
1029-Danh muc Sach Giao Khoa khoi 6.pdf
 
Unit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptxUnit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptx
 
Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptxBasic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
 
Paris 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityParis 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activity
 
Accessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactAccessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impact
 

ENUM - make u r names as data types

  • 1. Keywords – II Enum : An enum type is a special data type that enables for a variable to be a set of predefined constants. The variable must be equal to one of the values that have been predefined for it. The syntax is : enum Tag_name {Variables_names} For example: enum tag_name{ value1, value2,...,valueN }; Here, tag_name is the name of enumerated data type. And value1, value2,....,valueN are values of type tag_name. • If the first enumerator does not have an initializer (if it is not initialized by the user), the associated value is zero. For any other enumerator whose definition does not have an initializer, the associated value is the value of the previous enumerator plus one. • Enum variables are the same size as an int variable. This is because each enumerator is automatically assigned an integer value based on it’s position in the enumeration list In the above exapmle, By default, value1 will be equal to 0, value2 will be 1 and so on... But, the programmer can change the default values to Also See more posts : www.comsciguide.blogspot.com
  • 2. their own values. //Changing the default value of enum elements enum numbers { zero = 0, five = 5, twentyone = 21, thirty = 30 }; cout<<zero<<endl; //output = 0 cout<<five<<endl; //output = 5 cout<<twentyone<<endl; //output = 21 cout<<thirty<<endl; //output = 30 enum months { january = 1, february, march, april, may, june, july, august, september, october, november, december}; By creating the enum months, you have also created a new data type called months. You can use this new data type as you might any other data type. For example: months jan ; jan = january; • At the declaration time, we can also initialize the values with the primitive operators(only a few). enum Letters { A, B, C=-10, D, E=1, F, G=F+C}; //A=0, B=1, C=-10, D=-9, E=1, F=2, G=12 • The enum constants can be assigned to other enumerators. enum color { red, yellow, green = 20, blue }; Also See more posts : www.comsciguide.blogspot.com
  • 3. color col = red; int n = blue; // n == 21 cout<<col; // output =0; • Already declared enumerators can't be reassigned explicitly. enum color { red = 0, yellow, green, blue }; color red = 11; // compilation error However, the compiler will not implicitly cast an integer to an enumerated value. The following will produce a compiler error: enum color { red = 0, yellow, green, blue }; color red1 = 11; // compilation error • But there is one way to change enumerators values.This can be done using the static_cast operator by forcing the compiler to put the value in the enumerated data types. enum color { red = 0, yellow, green, blue }; color red = static_cast<color>(11); // error color red1 = static_cast<color>(11) // no error • Assigning between enumerators can be done but between integers and enumerators results in compilation error. And enum also should be of the same type. enum color { red = 0, yellow, green, blue }; color red1 = 11; // compilation error color red1 = red; // no error Also See more posts : www.comsciguide.blogspot.com
  • 4. enum color { red = 0, yellow, green, blue }; enum color1 {violet ,orange, black ,white }; color red1 = white; // compilation error • Enumerated types are incredibly useful for code documentation and readability purposes when you need to represent a specific number of states. enum Pincode { hyd = 500001, krnl = 518001, kdp = 516001, jmd = 516434 }; Pincode getpincode() { if(city == ”hyderabad”) return hyd; if(city == ”kurnool”) return krnl; if(city == ”kadapa”) return kdp; if(city == ”jammalamadugu”) return jmd; } This will be much easier to read than returning the number values. Enumerators with class : In gerenal, Enumerators are implicitly converted into the int data type. It is also possible to have char, float etc thus preserving data type safety. They are declared with enum class (or enum struct) instead of just enum. Also See more posts : www.comsciguide.blogspot.com
  • 5. For example : enum class biodata{ name, age, place, dob }; • Each enum value is scoped with the name of the enum class. In other words, to access the enum values, you must write: enum class Colors {black, blue, green, cyan}; Colors mycolor; mycolor = Colors::blue; if (mycolor == Colors::green) cout<<”the color is green”; Enumerated types declared with enum class also have more control over their underlying type. It may be any integral data type, such as char, short or unsigned int, which essentially serves to determine the size of the type. This is specified by a colon and the underlying type following the enumerated type. For example: enum class biodata : int { dob, age}; enum class biodata : char{ name, place}; Try urself : 1. #include<iostream> using namespace std; class s { Also See more posts : www.comsciguide.blogspot.com
  • 6. public: enum Pincode { hyd = 500001, krnl = 518001, kdp = 516001, jmd = 516434 }; Pincode getpincode(string city) { if(city=="hyderabad") return hyd; if(city=="kurnool") return krnl; if(city=="kadapa") return kdp; if(city=="jammalamadugu") return jmd; } }; int main() { s aa; string p = "kurnool"; int a = aa.getpincode(p); cout<<a; return 0; } 2. #include<iostream> using namespace std; int main() { enum Color { RED, GREEN, BLUE}; Color r = RED; switch(r) Also See more posts : www.comsciguide.blogspot.com
  • 7. { case RED : std::cout << "redn"; break; case GREEN : std::cout << "greenn"; break; case BLUE : std::cout << "bluen"; break; } return 0; } Also See more posts : www.comsciguide.blogspot.com