-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbank.cpp
More file actions
86 lines (85 loc) · 2.5 KB
/
bank.cpp
File metadata and controls
86 lines (85 loc) · 2.5 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
#include<iostream>
using namespace std;
class BankAccount
{
private:
string holdername;
double balance;
public:
BankAccount(string name, double initialBalance)
{
holdername = name;
balance = initialBalance;
}
void deposit(double amount)
{
if(amount<0)
{
cout<<"enter a valid amount to deposit"<<endl;
}
else
{
balance +=amount;
cout<<"deposit succesful"<< endl<<"balance:"<<balance<<endl;
}
}
void withdraw(double amount)
{
if(amount>balance)
{
cout<<"insufficient balance"<<endl;
}
else if(amount<=0)
{
cout<<"enter a valid amount to withdraw"<<endl;
}
else
{
balance-=amount;
cout<<"withdrawal successful"<<endl<<"balance:"<<balance<<endl;
}
}
void displayaccountinfo()
{
cout<<"account holder:"<<holdername<<endl;
cout<<"balance :"<<balance<<endl;
}
};
int main()
{
string honame;
int bal;
int dep;
int with;
int choice;
cout<<"enter the name of the holder"<<endl;
cin>>honame;
cout<<"enter the balance "<<endl;
cin>>bal;
BankAccount account(honame,bal);
cout<<"choose an option:"<<endl<<"1.ACCOUNT INFO"<<endl<<"2.DEPOSIT"<<endl<<"3.WITHDRAWAL"<<endl;
cout<<"enter your choice"<<endl;
cin>> choice;
switch(choice)
{
case 1:
account.displayaccountinfo();
break;
case 2:
cout<<"enter the amount to deposit"<<endl;
cin>>dep;
account.deposit(dep);
account.displayaccountinfo();
break;
case 3:
cout<<"enter the amount to withdraw"<<endl;
cin>>with;
account.withdraw(with);
account.displayaccountinfo();
break;
default:
cout<<"invalid choice"<<endl;
break;
}
return 0;
}