0% found this document useful (0 votes)
20 views3 pages

Month. The Month Enumeration Should Consist of Twelve Constants Representing The Months

The student is tasked with creating a program that prompts the user for a number representing a month and displays the corresponding month name. To do this, the student must define a Year class with a Month enumeration of the 12 months as constants and map the user's input number to the appropriate month name for output using this Year class and Month enumeration.

Uploaded by

Dheeraj Kumar
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
20 views3 pages

Month. The Month Enumeration Should Consist of Twelve Constants Representing The Months

The student is tasked with creating a program that prompts the user for a number representing a month and displays the corresponding month name. To do this, the student must define a Year class with a Month enumeration of the 12 months as constants and map the user's input number to the appropriate month name for output using this Year class and Month enumeration.

Uploaded by

Dheeraj Kumar
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 3

The task for the student is to create a program that prompts the user to enter a number

representing a month and displays the corresponding month as output. To accomplish this,
the student should implement a class named Year that includes an enumeration called
Month. The Month enumeration should consist of twelve constants representing the months
of the year. The student needs to ensure that the program utilizes the Year class and the
Month enumeration to correctly map the input number to the corresponding month name for
display.

#include <iostream>

#include <string>

using namespace std;

class Year {

public:

enum Month {

JANUARY = 1,

FEBRUARY,

MARCH,

APRIL,

MAY,

JUNE,

JULY,

AUGUST,

SEPTEMBER,

OCTOBER,

NOVEMBER,

DECEMBER

};

};
int main() {

int monthNumber;

cin >> monthNumber;

if (monthNumber >= Year::JANUARY && monthNumber <= Year::DECEMBER) {

Year::Month month = static_cast<Year::Month>(monthNumber);

switch (month) {

case Year::JANUARY: cout << "Month: JANUARY" << endl; break;

case Year::FEBRUARY: cout << "Month: FEBRUARY" << endl; break;

case Year::MARCH: cout << "Month: MARCH" << endl; break;

case Year::APRIL: cout << "Month: APRIL" << endl; break;

case Year::MAY: cout << "Month: MAY" << endl; break;

case Year::JUNE: cout << "Month: JUNE" << endl; break;

case Year::JULY: cout << "Month: JULY" << endl; break;

case Year::AUGUST: cout << "Month: AUGUST" << endl; break;

case Year::SEPTEMBER: cout << "Month: SEPTEMBER" << endl; break;

case Year::OCTOBER: cout << "Month: OCTOBER" << endl; break;

case Year::NOVEMBER: cout << "Month: NOVEMBER" << endl; break;

case Year::DECEMBER: cout << "Month: DECEMBER" << endl; break;

} else {

cout << "Invalid month input" << endl;

}
return 0;

You might also like