CS 113: Introduction to Computer Science II with Introduction to C

Steve Homer---Fall 1998

Homework 2---due Tuesday, February 16 before 10:00 PM

Reading: Kelley and Pohl, Chapters 5-8, pages 191-305


The files you must submit for this homework are exactly "calendar.c" and "calendar.scr" (containing a script of your source code, compilation, and test runs, in that order).

You are to write 5 of the functions in a calendar program. The calendar should be in the European format where each week starts with Monday and ends with Sunday (rather than Sunday through Saturday as we do here). The program takes as input any four digit year after 1899 and outputs the calendar of that year.

You can find the detailed outline of the program here. It can also be found in the file /cs/course/cs113/current/hw2/calendar.c. However, the program we provide is the standard one which starts each week with Sunday. You will need to make several changes to have your program begin with Monday.

One reasonable way to attack this is to first write the function in the code we provide so that you will be getting the usual American calendar to work. Then change this program to do the European calendar, starting with Monday. If you do the first part well, changing it to European style is surprisingly short and easy.

You will also need to write the 5 functions indicated. They are GetYearFromUser, FirstDayOfMonth, MonthDays, IndentFirstLine and IsLeapYear.

The output for the year 1952 is in the directory /cs/course/cs113/current/hw2 for you to look at.

The rule for leap years is: A year is a leap year if it is evenly divisible by 4 unless it is evenly divisible by 100 AND NOT evenly divisible by 400. (So 2000 is a leap year while 1900 is not.)

Check your program by running it on several different inputs. You should turn in the output from the years 1999 and 1984 (in that order).

As a suggestion, give your executable (not to be submitted) a name like "calprog", since "cal" and "calendar" are already commands on the system.


EXTRA CREDIT - OPTIONAL:

For extra credit you can get your program to output 3 months across the screen rather than just one month. You can see what such a calendar might look like by running the command "cal 1952" (of course, unlike what "cal" does, your 3-across calendar must still start the week on Monday). You may have to write other functions, or re-organize the ones we've given, to do this extra part.

Only do this part if the regular part of your program is working first. You won't get extra credit unless you first have a working calendar program.