Write a program that, given a month and year, prints a calendar, such as
June 2016
Su Mo Tu We Th Fr Sa
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
You should create at least two functions:
1) int JulianDayDate(int month, int day, int year)
This function should return the day of the week, given a date. Here is one algorithm to do this given a Julian date:
JMD = (day + ((153 * (month + 12 * ((14 - month) / 12) - 3) + 2) / 5) +
(365 * (year + 4800 - ((14 - month) / 12))) +
((year + 4800 - ((14 - month) / 12)) / 4) -
((year + 4800 - ((14 - month) / 12)) / 100) +
((year + 4800 - ((14 - month) / 12)) / 400) - 32045) % 7;
This formula returns an index of the day of the week. // 0 = Monday, 1 = Tuesday, ..., 6 = Sunday
You can use the above to find out the weekday of the first day of the month for your calendar.
2) Next, you should create your own function to return the number of days in the month that you need to print. Your function should correctly handle leap years. Make sure your test output shows the various possible outputs, month lengths of 28,29,30,31.
int getDaysInMonth(int month, int year)
Hints:
- Use helper methods to print the header and to print each row will make your code easier to understand and debug.
- Each row except the header will have 20 characters.
- You may want to also create a method that calculates the number of leading spaces before the first date of the month to make your code more modular.
Submission Instructions:
Submit C++ source code files that solve the defined problem.
Submit a screenshot of your test output including all test cases. You should validate your date inputs.