
Program 3 - Calendar
Comp 150
100 Points
Write a C++ program called calendar.cpp that will produce a calendar for a given month and year. The user will be
able to produce calendars until 0 is entered for the month. All user input should be validated.
Your program should produce output exactly like the example below.
To determine which day of the week a calendar should start on,
consider the fact that Jan 1, 1900 was on a Monday. That
means Feb 1, 1900 would be on Thurs since there are 31 days
in Jan, and Jan 31
st
was on a Wed. Mar 1, 1900 would begin on
Thurs since there are 28 days in Feb, and Feb 28
th
was on a
Wed.
The following formula can be used for calculating which day of
the week the 1
st
would fall on for a particular month and year:
First Day = Remainder of (1 + Total Number of Days from Jan 1,
1900 to 1
st
of current Month) / 7
where First Day of 0 is Sun, 1 is Mon, 2 is Tues, …, 6 is Sat.
Example:
First Day for Mar 1900: (Remainder of [1+ 31 + 28]) / 7 = 4 which
corresponds to Thurs.
In calculating the total number of days since Jan 1, 1900, it is necessary to add a day to Feb for Leap Years. If the
number of the year is divisible by 4 then the year is a Leap Year, except in the case where the number of the year
ends in 00; then the year is not a Leap Year. However, if the number of the year ends in 00 and the year is
divisible by 400 the year is a Leap Year.
Notes about output:
• Each day is separated by 2 spaces (Sun--Mon)
• The right edge of the month and year output ("January 1900") should be aligned with the right edge of "Thu"
unless the year is greater than 4 digits.
You can use the finished version of m y program for testing if you’d like. It’s located at:
\\cs1\Classes\comp170\calendar_fm.exe
Submit your program and a structure chart (as a .txt file) to Easel (http://cs.harding.edu/easel/) before class on
the due date.
The main purpose of this assignment is for you to get experience using functions. Use them whenever appropriate.
Each function should have a single purpose and be named with a verb and noun. Make sure no function is greater
than a printed page. You will be penalized greatly for not using functions.
Enter month (1-12) or 0 to quit: 4
Enter year (1900 or above): 2000
April 2000
Sun Mon Tue Wed Thu Fri Sat
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
Enter month (1-12) or 0 to quit: 1
Enter year (1900 or above): 1900
January 1900
Sun Mon Tue Wed Thu Fri Sat
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
Enter month (1-12) or 0 to quit: 0