#include void print_monthname(int); int month_length(int, int); int is_leap_year(int); int print_month(int, int, int); main() { int i; int start_on, year; cout << "Which year> "; cin >> year; cout << "On which day does the year begin> "; cin >> start_on; i = 1; while (i <= 12) { print_monthname(i); start_on = print_month(i, year, start_on); i++; } } void print_monthname(int m) /* Displays the name of the given month m on a line by itself. m - month number (1 - January, ..., 12 - December) */ { if (m == 1) cout << "January" << endl; if (m == 2) cout << "February" << endl; if (m == 3) cout << "March" << endl; if (m == 4) cout << "April" << endl; if (m == 5) cout << "May" << endl; if (m == 6) cout << "June" << endl; if (m == 7) cout << "July" << endl; if (m == 8) cout << "August" << endl; if (m == 9) cout << "September" << endl; if (m ==10) cout << "October" << endl; if (m ==11) cout << "November" << endl; if (m ==12) cout << "December" << endl; return; } int month_length(int m, int y) /* Computes the number of days in the given month. The year is required to determine if February has 28 or 29 days. m - month we are interested in y - year we are interested in returns - the number of days in the given month */ { if (m == 1) return(31); if (m == 2) { if (is_leap_year(y)) return(29); else return(28); } if (m == 3) return(31); if (m == 4) return(30); if (m == 5) return(31); if (m == 6) return(30); if (m == 7) return(31); if (m == 8) return(31); if (m == 9) return(30); if (m == 10) return(31); if (m == 11) return(30); if (m == 12) return(31); return(0); } int is_leap_year(int y) /* Determines if the given year is a leap year. y - the year we are interested in returns - 1 if the year is a leap year 0 if the year is not a leap year */ { return((y % 4) == 0); } int print_month(int month, int year, int day) /* Displays the days of the given month in the usual calendar form. month - the month we would like to see year - the year we are interested in day - the starting day of the month returns - the starting day of the next month. If this month ends on day 3 then next month should start on day 4. */ { int i, max_days, cur_day; i = 1; while (i < day) { cout << " "; i++; } cur_day = day; max_days = month_length(month, year); i = 1; while (i <= max_days) { cout.width(3); cout << i; cur_day++; if (cur_day == 8) { cout << endl; cur_day = 1; } i++; } cout << endl; return(cur_day); }