-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathUserException.cpp
83 lines (69 loc) · 1.49 KB
/
UserException.cpp
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
#include<bits/stdc++.h>
using namespace std;
class UserEx {
public:
int age;
float sal;
string place;
UserEx(int age) {
age = age;
}
UserEx(float sal) {
sal = sal;
}
UserEx(string place) {
place = place;
}
void dis1() {
cout << "\nAge is " << age;
}
void dis2() {
cout << "\nSalary is " << sal;
}
void dis3() {
cout << "\nPlace is " << place;
}
};
int main() {
int age;
float sal;
string place;
cout << "\nEnter the age, salary and place: ";
try {
cout << "\nEnter the age: ";
cin >> age;
if (age < 18 || age > 55)
throw UserEx(age);
else
cout << "\nAge is: " << age;
}
catch (UserEx e) {
cout << "\nAge is invalid.";
e.dis1();
}
try {
cout << "\nEnter the salary: ";
cin >> sal;
if (sal < 50000 || sal > 150000)
throw UserEx(sal);
else
cout << "\nSalary is: " << sal;
}
catch (UserEx e) {
cout << "\nSalary is invalid.";
e.dis2();
}
try {
cout << "\nEnter the place of working: ";
cin >> place;
if (place != "Pune" || place != "Mumbai" || place != "Bangalore" || place != "Chennai")
throw UserEx(sal);
else
cout << "\nPlace is: " << place;
}
catch (UserEx e) {
cout << "\nPlace is invalid.";
e.dis3();
}
return 0;
}