Zeller’s Congruence is a formula that calculates the day of the week on which any date falls, given the month, day, and year. Zeller’s Congruence is:
(D + floor((M+1)*26/10) + Y + floor(Y/4) + floor(C/4) - 2*C) mod 7
where C is the century (the left-most two digits of the year, for example, 19 if the year is 1948), Y is the year within the century (0-99), D is the day number (1-31), and M is determined from the month by:
January M = 13, and subtract 1 from the year before computing C and Y.
February M = 14, and subtract 1 from the year before computing C and Y.
March M = 3
April M = 4
November M = 11
December M = 12
The value that results from Zeller’s Congruence is an integer in the range 0-6, where 0=Saturday, 1=Sunday, 2=Monday, 3=Tuesday, 4=Wednesday, 5=Thursday, and 6=Friday.
The mod operator
The mod operator in the formula refers to the mathematical modulo operation, as in modular arithmetic. It is closely related to the % operator in C++, but it is not identical. If integers A and B are both positive, then (A mod B) is the same as (A%B). However, if A is negative and B is positive, then (A mod B) is the same as (A%B)+B.
In Zeller’s Congruence, the first operand of mod may be negative. You may write a function to implement this operation, if you wish.
Write a C++ function called weekday that uses Zeller’s Congruence to calculate the day of the week on which a chosen date falls. The parameters of the function are three integers that indicate the chosen month (1-12), day (1-31), and year, for example, 7, 4, and 1776 for July 4, 1776. The return value of the function is an integer in the range 0-6 to indicate the weekday on which the date falls.
Your program must repeatedly read a month, day, and year number, call the function to compute the day of the week, and call a void function to display the resulting day name. You must write the void function.
Make your screen look like the sample below. Terminate the program when the user enters zero for a month number.
Zeller’s Congruence is based upon the Gregorian calendar, which was gradually adopted across the Western world beginning on October 15, 1582. It does not produce correct weekdays before the adoption of the Gregorian calendar.
Here is a sample to illustrate how the screen must appear when your program runs. You must strictly follow this format, wording, spacing, and alignment. The characters in blue are typed by the user. The other characters are output by the program.