-
Notifications
You must be signed in to change notification settings - Fork 0
/
bankingmanagementsystem.cpp
348 lines (273 loc) · 8.6 KB
/
bankingmanagementsystem.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
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
#include <iostream>
#include <fstream>
#include <ctime>
using namespace std;
struct customer
{
int account_Num;
char name[30];
int balance;
};
void intro();
void withdraw(struct customer list[], int iter, int number, int amt);
int search(struct customer list[80], int size, int number);
void display(struct customer list[80], int iter);
void deposit(struct customer list[], int size, int number, int amt);
void add(struct customer list[80], int iter);
bool deleteAcc(struct customer list[80], int size, int target);
void sortbyAccNumAsc(struct customer list[80], int size);
void sortbyAccNumDes(struct customer list[80], int size);
int main()
{
int n, ch, accountNum, index, amount, iter = 0;
struct customer data[80];
ofstream statFile;
statFile.open("statisticalReport.txt");
if (!statFile)
{
cout << "There is an error with opening the statisticalReport.txt file" << endl;
}
ifstream inFile;
inFile.open("input.txt");
if (!inFile)
{
cout << "There is an error with opening the output.txt file" << endl;
exit(1);
}
inFile >> n;
for (int i = 0; i < n; i++)
{
inFile >> data[i].account_Num >> data[i].name >> data[i].balance;
iter = i + 1;
}
inFile.close();
intro();
statFile << "- the user started the program.." << endl;
while (true)
{
cout << "\t\t\t\t ::MAIN MENU::\n";
cout << "\n\n\t1. DISPLAY RECORDS";
cout << "\n\n\t2. ADD RECORDS";
cout << "\n\n\t3. SEARCH RECORDS";
cout << "\n\n\t4. DEPOSIT AMOUNT";
cout << "\n\n\t5. WITHDRAW AMOUNT";
cout << "\n\n\t6. SORT RECORDS";
cout << "\n\n\t7. DELETE RECORDS";
cout << "\n\n\t0. EXIT";
cout << "\n\n\tSelect Your Option: ";
cin >> ch;
int* p = &iter;
switch (ch)
{
case 1:
display(data, iter);
break;
case 2:
add(data, iter);
iter++;
statFile << "- the user added an account" << endl;
break;
case 3:
cout << "Enter account number to search : ";
cin >> accountNum;
index = search(data, iter, accountNum);
if (index == -1)
{
cout << "Record not found : ";
}
else
{
cout << "Account Number: " << data[index].account_Num <<
endl << "Name: " << data[index].name << endl << "Balance: " << data[index].balance << endl;
statFile << "- the user searched an account" << endl;
}
break;
case 4:
cout << "Enter account number : ";
cin >> accountNum;
cout << "Enter amount to deposit : ";
cin >> amount;
deposit(data, iter, accountNum, amount);
statFile << "- the user deposited from an account" << endl;
break;
case 5:
cout << "Enter account number : ";
cin >> accountNum;
cout << "Enter amount to withdraw : ";
cin >> amount;
withdraw(data, iter, accountNum, amount);
statFile << "- the user withdrawed from an account" << endl;
break;
case 6:
int c2;
cout << "How do you want the records to be sorted?\n1)By account number - Descending\n2)By account number - Ascending" << endl;
cin >> c2;
switch (c2)
{
case 1:
sortbyAccNumDes(data, iter);
statFile << "- the user sorted all accounts desceningly" << endl;
break;
case 2:
sortbyAccNumAsc(data, iter);
statFile << "- the user sorted all accounts ascendingly" << endl;
break;
}
break;
case 7:
char c;
cout << "Enter account number : ";
cin >> accountNum;
cout << "Are you sure you want to delete account number - " << accountNum << " ? (y or n)" << endl;
cin >> c;
if (c == 'y')
{
if (deleteAcc(data, iter, accountNum))
iter--;
else
cout << "Record not found!" << endl;
}
statFile << "- the user deleted an account" << endl;
break;
case 0:
ofstream outFile;
outFile.open("input.txt");
if (!outFile)
{
cout << "There is an error with opening the output.txt file" << endl;
exit(1);
}
outFile << iter << endl;
for (int i = 0; i < iter; i++)
{
outFile << data[i].account_Num << " " << data[i].name << " " << data[i].balance << endl;
}
outFile.close();
statFile << "- the user exited the program" << endl << endl;
const time_t ttime = time(0);
char* dt = ctime(&ttime);
statFile << "Updated: " << dt << endl;
statFile.close();
exit(0);
}
}
return 0;
}
void add(struct customer list[80], int iter)
{
cout << "\nEnter account number : ";
cin >> list[iter].account_Num;
cout << "Enter name : ";
cin >> list[iter].name;
list[iter].balance = 0;
}
void display(struct customer list[80], int iter)
{
if (iter >= 0)
{
cout << "\n\nAccount Number\tName\tBalance\n";
cout << "-------------------------------------------------------" << endl;
for (int i = 0; i < iter; i++)
{
cout << " " << list[i].account_Num << "\t\t" << list[i].name << " " << list[i].balance << endl << "-------------------------------------------------------" << endl;
}
}
else
cout << "There are no records to be displayed.."<<endl;
}
int search(struct customer list[80], int size, int target)
{
for (int i = 0; i < size; i++)
{
if (list[i].account_Num == target)
{
return i;
}
}
return -1;
}
void deposit(struct customer list[], int size, int number, int amount)
{
int i = search(list, size, number);
if (i == -1)
{
cout << "Record not found";
}
else
{
list[i].balance += amount;
}
}
void withdraw(struct customer list[], int s, int number, int amount)
{
int i = search(list, s, number);
if (i == -1)
{
cout << "Record not found\n";
}
else if (list[i].balance < amount)
{
cout << "Insufficient balance\n";
}
else
{
list[i].balance -= amount;
}
}
bool deleteAcc(struct customer list[80], int size, int target)
{
int index = search(list,size,target);
if (index != -1)
{
for (int i = index; i < size; i++)
{
list[i] = list[i+1];
}
return true;
}
return false;
}
void sortbyAccNumAsc(struct customer list[80], int size)
{
//Bubble Sort - Ascending
for (int step = 0; step < size - 1; ++step)
{
for (int i = 0; i < size - step - 1; ++i)
{
if (list[i].account_Num > list[i + 1].account_Num)
{
// swap
struct customer temp = list[i];
list[i] = list[i + 1];
list[i + 1] = temp;
}
}
}
}
void sortbyAccNumDes(struct customer list[80], int size)
{
//Bubble Sort - Descending
for (int step = 0; step < size - 1; ++step)
{
for (int i = 0; i < size - step - 1; ++i)
{
if (list[i].account_Num < list[i + 1].account_Num)
{
// swap
struct customer temp = list[i];
list[i] = list[i + 1];
list[i + 1] = temp;
}
}
}
}
void intro()
{
cout << "\n\n\t\t\t\t======================\n";
cout << "\t\t\t\tBANK MANAGEMENT SYSTEM";
cout << "\n\t\t\t\t======================\n";
cout << endl << endl;
cout << "\t\t\tThis project is done by:" << endl << endl;
cout << "\t\t\t\t\t\tDanyahscript" << endl;
cout << endl << endl;
}