Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

CSCI 2170 OLAI (Due Date: midnight Feb 5th, Deadline: midnignt Feb 7') Write a CH program that, given a person's birth date, computes and displays

image text in transcribed
CSCI 2170 OLAI (Due Date: midnight Feb 5th, Deadline: midnignt Feb 7') Write a CH program that, given a person's birth date, computes and displays the day of the week the person was bom Name your source program "weekday.cpp". Check for User inputs Your program should first check for user inputs. If the date entered is not a valid send out an error message and stop the program. If the date entered is valid, proceed to compute for the corresponding week of the day. Determine the day of the week one was born We use the formula called: Zeller's Rule to compute the day of the week for a person's birthday. The following formula is named Zeller's Rule after a Reverend Zeller. Here's the formula: f-d + (13*m-1)/5+D+D/4 + C/4 - 2*C. declare all variables to be of integer type d is the day of the month. Let's use January 29, 2064 as an example. For this date, d - 29. m is the month number. Months have to be counted in a special way for Zeller's Rule: March is 1, Aprilis 2, and so on to January is 11, and February is 12. (This makes the formula simpler, because on leap years February 29 is counted as the last day of the year.) Because of this rule, January and February are always counted as the 11th and 12th months of the previous year. In our example, m=11. (use multi-way if statement to compute the m value based on month) If the original birth month is January or February: subtract from the year value. In our case, birth month is January, therefore, modified year-year-12064 - 1 = 2063. For all other birthday months, do not subtract 1 from the birth year, i.e., modified year year. D is the last two digits of the modified year. In this example, D-modified year % 100 = 2063% 100 63. C stands for century: it's the first two digits of the modified year value. In our case, C = 2063/100=20. . Now let's substitute our example numbers into the formula: f-d+ [(13*m-1)/5] +D+ [D/4]+[C/4) -2C - 29+ [(1311-175] +63 + [63/4] + [20/4] -2*20 -29+ [28] +63 +[15] + [5] -40 = 29+ 28 +63 + 15 + 5 - 40 -100. This f number modulo 7 gives the day of week: (0:Sunday, 1:Monday, 2:Tuesday, 3: Wednesday, 4:Thursday, 5:Friday, 5:Saturday). Use multi-way if statement to display the day of the week. For example, 100%7-2. Therefore Jan 20th 2016 s on Tuesday. If the remainder is negative, add 7 to the remainder. The following are example runs of the program: Example run 1 Welcome! Just tell me your birth date, and I will tell which day of the week you were born Lets get started ... Please tell me your birth date, in the form of month day year 2 37 2001 Your input value is not correct. The computation is not carried out

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

Database Basics Computer EngineeringInformation Warehouse Basics From Science

Authors: Odiljon Jakbarov ,Anvarkhan Majidov

1st Edition

620675183X, 978-6206751830

Students also viewed these Databases questions

Question

differentiate the function ( x + 1 ) / ( x ^ 3 + x - 6 )

Answered: 1 week ago