# Assignment 3: Calendar

Due: Tuesday, Feb 23rd by 11:59 PM

Update Feb 16th: Correction to the Julian Day Number formula.

## Getting Started

Start a Cygwin Bash Shell and run the following commands:

```cd h:
cd CS101
unzip CS101_Assign3.zip
cd CS101_Assign3
```

H:\CS101\CS101_Assign3\Calendar.cpp

Run the command

```make
```

when you are ready to compile the program. To run the program, run the command

```./Calendar.exe
```

Your task is to write a program which prompts the user to enter a day, month, and year, and then prints a calendar of that month, highlighting the day the user entered.

For example, let's say that the user entered the date 2 8 2008, meaning February 8th, 2008:

The program should display the following calendar:

## Requirements

The calendar displayed should have the name of the month and the year at the top, then a row of column headers with the days of the week (abbreviations are fine), and then a table showing where each day in the month falls.

The day entered by the user should be highlighted by drawing a colored box around it.

Your program should support any date in the Gregorian (modern) calendar.

## Approach / Hints

A Julian Day Number is an integer representation of dates since January 1, 4713 BC.

Assuming that M is a month (1 for January), D is a day of the month (1 for the first day of the month), and Y is a year, then the Julian Day Number (JDN) can be computed as follows:

JDN = (1461 × (Y + 4800 + (M − 14)/12))/4 +(367 × (M − 2 − 12 × ((M − 14)/12)))/12 − (3 × ((Y + 4900 + (M - 14)/12)/100))/4 + D − 32075

[source: Wikipedia]

Note that all divisions in the formula above are integer divisions, meaning that any fraction in the quotient is discarded.

Any Julian Day Number can be taken modulo 7 in order to determine which day of the week the day falls on:

 JDN % 7 == 0 Monday JDN % 7 == 1 Tuesday JDN % 7 == 2 Wednesday JDN % 7 == 3 Thursday JDN % 7 == 4 Friday JDN % 7 == 5 Saturday JDN % 7 == 6 Sunday

The program can determine how to display a calendar for the month containing the user's date using the following approach:

1. Convert the date to a Julian Day Number.
2. Using the JDN for the user's date, calculate the JDN for the first day of the month and the last day of the month. Note that you will need to determine the number of days in the month; see below.
3. Display each day of the month in the appropriate row and column of the calendar.

To determine the number of days in the month:

• January, March, May, July, August, October, and December each have 31 days.
• April, June, September, and November each have 30 days.
• February has 28 days, except in leap years, when it has 29 days.

A leap year is any year which either

• Is evenly divisble by 4 and not evenly divisible by 100, or
• Is evenly divisible by 400

Important: You will use printf and scanf to prompt the user to enter the day, month, and year. Make sure that the calls to these functions take place before the calls to the display functions (e.g., cons_clear_screen).

Use the display functions (e.g., cons_move_cursor, cons_change_color, etc.) that you used in Lab 8 in order to precisely control the appearance of the calendar.

• Prompts, data entry: 15 points
• Print month and year at top of calendar: 10 points
• Print days of week as column headers: 10 points
• Print correct number of days in month: 25 points
• Correctly list each day in appropriate column (day of week): 25 points
• Formatting (rows and columns lined up precisely): 10 points
• Day entered by user is highlighted with colored box: 5 points

An insane extra credit option is available for up to 10 additional points.

Points may be deducted for poor coding style. You should make sure you use meaningful variable names, write comments to document what your code is doing, and properly indent all code in nested blocks (if/else statements and loops.)

## Submitting

To submit your work, make sure your Calendar.cpp file is saved, and type the command

```make submit
```