-
Notifications
You must be signed in to change notification settings - Fork 242
/
Copy pathBank.cpp
320 lines (286 loc) · 9.67 KB
/
Bank.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
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
#include <iostream>
#include <string>
#include <cmath>
using namespace std;
class Bank
{
public:
int acc_no;
string name, type;
float balance;
Bank() : acc_no(0) {}
void create()
{
static int nxtacc = 1;
acc_no = nxtacc++;
cout << "\nEnter Your Full Name: ";
cin.ignore();
getline(cin, name);
cout << "\nSelect Account Type:" << endl;
cout << "1. Current Account" << endl;
cout << "2. Savings Account" << endl;
cout << "Enter your choice: ";
int typeChoice;
cin >> typeChoice;
if (typeChoice == 1)
{
type = "Current";
}
else if (typeChoice == 2)
{
type = "Savings";
}
else
{
cout << "\nInvalid Option. Please Try Again.\n";
return;
}
cout << "\nEnter Your Initial Deposit: Rs. ";
cin >> balance;
cout << "\nYour Account was Successfully Created with Account Number: " << acc_no << endl << endl;
}
void deposit()
{
float amount;
cout << "\nEnter the Amount You want to Deposit: Rs. ";
cin >> amount;
balance += amount;
cout << "Hey " << name << ", Your Balance is: Rs. " << balance << endl << endl;
}
void withdraw()
{
float amount;
cout << "\nEnter the Amount You want to Withdraw: Rs. ";
cin >> amount;
if (amount > balance)
{
cout << "Insufficient funds" << endl;
}
else
{
balance -= amount;
}
cout << "Hey " << name << ", Your balance is: Rs. " << balance << endl << endl;
}
void display()
{
cout << "\n\nAccount Number: " << acc_no << endl;
cout << "Name: " << name << endl;
cout << "Account Type: " << type << endl;
cout << "Balance: Rs. " << balance << endl << endl;
}
};
class curr_acct : public Bank
{
public:
void updatecur()
{
if (balance < 10000)
{
cout << "Your account doesn't meet the minimum balance.\n A service charge of Rs. 250 will be deducted from your account." << endl;
balance -= 250;
cout << "Please deposit money by cash or by cheque.\nIf you are out of cheque leaves from your chequebook, contact an employee to provide you with a new chequebook.";
}
else
{
cout << "Your account meets the minimum balance.\nNo service charge imposed." << endl;
}
display();
}
void chequebook(Bank* accounts[], int numAccounts)
{
cout << "\nChequeBook Facilities Menu:\n";
cout << "1. Withdraw with Cheque" << endl;
cout << "2. Send Money to Another Account with Cheque" << endl;
cout << "Enter your choice: ";
int choice;
cin >> choice;
switch (choice)
{
case 1:
withdraw();
break;
case 2:
int receiverAccNo;
float amount;
cout << "\nEnter the Receiver's Account Number: ";
cin >> receiverAccNo;
if (receiverAccNo >= 1 && receiverAccNo <= numAccounts && receiverAccNo != acc_no && accounts[receiverAccNo - 1] != nullptr)
{
cout << "\nEnter the Amount to Send: Rs. ";
cin >> amount;
if (amount <= balance)
{
balance -= amount;
accounts[receiverAccNo - 1]->balance += amount;
cout << "\nMoney sent successfully!\n" << endl;
}
else
{
cout << "\nInsufficient funds in your account.\n" << endl;
}
}
else
{
cout << "\nInvalid Receiver's Account Number.\n" << endl;
}
break;
default:
cout << "\nInvalid choice.\n" << endl;
}
}
};
class sav_acc : public Bank
{
public:
void updatesav()
{
float interest, t;
cout << "\nCalculating Interest:" << endl << endl;
cout << "Rate of Interest is 6.8% and interest is compounded quarterly.\n" << endl;
cout << "Please Enter the Time Period of Investment (in years, use decimal if months): "<< endl;
cin >> t;
interest = balance * pow((1+ 0.068/4), (4 * t)) - balance;
cout << "\nYour Interest is = Rs. " << interest << endl;
balance += interest;
display();
}
};
int main()
{
Bank* accounts[10];
int choice1, choice2;
for (int i = 0; i < 10; i++)
{
accounts[i] = nullptr;
}
while (true)
{
cout << "\n\n*** Taz Bank Ltd. Banking App ***\n\n";
cout << "1. Create a New Account" << endl;
cout << "2. Deposit to an Existing Account" << endl;
cout << "3. Withdraw from an Existing Account" << endl;
cout << "4. Account Information Display Menu" << endl;
cout << "5. Update Account" << endl;
cout << "6. ChequeBook Facilities (Only For Current Accounts)" << endl;
cout << "7. Exit" << endl;
cout << "\nEnter your choice: ";
cin >> choice1;
switch (choice1)
{
case 1:
int i;
for (i = 0; i < 10; i++)
{
if (accounts[i] == nullptr)
{
accounts[i] = new Bank();
accounts[i]->create();
break;
}
}
if (i == 10)
{
cout << "\nCannot create more accounts. The limit is reached." << endl;
}
break;
case 2:
int acc_no;
cout << "\nEnter Your Account Number: ";
cin >> acc_no;
if (acc_no >= 1 && acc_no <= 10 && accounts[acc_no - 1] != nullptr)
{
accounts[acc_no - 1]->deposit();
}
else
{
cout << "\nAccount Doesn't Exist!" << endl;
}
break;
case 3:
cout << "\nEnter Your Account Number: ";
cin >> acc_no;
if (acc_no >= 1 && acc_no <= 10 && accounts[acc_no - 1] != nullptr)
{
accounts[acc_no - 1]->withdraw();
}
else
{
cout << "\nAccount Doesn't Exist!" << endl;
}
break;
case 4:
cout << "\n*** Account Information ***\n";
cout << "1. Display Information of an Account" << endl;
cout << "2. Display Information of All Accounts" << endl;
cout << "3. Back to Main Menu" << endl;
cout << "\nEnter your choice: ";
cin >> choice2;
switch (choice2)
{
case 1:
cout << "\nEnter Your Account Number: ";
cin >> acc_no;
if (acc_no >= 1 && acc_no <= 10 && accounts[acc_no - 1] != nullptr)
{
accounts[acc_no - 1]->display();
}
else
{
cout << "\nAccount Doesn't Exist!" << endl;
}
break;
case 2:
for (i = 0; i < 10; i++)
{
if (accounts[i] != nullptr)
{
accounts[i]->display();
}
}
break;
case 3:
break;
default:
cout << "\nInvalid choice in Account Information Menu. Please select a valid option.\n" << endl;
}
break;
case 5:
cout << "\nPlease Enter Your Account Number: ";
cin >> i;
if (accounts[i - 1] != nullptr)
{
if (accounts[i - 1]->type == "Current")
{
static_cast<curr_acct*>(accounts[i - 1])->updatecur();
}
else if (accounts[i - 1]->type == "Savings")
{
static_cast<sav_acc*>(accounts[i - 1])->updatesav();
}
}
break;
case 6:
cout << "\nPlease Enter Your Account Number: ";
cin >> i;
if (accounts[i - 1] != nullptr && accounts[i - 1]->type == "Current")
{
static_cast<curr_acct*>(accounts[i - 1])->chequebook(accounts, 10);
}
else
{
cout << "\nInvalid choice. Chequebook facilities are only available for Current Accounts.\n" << endl;
}
break;
case 7:
cout << "\n\nGoodbye User!! Hope to See You Soon." << endl;
for (i = 0; i < 10; i++)
{
delete accounts[i];
}
return 0;
default:
cout << "\nInvalid choice. Please select a valid option.\n" << endl;
}
}
}