Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

This must be done in C++ format and before continuing to post please read the IMPORTANT NOTES first, which i will post below after the

This must be done in C++ format and before continuing to post please read the IMPORTANT NOTES first, which i will post below after the question. This home work is actually done but it just needs a few requirements to be totally complete. I will post my solution after the important notes.

Question: Write a program that prompts the user to enter a person's date of birth in numeric form such as 8/27/1980. The program then outputs the date of birth in the form: August 27, 1980. Your program must contain at least two exeception classes: invalidDay and invalidMonth. If the user enters an invalid value for day, then the program should throw and catch an invalidDay object. Similar conventions for the invalid values of month and year. (Note that your program must handle a leap year.)

IMPORTANT NOTES: The program is actually done, with all the the exception caught. but the problem is that it needs a continuous menu required to allow for testing the code. it needs an input from the user, asking if they would like to continue with an input. This needs to be asked again after the user enters the previous date of birth, asking if they would like to input another date of birth, if yes, loop with the previous question, if no, exit program. it also needs to ask the user again when they caught an exception, to put the right input. until the input is correct, they will keep asking the user to try again. currently, the program will end after catching each exception, and that is the problem. I don't think the header files needed to be changed at all since it catches all exception properly. so the problem is the main file which needs the exit program and the loop for try again. Before posting your solution, please make sure the program runs and compiles first. I would appreciate your help for this

my code:

//invalidDay.h #include #include using namespace std; class invalidDay { string msg;

public: invalidDay() { msg = "Day input is wrong"; } void showException() { cout << msg << endl; } };

================================================

//invalidMonth.h #include #include using namespace std; class invalidMonth { string msg; public: invalidMonth() { msg = "Month input is wrong"; } void showException() { cout << msg << endl; } };

====================================

//leapYear.h #include #include using namespace std; class leapYear { string msg; public: leapYear() { msg = "Year input is wrong"; } void showException() { cout << msg << endl; } };

=====================================

//main.cpp #include #include #include "invalidDay.h" #include "invalidMonth.h" #include "leapYear.h" using namespace std;

void read_date(int &day, int &month, int &year); int main() { int day, month, year; string months[12] = {"january", "february", "march", "april", "may", "june", "july", "august", "september", "october", "november", "december"}; try { read_date (day, month, year); cout << "Date of Birth " << months[month-1] << " " << day << ", " << year<> y; cout << "Enter month: "; cin >> m; if (m<=0 || m>13) throw invalidMonth(); cout << "Enter day: "; cin >> d; if (d<=0 || d>31) throw invalidDay(); else if (m == 2) { if ((y%400==0 || (y!=100&&y%4==0)) && d>29) throw leapYear(); else if(!(y%400==0 || (y!=100&&y%4==0)) && d > 28) throw leapYear(); } }

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 Concepts

Authors: David M. Kroenke, David J. Auer

7th edition

133544621, 133544626, 0-13-354462-1, 978-0133544626

More Books

Students also viewed these Databases questions

Question

What sexual dysfunctions affect sexual desire and arousal?

Answered: 1 week ago