-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
192 lines (172 loc) · 5.3 KB
/
main.cpp
File metadata and controls
192 lines (172 loc) · 5.3 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
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
#include<iostream>
#include<iomanip>
#include<fstream>
#include<cctype>
using namespace std;
class Bank_Account{
int acc_no;
char name[50];
char acc_type;
int deposit_money;
public:
int ret_acc_num() const{
return acc_no;
}
void create_account();
void display_account();
void report() const;
};
void Bank_Account :: report() const{
cout << acc_no << setw(10) << " " << name << setw(10) << acc_type << setw(6) << deposit_money << endl;
}
void Bank_Account :: create_account(){
system("cls");
cout << "\t Enter the account number: ";
cin >> acc_no;
cout << "\t Enter the account holder name: ";
cin.ignore();
cin.getline(name, 50);
cout << "\t Enter the type of the account (C/S): ";
cin >> acc_type;
acc_type = toupper(acc_type);
cout << "\t Enter the initial amount: ";
cin >> deposit_money;
cout << endl;
cout << "\t Account Created... :)" << endl;
}
void Bank_Account :: display_account(){
cout << "\t Bank Account Number: " << acc_no << endl;
cout << "\t Account Holder Name: " << name << endl;
cout << "\t Account Type: ";
if(acc_type == 'C') cout << "Current" << endl;
else cout << "Savings" << endl;
cout << "\t Balance Amount: " << deposit_money << endl;
}
void new_account(){
Bank_Account AC;
ofstream outFile;
outFile.open("account.dat", ios::binary | ios::app);
AC.create_account();
outFile.write(reinterpret_cast<char *> (&AC), sizeof(Bank_Account));
outFile.close();
}
void delete_account(int acc_no){
Bank_Account AC;
ifstream inFile;
ofstream outFile;
inFile.open("account.dat", ios::binary);
if(!inFile){
cout << "File could not be opened!! Press any key...";
return;
}
outFile.open("Temp.dat", ios::binary);
inFile.seekg(0, ios::beg);
while(inFile.read(reinterpret_cast<char *> (&AC), sizeof(Bank_Account))){
if(AC.ret_acc_num() != acc_no){
outFile.write(reinterpret_cast<char *> (&AC), sizeof(Bank_Account));
}
}
inFile.close();
outFile.close();
remove("Bank_Account.dat");
rename("Temp.dat", "Bank_Account.dat");
cout << "\t Record Deleted..." << endl;
}
void balance_enquiry(int acc_no){
Bank_Account AC;
bool flag = false;
ifstream inFile;
inFile.open("account.dat", ios::binary);
if(!inFile){
cout << "File could not be opened!! Press any key...";
return;
}
cout << "\t Bank Account Details" << endl;
while(inFile.read(reinterpret_cast<char *> (&AC), sizeof(Bank_Account))){
if(AC.ret_acc_num() == acc_no){
AC.display_account();
flag = true;
}
}
inFile.close();
if(flag == false){
cout << "\t Account number does not exist" << endl;
}
}
void display_all_details(){
system("cls");
Bank_Account AC;
ifstream inFile;
ofstream outFile;
inFile.open("account.dat", ios::binary);
if(!inFile){
cout << "File could not be opened!! Press any key...";
return;
}
cout << "\t Bank Account Holder List" << endl;
cout << "=============================================" << endl;
cout << "A/c no. NAME TYPE BALANCE" << endl;
cout << "=============================================" << endl;
while(inFile.read(reinterpret_cast<char *> (&AC), sizeof(Bank_Account))){
AC.report();
}
}
int main()
{
int ch, acc_no;
do{
system("cls");
cout << "\t\t\t--------------------------------------------" << endl;
cout << "\t\t\t| Welcome to the Banking Management System |" << endl;
cout << "\t\t\t--------------------------------------------" << endl;
cout << endl;
cout << "\t\t\t\t--- Main Menu ---" << endl;
cout << endl;
cout << "\t 1. Create an Account" << endl;
cout << "\t 2. Deposit Money" << endl;
cout << "\t 3. Withdraw Money" << endl;
cout << "\t 4. Balance Enquiry" << endl;
cout << "\t 5. All Account Holder List" << endl;
cout << "\t 6. Modify an Account" << endl;
cout << "\t 7. Close an Account" << endl;
cout << "\t 8. Exit" << endl;
cout << endl;
cout << "Enter your choice (1-8): ";
cin >> ch;
switch(ch){
case 1: // create account
new_account();
break;
case 2: // deposit func
system("cls");
cout << "\t Enter the account number: ";
cin >> acc_no;
break;
case 3: // withdraw func
system("cls");
cout << "\t Enter the account number: ";
cin >> acc_no;
break;
case 4: // balance enquiry func
system("cls");
cout << "\t Enter the account number: ";
cin >> acc_no;
balance_enquiry(acc_no);
break;
case 5: // account details func
display_all_details();
break;
case 6: // modify acc func
break;
case 7: // close acc func
system("cls");
cout << "\t Enter the account number: ";
cin >> acc_no;
delete_account(acc_no);
break;
case 8:
cout << "\nThank you for using our service! Please come back again!!\n";
break;
}
}while(ch != 8);
}