-
Notifications
You must be signed in to change notification settings - Fork 0
/
Bank Management Demo.cpp
247 lines (206 loc) · 5.24 KB
/
Bank Management Demo.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
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
#include<bits/stdc++.h>
using namespace std;
class BankAccount
{
public:
string accountHolder;
string address;
int age;
int accountNumber;
protected:
int balance;
private:
string password;
public:
BankAccount(string accountHolder, string address, int age, string password)
{
srand(time(0));
this->accountHolder = accountHolder;
this->address = address;
this->age = age;
this->password = password;
this->balance = 0;
this->accountNumber = rand()%1000000000;
cout << "Your Account No. is : " << this->accountNumber << endl;
}
string givePassword()
{
return password;
}
int showBalance(string password)
{
if(this->password==password)
return this->balance;
else
return -1;
}
void addMoney(string password, int amount)
{
if(amount < 0)
{
cout << "Invalid Amount" << endl;
return;
}
if(this->password == password)
{
this->balance += amount;
cout << "Successfully Money Added" << endl;
}
else
cout << "Password Incorrect" << endl;
}
void depositMoney(string password, int amount)
{
if(amount < 0)
{
cout << "Invalid Amount" << endl;
return;
}
if(this->balance < amount)
{
cout << "Insufficient Balance" << endl;
return;
}
if(this->password == password)
{
this->balance -= amount;
cout << "Successfully Money Deposit" << endl;
}
else
cout << "Password Incorrect" << endl;
}
friend class MyCash;
};
class MyCash
{
protected:
int balance;
public:
MyCash()
{
this->balance = 0;
}
void addMoneyFromBank(BankAccount *myAccount, string password, int amount)
{
if(amount < 0)
{
cout << "Invalid Amount" << endl;
return;
}
if(myAccount->balance < amount)
{
cout << "Insufficient Balance" << endl;
return;
}
if(myAccount->password == password)
{
this->balance += amount;
myAccount->balance -= amount;
cout << "Successfully Money Added from Bank Account" << endl;
}
else
cout << "Password Incorrect" << endl;
}
int showBalance()
{
return this->balance;
}
};
BankAccount* createAccount();
void add_money(BankAccount *myAccount);
void deposit_money(BankAccount *myAccount);
void add_money_from_bank(MyCash *myCash, BankAccount *myAccount);
int main()
{
BankAccount *myAccount = createAccount();
MyCash *myCash = new MyCash();
while(true)
{
cout << endl;
cout << "Select Option:" << endl;
cout << " 1. ADD Money to Bank." << endl;
cout << " 2. DEPOSITE Money from Bank." << endl;
cout << " 3. ADD Money to MyCash from Bank." << endl;
cout << " 4. Exit." << endl;
cout << endl;
bool isExit = false;
int option;
cin >> option;
switch(option)
{
case 1:
add_money(myAccount);
break;
case 2:
deposit_money(myAccount);
break;
case 3:
add_money_from_bank(myCash, myAccount);
break;
case 4:
isExit = true;
break;
default:
cout << "Invalid Option Entered..!\n\n" << endl;
}
if(isExit)
{
delete myAccount;
break;
}
}
return 0;
}
BankAccount* createAccount()
{
string accountHolder, password, address;
int age;
cout << "CREATE NEW ACCOUNT:" << endl;
cout << "Your Name: ";
cin >> accountHolder;
cout << "Your Address: ";
cin >> address;
cout << "Your Age: ";
cin >> age;
cout << "Password: ";
cin >> password;
BankAccount *myAccount = new BankAccount(accountHolder, address, age, password);
return myAccount;
}
void add_money(BankAccount *myAccount)
{
string password;
int amount;
cout << "ADD MONEY:" << endl;
cout << "Password: ";
cin >> password;
cout << "Amount: ";
cin >> amount;
myAccount->addMoney(password, amount);
cout << "Your Balance: " << myAccount->showBalance(myAccount->givePassword()) << endl;
}
void deposit_money(BankAccount *myAccount)
{
string password;
int amount;
cout << "DEPOSIT MONEY:" << endl;
cout << "Password: ";
cin >> password;
cout << "Amount: ";
cin >> amount;
myAccount->depositMoney(password, amount);
cout << "Your Balance: " << myAccount->showBalance(myAccount->givePassword()) << endl;
}
void add_money_from_bank(MyCash *myCash, BankAccount *myAccount)
{
string password;
int amount;
cout << "ADD MONEY FROM BANK" << endl;
cout << "Password: ";
cin >> password;
cout << "Amount: ";
cin >> amount;
myCash->addMoneyFromBank(myAccount, password, amount);
cout << "Your Bank Balance is: " << myAccount->showBalance(myAccount->givePassword()) << endl;
cout << "MyCash Balance is: " << myCash->showBalance() << endl;
}