-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathlec7_2.cpp
More file actions
105 lines (93 loc) Β· 1.94 KB
/
Copy pathlec7_2.cpp
File metadata and controls
105 lines (93 loc) Β· 1.94 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
#include<iostream>
#include<stdexcept> // Include for std::runtime_error
using namespace std;
// class exception
// {
// protected:
// string msg;
// public:
// exception(string msg)
// {
// this->msg = msg;
// }
// string what()
// {
// return msg;
// }
// };
// class runtime_error : public exception
// {
// public:
// runtime_error(const string &msg) : exception(msg);
// };
class Customer
{
string name;
int balance, account_balance;
public:
Customer(string name, int balance, int account_balance)
{
this->name = name;
this->balance = balance;
this->account_balance = account_balance;
}
void deposit(int amount)
{
if (amount > 0)
{
balance += amount;
cout << amount << " Amount is deposited successfully" << endl;
}
else
{
throw runtime_error("Amount should be greater than 0");
}
}
void withdraw(int amount)
{
if (amount <= balance && amount > 0)
{
balance -= amount;
cout << amount << " Amount is withdrawn successfully" << endl;
}
else if (amount <= 0)
{
throw runtime_error("Amount should be greater than 0");
}
else
{
throw runtime_error("Insufficient Balance");
}
}
};
int main()
{
// try{
// int *p = new int[10000000000];
// //cout<<"Memory is allocated"<<endl;
// delete[] p;
// }
// catch(const exception &e)
// {
// cout<<"exception Ocuured due to line : "<<e.what();
// }
Customer C1("Jashan", 124, 50);
try
{
C1.deposit(5000);
C1.withdraw(6000);
}
catch (const exception &e)
{
cout << "Exception occurred: " << e.what() << endl;
}
catch (const bad_alloc &e)
{
cout << "Exception occurred: " << e.what() << endl;
}
catch (...)
{
cout << "Exception occurred" << endl;
}
return 0;
}