#include<iostream>
#include<string.h>
using namespace std;
class User {
protected:
int age, vehicle;
long double income;
string city;
public:
User(int a, int v, long double i, string c) {
age = a;
vehicle = v;
income = i;
city = c;
}
};
class Exceptionhandling: public User {
public:
Exceptionhandling(int a, int v, long double i, string c): User(a, v, i, c) {}
void checkcondition() {
try {
if(age<18||age>55) {
throw "Age should be between 18 and 55";
}
}
catch(const char* msg) {
cerr<<msg<<endl;
}
try {
if(income<50000||income>100000) {
throw "Income should be between 50,000 and 1,00,000";
}
}
catch(const char* msg) {
cerr<<msg<<endl;
}
try {
if(city=="Pune"||city=="pune"||city=="Mumbai"||city=="mumbai"||city=="chennai"
||city=="Chennai"||city=="delhi"||city=="Delhi") {
}else{
throw "City should be pune/mumbai/delhi/chennai";
}
}
catch(const char* msg) {
cerr<<msg<<endl;
}
try {
if(vehicle!=4) {
throw "User must have 4 wheeler";
}
}
catch(const char* msg) {
cerr<<msg<<endl;
}
}
};
int main() {
int age, vehicle;
long double income;
string city;
// Get the user input
cout<<"Enter the age :"<<endl;
cin>>age;
cout<<"Enter the vehicle :"<<endl;
cin>>vehicle;
cout<<"Enter the income :"<<endl;
cin>>income;
cout<<"Enter the city :"<<endl;
cin>>city;
Exceptionhandling eh(age, vehicle, income, city);
eh.checkcondition();
return 0;
}
To embed this program on your website, copy the following code and paste it into your website's HTML: