Week days example using Enumeration in C++


The code defines an enumeration type named week, which has seven constants corresponding to the days of the week. The main() function creates an instance of the week enumeration named today and initializes it to the constant Wednesday. The cout statement then prints the day of the week represented by today incremented by 1.

Since the first constant Sunday has the value 0, and the subsequent constants have incrementing values by 1, adding 1 to today will give us the value of the next day of the week. In this case, since today is initialized to Wednesday, adding 1 to it will give us the value 4 (corresponding to Thursday).

Source Code

#include<iostream>
using namespace std;
enum week { Sunday, Monday, Tuesday, Wednesday, Thursday, Friday, Saturday };
int main()
{
  week today;
  today=Wednesday;
  cout<<"Day "<<today+1;
  return 0;
}
To download raw file Click Here

Output

Day 4

Program List


Flow Control

IF Statement Examples


Switch Case


Goto Statement


Break and Continue


While Loop


Do While Loop


For Loop


Friend Function in C++


String Examples


Array Examples


Structure Examples


Structure & Pointer Examples


Structure & Functions Examples


Enumeration Examples


Template Examples


Functions


Inheritance Examples

Hierarchical Inheritance


Hybrid Inheritance


Multilevel Inheritance


Multiple Inheritance


Single Level Inheritance


Class and Objects

Constructor Example


Destructor Example


Operator Overloading Example


Operator and Function Example


List of Programs


Pointer Examples


Memory Management Examples


Pointers and Arrays


Virtual Function Examples