/*
 * File: calendar.c
 * ----------------
 * This program is used to generate a calendar for a year
 * entered by the user.
 */

#include 
#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);
void IndentFirstLine(int weekday);
int PrintDays (int no_of_days, int weekday);
int MonthDays(int month, int year);
int FirstDayOfMonth(int month, int year);
char * MonthName(int month);
int IsLeapYear(int year);

// 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)
{
    cout << "This program displays a calendar for a full\n";
    cout << "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.
 */

int GetYearFromUser(void)
{
    int year;

    while (1) {
         cout << "Which year? ";
        cin >> year;
        if (year > 1899) return (year);
        cout <<"The year must be at least 1900.\n";
    }
}

/*
 * 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);
        cout << "\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;

    cout << "  \n   "<< MonthName(month)<<" " <