-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlec7.cpp
64 lines (56 loc) Β· 1.3 KB
/
lec7.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
#include<iostream>
using namespace std;
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<<"bAmount is deposited successfully"<<endl;
}
else
{
// cout<<"Amount should be greater than 0"<<endl;
throw "Amount should be greater than 0\n";
}
}
void withdraw(int amount)
{
if(amount <= balance && amount > 0)
{
balance-=amount;
cout<<amount<<"Amount is withdrawn successfully"<<endl;
}
else if(amount <0)
{
// cout<<"Amount should be greater than 0"<<endl;
throw "Amount should be greater than 0\n";
}
else{
//cout<<"Insufficient Balance"<<endl;
throw "Insufficient Balance\n";
}
}
};
int main()
{
Customer C1("Jashan" , 124 , 50);
try{
C1.deposit(5000);
C1.withdraw(6000);
}
catch(const char *e)
{
cout<<"Exception occured : "<<e<<endl;
}
}