63 087
Assignments Done
99,1%
Successfully Done
In July 2018

Answer to Question #23859 in C++ for emmanuel

Question #23859
define an enumeration called months of the year and use it to define a function which takes a month as argument and returns it as a constant string.
Expert's answer
#include <conio.h>
#include <iostream>

using namespace std;

enum MonthsOfTheYear
{
January,
February,
March,
April,
May,
June,
July,
August,
September,
October,
November,
December
};

const char* month_to_string(MonthsOfTheYear month)
{
static const char* month_names[12] = { "January", "February", "March", "April", "May", "June", "July",
quot;August", "September", "October", "November", "December" };
int index = (int)month;
return (index < 0 || index > 11) ? "Wrong month" : month_names[index];
}
& &
int main()
{
cout << month_to_string(March) << endl;
cout << month_to_string(November) << endl;
cout << month_to_string(July) << endl;

_getch();
return 0;
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be first!

Leave a comment

Ask Your question

Submit
Privacy policy Terms and Conditions