EBK ABSOLUTE C++
EBK ABSOLUTE C++
6th Edition
ISBN: 9780133970944
Author: SAVITCH
Publisher: PEARSON CUSTOM PUB.(CONSIGNMENT)
bartleby

Videos

Textbook Question
100%
Book Icon
Chapter 3, Problem 12PP

Write a program that inputs a date (e.g., 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 isLeapYear (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 (i.e., the century), divide by 4, and save the remainder. Subtract the remainder from 3 and return this value multiplied by 2. For example, the year 2008 becomes ( 20 / 4 ) = 5 remainder 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 remainder 0. Return 2 + 8 = 10.

int getMonthValue (int month, int year) ;

This function should return a value based on the following table and will require invoking the isLeapYear function:

Chapter 3, Problem 12PP, Write a program that inputs a date (e.g., July 4, 2008) and outputs the day of the week that

Finally, to compute the day of the week, compute the sum of the date’s day plus the values returned by getMonthVaIue, getYearVaIue, and getCenturyVaIue. 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 )  +  ( getMonthVaIue )  + ( getYearVaIue )  +  ( getCenturyVa1ue )  = 4 + 6 + 10 + 6 = 26 .26/7 = 3 remainder 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.

Blurred answer
Students have asked these similar questions
Write a program that takes in an integer in the range 20-98 as input. The output is a countdown starting from the integer, and stopping when both output digits are identical. Ex: If the input is 93, the output is: 93 92 91 90 89 88 Ex: If the input is 77, the output is: 77 Ex: If the input is not between 20 and 98 (inclusive), the output is: Input must be 20-98 For coding simplicity, follow each output number by a space, even the last one. Use a while loop. Compare the digits; do not write a large if-else for all possible same-digit numbers (11, 22, 33, ..., 88), as that approach would be cumbersome for large ranges.
Write a program that reads an integer age of kids, finds the maximum of them, and counts its occurances, finds the minimum of them, and counts its occurances. And Find the average ages. Assum that the input ends with number -1.
Write a program that takes in a positive integer as input, and outputs a string of 1's and 0's representing the integer in binary. For an integer x, the algorithm is: As long as x is greater than 0 Output x % 2 (remainder is either 0 or 1) x = x / 2 Note: The above algorithm outputs the 0's and 1's in reverse order. You will need to write a second function to reverse the string. Ex: If the input is: 6 the output is: 110

Additional Engineering Textbook Solutions

Find more solutions based on key concepts
Knowledge Booster
Background pattern image
Computer Science
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
SEE MORE QUESTIONS
Recommended textbooks for you
Text book image
C++ Programming: From Problem Analysis to Program...
Computer Science
ISBN:9781337102087
Author:D. S. Malik
Publisher:Cengage Learning
Java random numbers; Author: Bro code;https://www.youtube.com/watch?v=VMZLPl16P5c;License: Standard YouTube License, CC-BY