This C++ Program which illustrates the use of enumerations. The program creates an enumeration of months, creates an enumeration variable, assigns it a month value and prints a comment on the current month.
Here is source code of the C++ program which illustrates the use of enumerations. The C++ program is successfully compiled and run on a Linux system. The program output is also shown below.
/*
* C++ Program to Illustrate the use of Enumerations
*/
#include<iostream>
using namespace std;
enum Month {January = 1 ,February = 2, March = 3, April = 4, May = 5,
June = 6, July = 7, August = 8, September = 9, October = 10,
November = 11, December = 12};
int main()
{
Month month;
month = August;
cout << "The month is August." << endl;
/* Printing comments on current Month */
if (month >= March && month <= May)
cout << "Yay, It is Spring!" << endl;
else if (month >= June && month <= August)
cout << "It is Summer, Who needs an Ice Cream?" << endl;
else if (month >= September && month <= November)
cout << "I am enjoying Autumn, Aren't You?" << endl;
else
cout << "Ooh, It is very cold outside! It's Winter!" << endl;
}
$ g++ main.cpp $ ./a.out The month is August. It is Summer, Who needs an Ice Cream?
Sanfoundry Global Education & Learning Series – 1000 C++ Programs.
advertisement
If you wish to look at all C++ Programming examples, go to C++ Programs.
Related Posts:
- Practice Programming MCQs
- Check C++ Books
- Practice Computer Science MCQs
- Check Programming Books
- Check Computer Science Books