CS 1711 - Assignment 3

Due: 5 pm, October 23
(This is a hard dead-line for both hard copy and drop-box submission. Do not leave it to the last minute. `I couldn't get my printer to work' or `The network was down at 4:30' are not accepted excuses for lateness.)

Question

Note change in computation of r!!

Write a program that prompts the user for a month and year, then displays a representation of the month on the screen.

What day the month starts on

Reverend Zeller developed a formula for computing the day of the week on which a date fell or will fall. Suppose we let a, b, c, and d be integers defined as follows:
  1. a = The number of the month with March = 1, April = 2, and so on, with January and February counted as months 11 and 12 of the preceding year.
  2. b = day of the month
  3. c = year of the century
  4. d = century
For example July 31, 1929 gives the values a=5, b=31, c=29, d=19 and January 3, 1970 gives a=11, b=3, c=69, d=19. Note the value of the year!.

Now calculate the integer values:

  1. w = (13a - 1)/5
  2. x = c/4
  3. y = d/4
  4. z = w + x + y + b + c - 2d + 7
  5. r = ((z modulo 7) + 7) modulo 7
The resulting value of r will contain the day of the week on which the date falls with 0 representing Sunday, 1 representing Monday, etc.

Month Length

Most months use a standard length of either 30 or 31 days. The number of days in February depends on whether or not it is a leap year. To calculate whether or not a certain year is a leap year, you use the following rules:
  1. if a year is a multiple of 4 then it is a leap year unless it breaks the next rule.
  2. if the year is multiple of 100 and a multiple of 400 it is a leap year.
For example the year 1996 was a leap year. The year 1900 is divisible by 100 but not by 400 so it is not a leap year. The year 2000 is divisible by 100 and 400 so it is a leap year.

Recall: The integer x is evenly divisible by y if x%y == 0.

Sample Run

Monthly Calendar Program
Which month (1=January, 2=February, ...)> 10
Which year> 1998


   October 1998
Su Mo Tu We Th Fr Sa
             1  2  3
 4  5  6  7  8  9 10
11 12 13 14 15 16 17
18 19 20 21 22 23 24
25 26 27 28 29 30 31

Some specifications of functions to use in your program:

void print_monthname(int month, int year)
/* Displays the name of the given month m on a line by itself. 
month - month number (1 - January, ..., 12 - December)*/

int month_length(int month, int year)
/* Computes the number of days in the given month. The year is required to determine if
February has 28 or 29 days. 
month - month we are interested in; year - year we are interested in
returns - the number of days in the given month */

int is_leap_year(int year)
/* Determines if the given year is a leap year; year - the year we are interested in 
returns - 1 if the year is a leap year; 0 if the year is not a leap year */

int first_day(int month, int year);
/*
month - the month we would like to see; 
year - the year we are interested in
returns - the day of the week on which the first day of the given month
falls within the given year.
*/


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.