YCP Logo Assignment 3: Calendar

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

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

Getting Started

Start by downloading CS101_Assign3.zip, saving it in the directory H:\CS101.

Start a Cygwin Bash Shell and run the following commands:

cd h:
cd CS101
unzip CS101_Assign3.zip
cd CS101_Assign3

Using Notepad++, open the file

H:\CS101\CS101_Assign3\Calendar.cpp

You will add your code to this file.

Run the command

make

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

./Calendar.exe

Your Task

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:

figures/assign3-enterDate.png

The program should display the following calendar:

figures/assign3-displayCalendar.png

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.

Grading

Your grade will be determined as follows:

  • 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

Enter your Marmoset username and password (which you should have received by email.) Note that your password will not be echoed to the screen. Make sure that after you enter your username and password, you see a message indicating that the submission was successful.

Important: Make sure that you check the file(s) you submitted to ensure that they are correct. Log into the server using the following URL:

https://camel.ycp.edu:8443/view/course.jsp?coursePK=61

You should see a list of labs and assignments. In the row for assign3, click the link labeled view. You will see a list of your submissions. Download the most recent one (which should be listed first). Verify that it contains the correct files.

You are responsible for making sure that your submission contains the correct file(s).