-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAssignment 7.cpp
More file actions
115 lines (112 loc) · 1.78 KB
/
Assignment 7.cpp
File metadata and controls
115 lines (112 loc) · 1.78 KB
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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
//============================================================================
// Name : Assignment14.cpp
// Author :
// Version :
// Copyright : Your copyright notice
// Description : Hello World in C++, Ansi-style
//============================================================================
#include <iostream>
using namespace std;
class ExceptionH{
public:
int age;
double income;
string city;
char veh;
ExceptionH()
{
}
ExceptionH(int a)
{
age=a;
}
ExceptionH(double i)
{
income=i;
}
ExceptionH(string c)
{
city=c;
}
ExceptionH(char v)
{
veh=v;
}
void E_Age()
{
cout<<"Invalid age"<<endl;
}
void E_Income()
{
cout<<"Invalid income"<<endl;
}
void E_City()
{
cout<<"Invalid city"<<endl;
}
void E_Vehicle()
{
cout<<"Invalid option"<<endl;
}
};
int main() {
ExceptionH o1;
try
{
cout<<"Enter age : ";
cin>>o1.age;
if(o1.age<18||o1.age>55)
throw ExceptionH(o1.age);
else
cout<<"Age : "<<o1.age<<endl;
}
catch(ExceptionH e)
{
e.E_Age();
}
try
{
cout<<"Enter income : ";
cin>>o1.income;
if(o1.income>100000||o1.income<50000)
throw ExceptionH(o1.income);
else
cout<<"Income : "<<o1.income<<endl;
}
catch(ExceptionH e)
{
e.E_Income();
}
try
{
cout<<"Enter city : ";
cin>>o1.city;
if(o1.city!="Pune"&&o1.city!="Mumbai"&&o1.city!="Chennai"&&o1.city!="Bangalore")
throw ExceptionH(o1.city);
else
cout<<"City : "<<o1.city<<endl;
}
catch(ExceptionH e)
{
e.E_City();
}
try
{
cout<<"Does user have a 4-wheeler? (Y/N): ";
cin>>o1.veh;
if(o1.veh!='Y'&&o1.veh!='N')
throw ExceptionH(o1.veh);
else
{
if(o1.veh=='Y')
cout<<"Yes the user has a 4-wheeler";
else
cout<<"No the user does not have a 4-wheeler";
}
}
catch(ExceptionH e)
{
e.E_Vehicle();
}
return 0;
}