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
Name the sections of an instruction.
topjm [15]
Instruction in memory has two parts: opcode and operands. The operands are subjects of the operation, such as data values, registers, or memory addresses. Due to variety of opcodes and operands, instructions may occupy different sizes of bytes in memory
3 0
3 years ago
How long does it take to design and program a character?
Kipish [7]
It takes about 5 days I believe 
6 0
3 years ago
Modify the code below to do the following:
Kitty [74]

Answer:

The code is appropriately given below with comments for better understanding

Explanation:

#include <linux/init.h>

#include <linux/module.h>

#include <linux/kernel.h>

#include <linux/hash.h>

#include <linux/gcd.h>

#include <asm/param.h>

#include <linux/jiffies.h>

/* This function is called when the module is loaded. */

static int simple_init(void)

{

  printk(KERN_INFO "Loading Module\n");

  printk(KERN_INFO "These are the HZ: %d\n", HZ);

  printk(KERN_INFO "These are the jiffies: %lu\n", jiffies);

  printk(KERN_INFO "Golden Ratio is: %lu\n", GOLDEN_RATIO_PRIME);  

  return 0;

}

/* This function is called when the module is removed. */

static void simple_exit(void) {

  printk(KERN_INFO "Removing Module");

  unsigned long a = gcd(3300, 24);

  printk(KERN_INFO "Greatest Common Denominator between 3,300 and 24 is: %lu\n", a);

  printk(KERN_INFO "These are the jiffies: %lu\n", jiffies);

}

/* Macros for registering module entry and exit points. */

module_init( simple_init );

module_exit( simple_exit );

MODULE_LICENSE("GPL");

MODULE_DESCRIPTION("Simple Module");

MODULE_AUTHOR("SGG");

7 0
3 years ago
What type of block start a sequence?
ss7ja [257]

Answer:

An algorithm?

8 0
2 years ago
Secure shell (SSH) operates over which port by default
Karolina [17]

Explanation:

By default, SSH opens port 22.

However, this can be arbitrarily changed.  So if port 22 does not work, it is necessary to check the exact/new port number.

5 0
2 years ago
Other questions:
  • Add the following functions to the code:
    9·1 answer
  • WILL GIVE BRAINLIEST! I'm doing a project at school. Does anyone have any good explanations for Digital Art? I need it to be at
    13·2 answers
  • What are five most important areas of the animal industry that involve science and technology?
    14·1 answer
  • This program outputs a downwards facing arrow composed of a rectangle and a right triangle. The arrow dimensions are defined by
    8·1 answer
  • What are lexical errors?<br> and fi(a==b)<br> will it be a lexical error or a syntactical error?
    8·1 answer
  • We use a cubic equation in which the variables and coefficients all take on values in the set of integers from 0 through p - 1 a
    8·1 answer
  • Which hardware device connects your network to the internet? select one:
    15·1 answer
  • In black and white,<br><br> we must be more conscious of image
    11·1 answer
  • Write a function namedmake_complex that stores its twoarguments (both of type double) in acomplex structure, then returns thestr
    12·1 answer
  • When you check your hard drive to see how much space is available, you are checking your
    15·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!