Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Write a program that inputs a date (for example, July 4, 2008) and outputs the d

ID: 3832260 • Letter: W

Question

Write a program that inputs a date (for example, July 4, 2008) and outputs the day of the week that corresponds to that date. The following alogrithm is from http://en.wikipedia.org/wiki/Calculating_the_day_fo_the_week. The implementation will require several functions.

bool isLeapYear(int year);

This function should return true if year is a leap year and false if it is not.         

Once this is written, create a top-level function named dayOfWeek with the header:

int dayOfWeek(int month, int day, int year);

the function should encapsulate the necessary logic to return the day of the week of th specified date as an       

int(Sunday = 0, Monday = 1, etc). You should add validation code to the function that tests if any of the inputs are invalid. If so, the function should return -1 as the day of the week. In your main function write a test driver that checks if dayOfWeek is returning the correct values. Your set of test cases should include at least two cases with invalid inputs.                        

Here is pseudocode to determine a leap year:

leap_year = (year divisible by 400) or (year divisible by 4 and year not divisible by 100)

int getCenturyValue(int year);

This function should take the first digits of the year (tht is, the century), divide by 4, and save the remainder. Subtract the remainder from 3 and return this value multipled by 2. For example, the year 2008 becomes: (20/4) = 5 with a remainder of 0.3 - 0 =3. Return 3*2 = 6.

int getYearValue(int year);

This function comutes a value based on he years since the beginning of the century. First, extract the last two digits of the year. For example, 08 is extracted for 2008. Next, factor in leap years. Divide the value from the previous step by 4 and discard the remainder. Add the two results together and return the value. For example, from 2008 we extract 08. then (8/4) = 2 with a remainder of 0. return 2+8 = 10.

int getMonthVa0lue(int month, int year);

This functin should return a value based on the table below and will require invoking the isLeapYear

Month                           Return Value

January                          0 (6 if year is a leap year)

February                         3 (2 if year is a leap year)

March                             3

April                                6

May                                 1

June                                4

July                                 6

August                            2

September                       5

October                           0

November                      3

December                      5

Finally, to compute the day of the week, compute the sum of the date's day plus the values returnd by getMonthValue, getYearValue, and getCenturyValue. Divide the sum by 7 and compute the remainder. A remainder of 0 corresponds to Sunday, 1 corresponds to Monday, etc., up to 6, which corresponds to Saturday. For example, the date July 4, 2008 shouldbe computed as (day of monty) + (getMonthValue) + (getYearValue) + (getCenturyValue) = 4 + 6 +10 + 6 = 26. 26/7 = 3 with a remainder of 5. the fifth day of the week corresponds to Friday.

Your program should allow the user to enter any date and output the corresponding day of the week in English.

This program should inclue a void function named getInput that prompts the use for the date and returns the month, day, and year using pass-by=reference parameters. You may choose to have the user enter the date's month as either a number (1-12) or a month name.

Explanation / Answer

}

#include <iostream>
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote