-
Notifications
You must be signed in to change notification settings - Fork 0
/
code.cpp
153 lines (148 loc) · 3.6 KB
/
code.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
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
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
#include<iostream>
#include<vector>
using namespace std;
class BankAccount{
private:
string name;
int accountNum;
double balance;
public:
BankAccount(string n, int ac,double bal){
name = n;
accountNum = ac;
balance = bal;
}
string getName(){
return name;
}
int getAccountNum(){
return accountNum;
}
double getBalance(){
return balance;
}
void deposit(double amount){
balance = balance + amount;
}
void withdraw(double amount){
if(balance >= amount){
balance = balance - amount;
cout<<"\t\tWithdraw Successfully..."<<endl;
}else{
cout<<"\t\tInsufficient Balance...."<<endl;
}
}
};
class BankManagement{
private:
vector<BankAccount> accounts;
public:
void AddAccount(string name,int accountNum,double balance){
accounts.push_back(BankAccount(name,accountNum,balance));
}
void showAllAccounts(){
cout<<"\t\tAll Account Holders "<<endl;
for(int i = 0; i<accounts.size();i++){
cout<<"Name :"<<accounts[i].getName()<<" Account Number :"<<accounts[i].getAccountNum()<<" Balance :"<<accounts[i].getBalance()<<endl;
}
}
void searchAccount(int account){
cout<<"\t\tAccount Holder "<<endl;
for(int i = 0; i<accounts.size();i++){
if(accounts[i].getAccountNum()==account){
cout<<"Name :"<<accounts[i].getName()<<" Account Number :"<<accounts[i].getAccountNum()<<" Balance :"<<accounts[i].getBalance()<<endl;
}
}
}
BankAccount* findAccount(int accountNum){
int i=0;
for(int i = 0; i<accounts.size();i++){
if(accounts[i].getAccountNum()==accountNum){
}
}
return &accounts[i];
}
};
main(){
BankManagement bank;
int choice;
char op;
do{
system("cls");
cout<<"\t\t::Bank Management System"<<endl;
cout<<"\t\t\tMain Menu"<<endl;
cout<<"\t\t1. Creat New Account"<<endl;
cout<<"\t\t2. Show All Account"<<endl;
cout<<"\t\t3. Search Account"<<endl;
cout<<"\t\t4. Deposit Money"<<endl;
cout<<"\t\t5. Withdraw Money"<<endl;
cout<<"\t\t6. Exit"<<endl;
cout<<"\t\t-------------------------------"<<endl;
cout<<"\t\tEnter Your Choice :";
cin>>choice;
switch(choice){
case 1:{
string name;
int accountNum;
double balance;
cout<<"\t\tEnter Name :";
cin>>name;
cout<<"\t\tEnter Account Number :";
cin>>accountNum;
cout<<"\t\tEnter Initial Balance :";
cin>>balance;
bank.AddAccount(name,accountNum,balance);
cout<<"\t\tAccount Created Successfully...."<<endl;
break;
}
case 2:{
bank.showAllAccounts();
break;
}
case 3:{
int accountNum;
cout<<"Enter Account Number :";
cin>>accountNum;
bank.searchAccount(accountNum);
break;
}
case 4:{
int accountNum;
double amount;
cout<<"\t\tEnter Account Number to Deposit Money :";
cin>>accountNum;
BankAccount* account = bank.findAccount(accountNum);
if(account !=NULL){
cout<<"\t\tEnter Amount to Deposit :";
cin>>amount;
account->deposit(amount);
cout<<"\t\t"<<amount<<" Deposit Successfully ...."<<endl;
}else{
cout<<"\t\tAcount Not Found ..."<<endl;
}
break;
}
case 5:{
int accountNum;
double amount;
cout<<"\t\tEnter Account Number to Withdraw Money :";
cin>>accountNum;
BankAccount* account = bank.findAccount(accountNum);
if(account !=NULL){
cout<<"\t\tEnter Amount to withdraw :";
cin>>amount;
account->withdraw(amount);
}else{
cout<<"\t\tAcount Not Found ..."<<endl;
}
break;
}
case 6:{
exit(1);
break;
}
}
cout<<"\t\tDo You Want to Countinue or Exit [Yes/No] ??";
cin>>op;
}while(op == 'y'||op =='Y');
}