/* program to classify month-day combinations * in terms of season and weeks - illustrate short-cut */ #include using namespace std; // Function Prototypes void classify(int,int); void translate(int); void whichseason(int); void whichweek(int); int main() { int month,day; char answer; do { // prompt for the month and day cout << endl << "Type in the number of a month (1-January ... 12-December): "; cin >> month; cout << "Type in the a date within the month (1-31): "; cin >> day; cout << endl << "month = " << month << " day = " << day << endl; // call a function to classify the month-day combination classify (month,day); // prompt whether or not to continue cout << endl << "Type Y to continue; N to stop: "; cin >> answer; } while (answer == 'Y'); // system("pause"); //un-comment when using DevC++ return 0; } /* Function classify() * Input: * month - a number specifying a month in the year * day - a number specifying a day within a month * Process: * calls a function to translate the month into a string * calls a function to determine which season month is in * calls a function to determine which week of the month * day is in. * Illegal entries for month and day will be caught * Output: * prints the results of the classification */ void classify(int month, int day) { // test for valid month if (month < 1 || month > 12) cout << month << " is not a valid value for the month" << endl; else { // valid month entered translate(month); //translate integer to string whichseason(month); } // test for valid day if (day < 1 || day > 31) // invalid day entered cout << day << " is not a valid value for the day" << endl; else // valid day entered whichweek(day); return; } /* Function translate() * Input: * month - a number specifying a month in the year * Process: * translates the month into a string * Output: * prints the name associated with month */ void translate(int month) { cout << "month "<< month << " is "; if (month == 1) cout << "January"; else if (month == 2) cout << "February"; else if (month == 3) cout << "March"; else if (month == 4) cout << "April"; else if (month == 5) cout << "May"; else if (month == 6) cout << "June"; else if (month == 7) cout << "July"; else if (month == 8) cout << "August"; else if (month == 9) cout << "September"; else if (month == 10) cout << "October"; else if (month == 11) cout << "November"; else cout << "December"; //if (month == 12) cout << endl; return; } /* Function whichseason() * Input: * month - a number specifying a month in the year * Process: * determines which season month is in * Output: * prints the name of the season */ void whichseason(int month) { if (month == 12 || month == 1 || month == 2) cout << "Winter is the season"; else if (month == 3 || month == 4 || month == 5) cout << "Spring is the season"; else if (month == 6 || month == 7 || month == 8) cout << "Summer is the season"; else // if (month == 9 || month == 10 || month == 11) cout << "Fall is the season"; cout << endl; return; } /* Function whichweek() * Input: * day - a number specifying a day within a month * Process: * determines which week of the month day is in. * assumes each week has 7 days. * Output: * prints the week within the month */ void whichweek(int day) { cout << (day+6)/7 << " is the week number for day " << day << endl; return; }