Due dates:

Getting Started

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

Start a Cygwin Bash Shell and run the following commands:

cd h:
cd CS101
unzip CS101_Assign02_Fa23.zip
cd CS101_Assign02_Fa23

Using Notepad++, open the file

H:\CS101\CS101_Assign02_Fa23\Calendar.cpp

You will add your code to this file.

Your Task

The program should prompt the user to enter the month and year as integers. It should then print out

  1. How many days the specified month has, and
  2. What day of the week the first day of the specified month falls on

Then it will display a formatted calendar for that month.

When you are ready to compile the program, in the Cygwin window type the command

make

To run the program, type the command

./Calendar.exe

Example run (user input in bold):

Enter month and year: 9 2018
There are 30 days in the month.
The month starts on a Saturday.

September 2018
Sunday     Monday     Tuesday    Wednesday  Thursday   Friday     Saturday   
                                                                  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         

Note that your program must ensure that the user enters a month that is valid (in the range 1..12) and a year that is after 4713 BC. If an invalid month or year is entered, the program should prompt the user to re-enter the month and year:

Enter month and year: 13 2012
Invalid date, please re-enter month and year: 10 -5000
Invalid date, please re-enter month and year: 2 2018
There are 28 days in the month.
The month starts on a Thursday.

February 2018
Sunday     Monday     Tuesday    Wednesday  Thursday   Friday     Saturday   
                                            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         

Milestone 1

In Milestone 1, your tasks are to

Here is an example run of the program for Milestone 1 (user input in bold):

Enter month and year: 9 2018
There are 30 days in the month.
The month starts on a Saturday.

Another example run (user input in bold):

Enter month and year: 2 1996
There are 29 days in the month.
The month starts on a Thursday.

Deliverables for Milestone 1

The design artifact for Milestone 1 is due at the beginning class on Tuesday, Sept 12th. Make sure that you fill out the “Strategy” and “Control flow sketch” sections of the design template.

The code for Milestone 1 should be submitted to Marmoset (using the command make submit_ms1) by the end of the day on Friday, Sept 15th.

Submitting Milestone 1

To submit your code, make sure your Calendar.cpp file is saved, and in the Cygwin window type

make submit_ms1

Approach/Hints for Milestone 1

Number of days in month

To determine the number of days in the month:

Leap Years

A year is a leap year if either:

For example, 1996 and 2000 were leap years, but 1900 and 2003 were not leap years.

Julian Day Computation

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:

Test Day of week
(JDN+1) % 7 == 0 Sunday
(JDN+1) % 7 == 1 Monday
(JDN+1) % 7 == 2 Tuesday
(JDN+1) % 7 == 3 Wednesday
(JDN+1) % 7 == 4 Thursday
(JDN+1) % 7 == 5 Friday
(JDN+1) % 7 == 6 Saturday

Milestone 2

In Milestone 2, using the information from Milestone 1 your tasks are

Here is an example run of the program for Milestone 2 (user input in bold):

Enter month and year: 8 2023
There are 31 days in the month.
The month starts on a Tuesday.

August 2023
Sunday     Monday     Tuesday    Wednesday  Thursday   Friday     Saturday   
                      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                            

Another example run (user input in bold):

Enter month and year: 13 2012
Invalid date, please re-enter month and year: 10 -5000
Invalid date, please re-enter month and year: 2 2024
There are 29 days in the month.
The month starts on a Thursday.

February 2018
Sunday     Monday     Tuesday    Wednesday  Thursday   Friday     Saturday   
                                            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                    

Deliverables for Milestone 2

The design artifact for Milestone 2 is due at the beginning class on Tuesday, Sept 19th. Make sure that you fill out the “Strategy” and “Control flow sketch” sections of the design template.

The code for Milestone 2 should be submitted to Marmoset (using the command make submit_ms2) by the end of the day on Monday, Sept 25th.

Submitting Milestone 1

To submit your code, make sure your Calendar.cpp file is saved, and in the Cygwin window type

make submit_ms2

Approach/Hints for Milestone 2

Separating weeks

Consider using multiple counters for which day is currently being printed and for the number of days previously printed to determine when a new week starts in order to begin the next line of output.

Grading

Your grade will be determined as follows:

Milestone 1 - 40 points

Milestone 2 - 60 points

We expect you to use good coding style. Points may be deducted for poor variable names, inconsistent or missing indentation, and/or lack of comments.

Extra Credit - 20 points

Add extra formatting such that

Enter month and year: 8 2023
There are 31 days in the month.
The month starts on a Tuesday.

                                 August 2023
------------------------------------------------------------------------------
|  Sunday  |  Monday  |  Tuesday | Wednesday| Thursday |  Friday  | Saturday |
------------------------------------------------------------------------------
|          |          |     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    |          |          |
-----------------------------------------------------------------------------

Submitting

To submit your code, make sure your Calendar.cpp file is saved, and in the Cygwin window type one of the following commands (depending on whether you are submitting Milestone 1 or Milestone 2).

For Milestone 1:

make submit_ms1

File Milestone 2:

make submit_ms2

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.

Make sure that you check the file(s) you submitted to ensure that they are correct. See the instructions for Verifying your submission.

Important: It is your responsibility to verify that you submitted the correct files. You may receive a grade of 0 for incorrectly submitted work.