Question -

                        Create User defined exception to check the following conditions and throw the exception if the criterion does not meet. a. User has age between 18 and 55 b. User has income between Rs. 50,000 – Rs. 1,00,000 per month Accept age, Income from the user and check for the conditions mentioned above. If any of the condition is not met, then throw the exception.


Code-


#include<iostream>

#include<string.h>

using namespace std;


class user

{ public:

  char vehicle;

 int salary,age;

 string city;

 

  user()

  {

   age=0;

   vehicle=0;  

   salary=0;

   

  }


  void getdata();

};


void user::getdata()

{

 

 cout<<"Enter Age Of Person:- ";

 cin>>age;

 if(age<18 || age>55)

  {

   throw 1;

  }

 

 cout<<"Enter Salary For Permonth:- ";

 cin>>salary;

 

  if(salary<50000 || salary>100000)

  {

   throw 2;

  }

 

 cout<<"Enter the City name User stay:-  :- ";

 cin>>city;

 if(city=="pune" || city=="mumbai" || city=="bangalore" || city=="chennai")

 {}

 

 else

 {

  throw 3;

 }

  

}


int main()

{

 user u;

 try

 {

  u.getdata();

  

 }


 catch(int i)

 {

  switch(i)

  {

   case 1:

    cout<<"\nInvalid....Please enter age between(18-55)";

    break;


   case 2:

    cout<<"\n Invalid...Please enter salary between(50000-100000)";

    break;

 

   case 3:

    cout<<"\nInvalid city";

    break; 




  }

 }

 return 0;

}