Home Uncategorized Write a program to illustrate Enumerations

Write a program to illustrate Enumerations

SHARE

AIM: Write a C++ program to illustrate Enumerations.

THEORY:

An enumeration is a distinct type whose value is restricted to a range of values (see below for details), which may include several explicitly named constants (“enumerators”). The values of the constants are values of an integral type known as the underlying type of the enumeration.

SOURCE CODE:

#include<iostream>
using namespace std;
enum week{Sunday,Monday,Tuesday,Wednesday,Thursday,Friday,Saturday};
enum Season{spring=3,Summer=4,Autumn=1,Winter=2};
int main()
{
   week today;
   today=Wednesday;
   cout<<“Day = “<<today+1<<“\n”;
   Season S;
   S=Summer;
   cout<<“Summer = “<<S<<endl;
   return 0;
}

Output:
Day = 4
Summer = 4

Back to Programs.