Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

7. Write a program that inputs a date (for example, July 4, 2008) and outputs the day of the week that corresponds to that

image text in transcribedimage text in transcribedimage text in transcribed

7. 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 algorithm is from http://en.wikipedia.org/wiki/Calculating_the_day_of_the_week. The implementation will require several functions. bool isLeap Year(int year); This function should return true if year is a leap year and false if it is not. 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 two digits of the year (that is, the century), divide by 4, and save the remainder. Subtract the remainder CHAPTER 5/ Functions for All Subtasks from 3 and return this value multiplied 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 computes a value based on the 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 this value. For example, from 2008 we extract 08. Then (8/4) = 2 with a remainder of 0. Return 2+ 8 = 10. int getMonthValue(int month, int year); This function should return a value based on the table below and will require invoking the isLeap Year function. Return Value 0 (6 if year is a leap year) 3 (2 if year is a leap year) Month January February March 3 April 6 May 1 June July August September 4625 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 returned 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 should be computed as (day of month) + (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 include a void function named getInput that prompts the user 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.

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

The Core Ios Developer S Cookbook Core Recipes For Programmers

Authors: Erica Sadun ,Rich Wardwell

5th Edition

0321948106, 978-0321948106

More Books

Students also viewed these Programming questions