Swaminathan K
asked on
can enums define their own functions in c++
Hi Team,
below is the code , I have written in C++ for enums . My question is is it possible to create an enum class with it own functions to display the enum information just like in java programming langauge.
Also I want to accept an enumerator name and then display its value , is it possible in enums using c++
Just like below , can i accept a enumerator name instead of integer value to display the info using it?
Also , I need to know
below is the code , I have written in C++ for enums . My question is is it possible to create an enum class with it own functions to display the enum information just like in java programming langauge.
Also I want to accept an enumerator name and then display its value , is it possible in enums using c++
Just like below , can i accept a enumerator name instead of integer value to display the info using it?
cout<<"Enter the day of the week";
cin>>wk;
wk1=static_cast<weekdays>(wk);
Also , I need to know
#include<iostream>
using namespace std;
int main()
{
// declare and use enums
int wk;
enum weekdays {MON=1,TUE=2,WED,THU,FRI };
enum weekends {SAT=1,SUN};
enum weekdays wk1;
enum weekends wkend1;
wk1=WED;
wkend1=SUN;
cout<<"The value of wk1 is :"<<wk1;
cout<<"The value of wkend1 is :"<<wkend1;
cout<<"Enter the day of the week";
cin>>wk;
wk1=static_cast<weekdays>(wk);
switch(wk1)
{
case MON:
cout<<"The day of the week is MONDAY";
break;
case TUE:
cout<<"The day of the week is TUESDAY";
break;
case WED:
cout<<"The day of the week is WEDNESDAY";
break;
case THU:
cout<<"The day of the week is THURSDAY";
break;
case FRI:
cout<<"The day of the week is FRIDAY";
break;
default:
cout<<"The invalid option";
}
cout<<endl<<endl;
return 0;
}
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.