Create a user-defined exception to check the following conditions, and if the criterion is not met, throw the exception. A. The user is between 18 and 55 years old. User stays have income between Rs. 50,000 – Rs. 1,00,000 per month c. User stays in Pune / Mumbai / Bangalore / Chennai d. User has an ATV Accept age, income, city, vehicle from the user and check the above conditions. If any of the conditions are not met, you throw an exception.

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 stays has income between Rs. 50,000 – Rs. 1,00,000 per month
c. User stays in Pune/ Mumbai/ Bangalore / Chennai
d. User has 4-wheeler
Accept age, Income, City, Vehicle from the user and check for the conditions mentioned
above. If any of the condition not met then throw the exception.

OUTPUT FOR THE PROGRAM
#include<iostream>
#include<string.h>
using namespace std;
int main()
{
int age;
double income;
char city[10];
long int vehicle;

cout<<"\nEnter the age: ";
cin>>age;
cout<<"\nEnter the income: ";
cin>>income;
cout<<"\nEnter the city: ";
cin>>city;
cout<<"\nEnter the vehicle(2/4): ";
cin>>vehicle;

try
{
if(age<18 || age>55)
throw age;
else
cout<<"\nAge is Perfect";
}
catch(int)
{
cout<<"\nException caught in age";
}

try
{
if(income<50000 || income>100000)
throw income;
else
cout<<"\nIncome is Perfect";
}
catch(double)
{
cout<<"\nException caught in Income";
}

try
{
if(strcmp(city,"pune") && strcmp(city,"mumbai") && strcmp(city,"bangalore") && strcmp(city,"chennai"))
throw city;
else
cout<<"\nCity is Perfect";
}
catch(char[])
{
cout<<"\nException caught in city";
}
try
{
if(vehicle!=4)
throw vehicle;
else
cout<<"\nVehicle is Perfect";
}
catch(long int)
{
cout<<"\nException caught in vehicle";
}
cout<<"\n\n";
return 0;
}

For more such posts click the link:-http://svencrai.com/G8W

Post a Comment

Previous Post Next Post