1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
Marina86 [1]
3 years ago
10

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 outp

uts the date of birth in the form: August 27, 1980. Your program must contain at least two exception 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.)
Computers and Technology
1 answer:
Oksi-84 [34.3K]3 years ago
7 0

Answer:

The program to this question can be given as:

Program:

//define header file.

#include<iostream>

#include<string>

using namespace std;

class invalidDay              //define class.

{

string msg;                   //define variable as private.

public:

invalidDay()               //constructor.

{

msg="Day input is wrong";            

}

void showException()           //define function.

{

cout<<msg<<endl;

}

};

class invalidMonth              //define class.

{

string msg;             //define variable as private.

public:

invalidMonth()              //constructor.

{

msg="Month input is wrong";

}

void showException()           //define function.

{

cout<<msg<<endl;

}

};

class leapYear           //define class            

{

string msg;         //define variable as private.

public:

leapYear()                  //define constructor

{

msg="year input is wrong";

}

void showException()         //define function.

{

cout<<msg<<endl;

}

};

void read_date(int &day,int &month,int &year);         //declaration of function.

void read_date(int &d,int &m,int &y)                 //defination of function.

{    

  //function body.

cout<<"Enter day"<<endl;

cin>>d;

if(d<=0 ||d>31)

throw invalidDay();               //Exception.

cout<<"Enter month"<<endl;

cin>>m;

if(m<=0 ||m>=13)

throw invalidMonth();

cout<<"Enter year"<<endl;

cin>>y;

if(y%400==0||(y!=100&&y%4==0))

if(d>=30)

throw leapYear();

}

int main()                     //main function

{

   //define variable

int day,month,year;                  

string months[12]={"January","February","March",            

"April","May","June","July","August","September",

"October","November","December"};

//Exception handling.

try                               //try block

{

read_date(day,month,year);

cout<<"Date of Birth "<<months[month-1]<<" "<<day<<","<<year;

}  

//catch bolck.

catch(invalidDay id)

{

id.showException();

}

catch(invalidMonth im)

{

im.showException();

}

catch(leapYear ly)

{

ly.showException();

}

return 0;

}

Output:

Enter day

12

Enter month

12

Enter year

2019

Date of Birth December 12,2019.

Explanation:

In the above program firstly we define 3 class that is invalidDay, invalidMonth, and leapYear. In these classes, we define a method, variable, and constructor, and in the constructor, we holding the value of the msg(variable). Then we define a function that is read_data. This function collects all values from the user and throws into leap year function. In the last, we define the main function this function used exception handling. In the exception handling, we use multiple catch block with try block. After handling all the exception we called all function of the class.

You might be interested in
The range of an area where users can access the Internet via high frequency radio signals transmitting an Internet signal from a
Alexandra [31]
A) hotspot
Bluetooth is for short distance and pan is Personal area networks (PANs) connect an individual's personal devices
8 0
3 years ago
Read 2 more answers
Data is best described as
viktelen [127]

Answer:

The answer is B

Explanation:

TOOK THE TEST

5 0
3 years ago
Read 2 more answers
Fuel-pressure regulators on fuel-return-type fuel-injection systems are installed
Natalija [7]
1) The correct answer is <span>B. at the end of the fuel rail.
2) The one who is correct is the Technician A.</span>
5 0
3 years ago
Read 2 more answers
How do you set up nordvpn with spectrum?
Setler [38]

Answer:

simple

Explanation:

use nordvpn with discount code: Chonchode

7 0
3 years ago
Windows Hello supports multiple biometric authentication methods, including facial recognition. What is the failsafe method to a
Orlov [11]

Answer:

The failsafe method when facial recognition method is unavailable is the Personal Identification Number (PIN) method.

Explanation:

The Personal Identification Number (PIN) option is available for setup for cases when other biometric authentication methods fail due to several reasons.

6 0
3 years ago
Other questions:
  • Build three classes that conform to the following interfaces. Use arrays in creating your classes (e.g., do not use the built-in
    8·1 answer
  • Where do scanned documents go in windows 10?
    11·1 answer
  • A cell has an unlimited number of conditions for Conditional Formatting.<br> A.true<br> B.false
    7·1 answer
  • It is an attribute that must be used in the form tag in specifying an input file type
    9·1 answer
  • Which routing protocol does an exterior router use to collect data to build its routing tables?
    8·1 answer
  • Retype and run, note incorrect behavior. Then fix errors in the code, which should print num_stars asterisks.
    9·1 answer
  • What is the most effective way to demonstrate being prepared for an interview?
    13·1 answer
  • R6. Suppose N people want to communicate with each of N - 1 other peo- ple using symmetric key encryption. All communication bet
    13·1 answer
  • On tool hackers use to get sensitive information from victims is/are:
    15·2 answers
  • I am trying to sum up a set of data based on 2 criteria (needs to have "green" in column E, and "January 2020" in collum A). Col
    11·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!