Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Using C++: Code Program 2 only Wtite a program that prompts the user to enter a

ID: 3808064 • Letter: U

Question

Using C++: Code Program 2 only


Wtite a program that prompts the user to enter a person's birth date in numeric form (e.g. 8-27-1990) and outputs the date of birth in the format of month day, year (e.g. August 27. 1990), Your program must work for three types of exceptions invalid day, invalid month and invalid year (year must be between 1915 and 2017). Make these as class driven exceptions Program Use one try-catch block with separate catches for the exception classes to handle errors for invalid day and month and a catch all to handle invalid year. Print the correct exception method error and have the user re-enter the error field value assume the user will enter a correct value Then print out converted date. Program 2: Use nested try-catch blocks to print the appropriate emor message fat the error in the internal try-catch block(s) Re-throw the exception and ask the user to re-enter the error field value in the outer try-catch block. Then print out the converted date.

Explanation / Answer

Code:-(Program 2)

#include <iostream>
#include <string>
#include <exception>
using namespace std;

int day;
int month;
int year;

class invalidDay : public exception{

    public:

        const char * what() const throw()

        {
          
            return "The value of day that you entered is invalid, try again.";

        }

};

class invalidMonth : public exception{

    public:

        const char * what() const throw()

        {
          
            return "The value of month that you entered is invalid, try again.";

        }

};

class invalidYear : public exception{

    public:

        const char * what() const throw()

        {
          
            return "The value of year that you entered is invalid, try again.";

        }

};

int main()
{
    int check=1;
    char month_words[10];
    while(check){
        cout << " Enter your birthday here in this format: mm/dd/yyyy--->: ";

        cout <<"Enter day here.";
        cin >> day;

        cout <<"Enter the month here.";
        cin >> month;

        cout <<"Enter the year here.";
        cin >> year;
    try{
      
  
        try{
            try{
            if (day > 31){
                invalidDay ed;
                throw ed;
            }
            }
        catch(invalidDay& x)
        {
        cout <<x.what()<<endl;
        continue;
        }
  
        if(month==1)
            cout<<"january";
    else
        if(month==2)
        cout << "February ";
    else
        if(month==3)
        cout << "March ";
    else
        if(month==4)
        cout << "April ";
    else
        if(month==5)
        cout << "May ";
    else
        if(month==6)
        cout << "June ";
    else
        if(month==7)
        cout << "July ";
    else
        if(month==8)
        cout << "August ";
    else
        if(month==9)
        cout << "September ";
    else
        if(month==10)
        cout << "October ";
    else
        if(month==11)
        cout << "November ";
    else
        if(month==12)
        cout << "December ";
    else
        if (month > 12){
             invalidMonth em;
                throw em;
        }
        }
    catch (invalidMonth& m)
    {
        cout <<m.what()<<endl;
        continue;
    }
    if(year<1915 || year>2017){
         invalidYear ey;
                throw ey;
    }
    }
    catch(invalidYear& y){
        cout<<y.what()<<endl;
        continue;
    }
    check=0;
}
cout << day << "," << year << "." << endl;
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote