(C++ Program)
Create an enum (enumeration) for the Months of the Year.
Use a Switch statement Selection structure to output the Various International/Domestic Holidays for each month as following:
Jan - New Years Day
Feb - Valentines Day
March - St. Patrick's Day
April - Earth Day
May - MayPole Day
June - Juneteenth
July - Eid-al-Adha
August - National Mahjong Day
September - Talk Like a Pirate Day
October - United Nations Day
November - International Computer Security Day
December - Human Rights Day
c++ Program :
//header files
#include <iostream>
using namespace std;
//enum
enum Months{
Jan,Feb,March,April,May,June,July,August,September,
October,November,December
};
//main() method
int main()
{
int month;//declaring variable to store month
//asking user month
cout<<"Enter month : ";
cin>>month;//reading month
//using switch statement
switch(month)
{
case 0://when month is Jan
cout<<"Jan-New Years Day"<<endl;
break;
case 1://when month is Feb
cout<<"Feb - Valentines Day"<<endl;
break;
case 2://when month is March
cout<<"March - St. Patrick's Day"<<endl;
break;
case 3://when month is April
cout<<"April - Earth Day"<<endl;
break;
case 4://when month is May
cout<<"May - MayPole Day"<<endl;
break;
case 5://when month is June
cout<<"June - Juneteenth"<<endl;
break;
case 6://when month is July
cout<<"July - Eid-al-Adha"<<endl;
break;
case 7://when month is August
cout<<"August - National Mahjong Day"<<endl;
break;
case 8://when month is September
cout<<"September - Talk Like a Pirate Day"<<endl;
break;
case 9://when month is October
cout<<"October - United Nations Day"<<endl;
break;
case 10://when month is November
cout<<"November - International Computer Security
Day"<<endl;
break;
case 11://when month is December
cout<<"December - Human Rights Day"<<endl;
break;
default://when invalid number is entered
cout<<"Enter valid month"<<endl;
break;
}
return 0;
}
==========================================
Screen 1:Screen when invalid month is entered
Screen 2:Screen when valid month is entered
Get Answers For Free
Most questions answered within 1 hours.