Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Write the following C++ code using pretty basic C++ commands and functions. Try to solve the code without using strings, return function, flag variables, and

Write the following C++ code using pretty basic C++ commands and functions. Try to solve the code without using strings, return function, flag variables, and other complex C++ commands. Instead can you please solve the code using if-else statements, "exit" function, boolean variables, and easy to understand C++ commands. Also-if possible-try to post copyable code, screenshot of the code in the source file, and a screenshot of the output. I know how to make the code with return function, but if you can solve this code by using the exit function, please do, as I want to see how the code can be constructed with the exit function of C++. Thank you.

image text in transcribedimage text in transcribed

Write a C++ program that, given a person's birth date, computes and displays the day of the week the person was born. 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, April is 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 1 from the year value. In our case, birth month is January, therefore, modified year = year - 1 = 2064 - 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] - 2*C = 29+ ((13*11-1)/5] +63 + [63/4] + [20/41 - 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, 6:Saturday). Use multi-way if statement to display the day of the week. For example, 100%7=2. Therefore Jan 29th, 2064 is 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. Example run 2 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 6 15 1988 You were born on Wednesday. Example run 3 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 1 15 2001 You were born on Monday. Example run 4 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 5 12 2005 You were born on Thursday. Example run 5 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 19 2000 You were born on Saturday. To check whether your program is producing the correct answers, refer to calendars of the past years. For example, on ranger, the command "cal 1988 will display the entire calendar for year 1988

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

More Books

Students also viewed these Databases questions

Question

How We Listen?

Answered: 1 week ago