Question
Write a program that calculates the elapsed time between two dates in terms of years , months , and days . Your program should prompt
Write a program that calculates the elapsed time between two dates in terms of years, months, and days. Your program should prompt the user to enter the current date in terms of month, day, year. After the date entered has been validated (as specified below), the program should prompt the user to see if they want to calculate how old they are. If they accept, the program should prompt the user to enter the date of their birth also in terms of month, day, and year. This date also needs to be validated (as specified below). Assuming both days have been correctly validated, the program should then calculate the persons age in years, months, and days and display the information accordingly. If the current date happens to be the person's birthday, your program should output a special congratulations message. The logic that controls the execution of your program should be in the main() body, however, the program should be designed to accomplish its' objective around at least the following logical functions:
bool enterDate(int month, int day, int year) This function prompts the user to enter a date (in some specified format as: m d y or m/d/y) and stores the data entered into the three arguments passed. Note you must decide if the arguments to this function should be passed by value or passed by reference. This function should invoke the validDate() function and return true or false false depending on whether the date entered is a valid date.
bool enterBirthDate( int cmonth, int cdate, int cyear, int bmonth, int bday, int byear) This function should invoke the enterDate() function to get the date of the person's birthday. Assuming a valid date was entered, this function should make sure that it is a valid birth date (i.e. date enter occurs before the current date) by invoking the dateBefore() function. This function should return true or false false depending on whether the date entered is a valid birth date.Think carefully which arguments to this function should be passed by reference and which arguments should be passed by value.
bool validDate(int month, int day, int year) This function checks that the month, day and year passed to the function represent a valid date. The function should return the boolean value true or false accordingly. For a date to be valid:
the month must be between 1 and 12.
if the month is in {4,6,9,11}, the the day must be in {1 .. 30}
if the month is in {1,3,5,7,8,10,12}, the the day must be in {1 .. 31}
if the month is in {2}, the the day must be in {1 .. 28}. Note, we will ignore leap years for the moment.
bool dateBefore(int month1, int day1, int year1, int month2, int day2, int year2) This function checks that the date corresponding to the parameters month1, day1, year1 is before the date corresponding to the parameters month2, day2, year2 (i.e. cannot have a birthday if you have not been born yet). The function should return the boolean value true or false accordingly.
void calculateAge() This function calculates your age in years, months, days and years. Note: You decide what arguments this function needs to take and how they should be passed. This requires some thought because, as the name of this function indicates, the purpose of this function is to calculate the age in years, months, and days. The display of this information, therefore, should take place after this function returns to wherever it was invoked from. In other words, there should be no cout statements in this function.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started