-
Notifications
You must be signed in to change notification settings - Fork 0
/
EXCEPTION HANDLING
91 lines (91 loc) · 1.36 KB
/
EXCEPTION HANDLING
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
#include <iostream>
#include <string.h>
using namespace std;
class data
{
int age;
string city;
double income;
char fw;
int c=0;
public:
void getage()
{
try
{
cout<<"Enter age:"<<endl;
cin>>age;
if(age<18||age>55)
throw(age);
else
c++;
}
catch(int i)
{
cout<<"Exception caught: Age should be between 18-55 years"<<endl;
}
}
void getcity()
{
try
{
cout<<"Enter the city you live in:"<<endl;
cin>>city;
if(city=="Pune"||city=="Mumbai"||city=="Bangalore"||city=="Chennai")
c++;
else
throw(city);
}
catch(string s)
{
cout<<"Exception caught: City should be either Pune, Mumbai, Bangalore or Chennai"<<endl;
}
}
void getincome()
{
try
{
cout<<"Enter monthly income:"<<endl;
cin>>income;
if(income<50000||income>100000)
throw(income);
else
c++;
}
catch(double d)
{
cout<<"Exception caught:Income should be between Rs. 50,000- Rs. 1,00,000"<<endl;
}
}
void fourw()
{
try
{
cout<<"Do you have a four wheeler? Y or N"<<endl;
cin>>fw;
if(fw=='y'||fw=='Y')
c++;
else
throw(fw);
}
catch(char w)
{
cout<<"Exception caught: 4 wheeler not present"<<endl;
}
}
void print()
{
if(c==4)
cout<<"No incorrect data provided, thanks";
}
};
int main()
{
data obj;
obj.getage();
obj.getincome();
obj.getcity();
obj.fourw();
obj.print();
return 0;
}