John Horton Conway, a mathematician who worked at Princeton University, died of COVID-19 in April 2020 at the age of 82. In addition to inventing the Game of Life, his "Doomsday" rule is credited with computing the day of the week for any given date.
Here is an example of a dialog for the program I am asking you to create (user input is in boldface):
Provide a month: January
Provide a day: 1
Provide a year: 2021
January 1, 2021 was a Friday!
In addition to correctly calculating a day of the week answer, your program needs to also handle errors as shown below:
Provide a month: January january
Provide a day: 2
Provide a year: 2020
Invalid month!
Provide a month: February
Provide a day: -10
Provide a year: 2000
Invalid day!
Provide a month: March
Provide a day: 3
Provide a year: -101
Invalid year!
Provide a month: -101
Provide a day: -101
Provide a year: -101
Invalid month!
These are the data validation rules I want your program to enforce:
Your program must gather the month, day and year, in that specific order. However, if you detect an error in an item, you do not have to request or get the remaining items if you don't want to; just be sure you write to cout the required error message and nothing more after that. If instead you choose to gather all input first before checking for any errors, and you detect more than one error, then write only the error message for the first erroneous input item as the last example shows.
You can test your understanding of this program's requirements by experimenting with the calculator we found at this website. http://www.howardstahl.com/ucla/winter21/project2
The algorithm your program should compute is documented below by working with a Month Code, Leap Year Offset (if applicable), Century Code, Year Code and Day Code. After describing the procedure, an example is shown below.
determine a month code with the following table:
Month | Month Code | Month | Month Code | Month | Month Code | Month | Month Code |
January | 1 | February | 4 | March | 4 | April | 0 |
May | 2 | June | 5 | July | 0 | August | 3 |
September | 6 | October | 1 | November | 4 | December | 6 |
determine if a Leap Year Offset of -1 needs to be added to the Month Code using the following guidelines:
if the year entered by the user is a leap year and if the month entered by the user is January or February, add -1 to the month code to adjust for the leap year. (A leap year occurs in years that are evenly divisible by 4. However, years that are evenly divisible by 100 are not leap years with the exception that years evenly divisible by 400 are leap years. In other words, 1996 is a leap year, 2000 is a leap year, 2004 is a leap year. 1900 is not a leap year, 1800 is not a leap, 2001 is not a leap year).
determine a century code with the following table (the division specified below should be int division):
Century Value = the year value entered by the user divided by 100 modulo 4
Century Value | Century Code | Century Value | Century Code | Century Value | Century Code | Century Value | Century Code |
0 | -2 | 1 | 3 | 2 | 1 | 3 | -1 |
determine a Year Code using the following formula:
Year Code = the year value entered by the user modulo 100 divided by 4 plus the year value entered by the user modulo 100. (Again, the division specified here should be int division)
determine a Day Code using the following formula:
Day Code = ( Century Code + day value entered by the user + Year Code + Month Code ) modulo 7
based on the Day Code, determine a day of the week using the following table:
0 | Sunday |
1, -6 | Monday |
2, -5 | Tuesday |
3, -4 | Wednesday |
4, -3 | Thursday |
5, -2 | Friday |
6, -1 | Saturday |
Based on all this information, let's take an example. For example, consider January 1, 2021 which was a Friday.
Here is an example. For example, consider January 1, 2000 which was a Saturday.
Your program must collect the information for one day in the manner indicated by the examples, and then write to cout exactly one line in a format required below. Our grading tool will judge the correctness of your program by examining your output. Your program's output must be in one of the following four forms; the text must be identical to what is shown (except that the italicized portions described below ):
Your program's output must not start with any spaces. If you are not a good speller or typist, or if English is not your first language, be especially careful about duplicating the messages exactly . Here are some foolish mistakes that may cause you to get no points for correctness on this project, no matter how much time you put into it:
January 1, 2020 was a Friday missing exclamation
January 1, 2020 was a Frday! misspelling
January 1, 2020 was a friday! wrong capitalization
January 1, 2020 was a Friday ! extra spaces
January 1 2020 was a Friday! no comma
Your program must gather the month, day and year, in that specific order. However, if you detect an error in an item, you do not have to request or get the remaining items if you don't want to; just be sure you write to cout the required error message and nothing more after that. If instead you choose to gather all input first before checking for any errors, and you detect more than one error, then write only the error message for the first erroneous input item.
You will not write any loops in this program. This means that each time you run the program, it handles only one date calculation. It also means that in the case of bad input, you must not keep prompting the user until you get something acceptable; our grading tool will not recognize that you're doing that.
The correctness of your program must not depend on undefined program behavior. Your program could not, for example, assume anything about n 's value at the point indicated:
int main()
{
int n;
int m = 42 * n; // n's value is undefined
...