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.

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

Comments

Popular posts from this blog

A book shop maintains the inventory of books that are being sold at the shop. The list includes details such as author, title, price, publisher and stock position. Whenever a customer wants a book, the sales person inputs the title and author and the system searches the list and displays whether it is available or not. If it is not, an appropriate message is displayed. If it is, then the system displays the book details and requests for the number of copies required. If the requested copies book details and requests for the number of copies required. If the requested copies are available, the total cost of the requested copies is displayed; otherwise the message ?Required copies not in stock? is displayed. Design a system using a class called books with suitable member functions and Constructors. Use new operator in constructors to allocate memory space required. Implement C++ program for the system

Write C++ program for storing appointment schedule for day. Appointments are booked randomly using linked list. Set start and end time and min and max duration for visit slot. Write functions for- a)Display free slots b)Book appointment c)Cancel appointment ( check validity, time bounds, availability etc) d)Sort list based on time e)Sort list based on time using pointer manipulation

Imagine a publishing company which does marketing for book and audiocassette versions. Create a class publication that stores the title (a string) and price (type float) of a publication. From this class derive two classes: book, which adds a page count (type int), and tape, which adds a playing time in minutes (type float). Write a program that instantiates the book and tape classes, allows user to enter data and displays the data members.