#include #include using namespace std; enum MonthT {JANUARY, FEBRUARY, MARCH, APRIL, MAY, JUNE, JULY, AUGUST, SEPTEMBER, OCTOBER, NOVEMBER, DECEMBER, NO_MONTH}; const MonthT FIRST_MONTH = JANUARY; const MonthT LAST_MONTH = DECEMBER; const int MONTHT_SIZE = 12; string MonthTToString(MonthT m); MonthT NextMonth(MonthT m); MonthT StringToMonthT(string month); void CommentOnMonth(MonthT month); void GetMonthName(string & name); int main () { MonthT i,month; string input; MonthT randomMonth; // initialize the random number generator exactaly once srand(time(NULL)); //I don't rally like this. for(i=JANUARY; i<= DECEMBER;i= MonthT(i + 1)) { cout << "Month number " << i << " is " << MonthTToString(i) << endl; } cout << endl << endl; // I like this much bettter for(i=FIRST_MONTH; i<= LAST_MONTH; i = NextMonth(i)) { cout << "Month number " << i << " is " << MonthTToString(i) << endl; } cout << endl << endl; // look you have to prime the pump here too! GetMonthName(input); while (input != "QUIT") { month = StringToMonthT(input); if (month == NO_MONTH) { randomMonth = MonthT(rand() % MONTHT_SIZE); cout << " That is not a valid month, did you mean " << MonthTToString(randomMonth) << "?" << endl; } else { CommentOnMonth(month); } cout << endl; GetMonthName(input); } return 0; } string MonthTToString(MonthT m){ string returnValue; switch (m) { case JANUARY: returnValue = "January"; break; case FEBRUARY: returnValue = "February"; break; case MARCH: returnValue = "March"; break; case APRIL: returnValue = "April"; break; case MAY: returnValue = "May"; break; case JUNE: returnValue = "June"; break; case JULY: returnValue = "July"; break; case AUGUST: returnValue = "August"; break; case SEPTEMBER: returnValue = "September"; break; case OCTOBER: returnValue = "October"; break; case NOVEMBER: returnValue = "November"; break; case DECEMBER: returnValue = "December"; break; } return returnValue; } MonthT StringToMonthT(string month){ MonthT returnValue=NO_MONTH; int i; // make it all lower case, and stop if there is a non-alpha character for(i=0; i= FIRST_MONTH && nextValue <= LAST_MONTH) { returnMonth = MonthT (nextValue); } return returnMonth; } void CommentOnMonth(MonthT month) { if (JUNE == month || JULY == month || AUGUST == month) { cout << "I really like the month of " << MonthTToString(month) << "!" << endl; } else if (month == APRIL || MAY || SEPTEMBER || OCTOBER) { cout << MonthTToString(month) << " is a mild month, not too bad" << endl; } else { cout << MonthTToString(month) << ", look out, SNOW!"<< endl; } } void GetMonthName(string & name){ int i; cout << " Enter a month name (or QUIT to quit) =>"; cin >> name; for(i=0;i