/* * File: calendar.c * ---------------- * This program is used to generate a calendar for a year * entered by the user. */ #include /* * Constants: * ---------- * Days of the week are represented by the integers 0-6. * Months of the year are identified by the integers 1-12; * because this numeric representation for months is in * common use, no special constants are defined. */ #define SUNDAY 0 #define MONDAY 1 #define TUESDAY 2 #define WEDNESDAY 3 #define THURSDAY 4 #define FRIDAY 5 #define SATURDAY 6 /* Function prototypes */ void GiveInstructions(void); int GetYearFromUser(void); void PrintCalendar(int year); void PrintCalendarMonth(int month, int year); int FirstDayOfMonth(int month, int year); char * MonthName(int month); You need to put function prototypes that are missing here. /* Main program */ int main(void) { int year; GiveInstructions(); year = GetYearFromUser(); PrintCalendar(year); return 0; } /* * Function: GiveInstructions * Usage: GiveInstructions(); * -------------------------- * This procedure prints out instructions to the user. */ void GiveInstructions(void) { printf("This program displays a calendar for a full\n"); printf("year. Any year after 1899 is okay.\n"); } /* * Function: GetYearFromUser * Usage: year = GetYearFromUser(); * -------------------------------- * This function reads in a year from the user and returns * that value. If the user enters a year before 1900, the * function gives the user another chance. Using a while loop here * is a good idea. The loop should only end when a good year is entered. */ int GetYearFromUser(void) { Write your function here. } /* * Function: PrintCalendar * Usage: PrintCalendar(year); * --------------------------- * This procedure prints a calendar for an entire year. */ void PrintCalendar(int year) { int month; for (month = 1; month <= 12; month++) { PrintCalendarMonth(month, year); printf("\n"); } } /* * Function: PrintCalendarMonth * Usage: PrintCalendarMonth(month, year); * --------------------------------------- * This procedure prints a calendar for the given month * and year. */ void PrintCalendarMonth(int month, int year) { int weekday, no_of_days ; printf(" %s %d\n", MonthName(month), year); printf(" Su Mo Tu We Th Fr Sa\n"); no_of_days = MonthDays(month, year); weekday = FirstDayOfMonth(month, year); IndentFirstLine(weekday); weekday = PrintDays (no_of_days, weekday); if (weekday != SUNDAY) printf("\n"); } /* * Function: IndentFirstLine * Usage: IndentFirstLine(weekday); * -------------------------------- * This procedure indents the first line of the calendar * by printing enough blank spaces to get to the position * on the line corresponding to weekday. It does this simply * by spacing over as many spaces are needed so that the numbers * begin printing in the correct columns. */ void IndentFirstLine(int weekday) { Write your function here. } /* * Function: PrintDays * Usage: PrintDays (no_of_days, weekday) * -------------------------------- * This procedure takes the number of days in a month and * the first day in that month and prints out the dates in * that month in the correct columns. * It returns the value of the day after the last day of * the month to the function PrintCalendarMonth. * You might use either a switch or if-else statement here. */ int PrintDays (int no_of_days, int weekday) { int day; for (day = 1; day <= no_of_days; day++) { printf(" %2d", day); if (weekday == SATURDAY) printf("\n"); weekday = (weekday + 1) % 7; } return (weekday); } /* * Function: MonthDays * Usage: ndays = MonthDays(month, year); * -------------------------------------- * MonthDays returns the number of days in the indicated * month and year. The year is required to handle leap years. * You may want to use the IsLeapYear function in this function. */ int MonthDays(int month, int year) { Write your function here. } /* * Function: FirstDayOfMonth * Usage: weekday = FirstDayOfMonth(month, year); * ---------------------------------------------- * This function returns the day of the week on which the * indicated month begins. This program simply counts * forward from January 1, 1900, which was a Monday. * It may be useful to use the IsLeapYear function. */ int FirstDayOfMonth(int month, int year) { Write your function here. } /* * Function: MonthName * Usage: name = MonthName(month); * ------------------------------- * MonthName converts a numeric month in the range 1-12 * into the string name for that month. */ char * MonthName(int month) { switch (month) { case 1: return ("January"); case 2: return ("February"); case 3: return ("March"); case 4: return ("April"); case 5: return ("May"); case 6: return ("June"); case 7: return ("July"); case 8: return ("August"); case 9: return ("September"); case 10: return ("October"); case 11: return ("November"); case 12: return ("December"); default: return ("Illegal month"); } } /* * Function: IsLeapYear * Usage: if (IsLeapYear(year)) . . . * ---------------------------------- * This function returns 1 if year is a leap year, 0 if not. */ int IsLeapYear(int year) { Write your function here. }