-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathBanking System.cpp
181 lines (161 loc) · 3.83 KB
/
Banking System.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
#include <iostream>
#include<fstream>
#include"Account.h"
#include"Customer.h"
#include<string>
Customer cus, cus2;
Customer a1, a2;
void startlist() {
cout << "****************BANK System**********************\n"
<< "* 1-Login *\n"
<< "* 2-Regester *\n"
<< "* enter your choise : *\n"
<< "*************************************************\n";
}
void loggedinlist() {
cout << "*******************************************\n"
<< " your Balance =" << cus.getBalance() << "$\n"
<< " *1-Deposit *\n"
<< " *2-Withdraw *\n"
<< " *3-Display Account information *\n"
<< " *4-Transfer Money *\n"
<< " *5-Display All Transactions *\n"
<< " *6-Logout *\n"
<< "********************************************\n";
}
bool loginacc() {
ifstream loginfile("log.txt");
if (!loginfile.is_open()) {
throw runtime_error("Error opening file");
}
string line;
bool loggedin = false;
cout << "Enter your email: ";
string email;
cin >> email;
cout << "Enter your password: ";
string password;
cin >> password;
try {
while (getline(loginfile, line)) {
int pos = line.find(",");
string orgemail = line.substr(0, pos);
string orgpass = line.substr(pos + 1);
if (email == orgemail && password == orgpass) {
cout << "Logged in successfully.\n";
loggedin = true;
cout << "";
}
}
}
catch (const exception& e) {
loginfile.close();
throw runtime_error("Error parsing file");
}
loginfile.close();
if (!loggedin) {
cout << "Please enter valid information.\n";
}
return loggedin;
}
void registeracc() {
cout << "Enter your name : ";
string name;
cin >> name;
cus.setName(name);
cout << "Enter your password : ";
string pass;
cin >> pass;
cus.setpass(pass);
cout << "Enter your Email : ";
string email;
cin >> email;
cus.setEmail(email);
cout << "Enter your Telephone number : ";
string tnumber;
cin >> tnumber;
cus.setPhone_num(tnumber);
cout << "Enter your address : ";
string Address;
cin >> Address;
//cin.ignore();
//getline(cin, Address);
cus.setAddress(Address);
cout << "Enter your Startup balance : ";
int balance;
cin >> balance;
cus.setBalance(balance);
}
using namespace std;
int main()
{
cus2.setBalance(1000);
int choise;
while (true)
{
cout << "Pleaes enter valid choise \n";
startlist();
cin >> choise;
switch (choise)
{
case 1:
if (loginacc()) {
int secoundchoise = 1;
int end = 6;
while (secoundchoise != end)
{
cout << "Pleaes enter valid choise \n";
cus.loadData(cus);
loggedinlist();
cin >> secoundchoise;
switch (secoundchoise)
{
case 1:
float DepTra;
cout << " Enter How much money you will deposit? \n";
cin >> DepTra;
cus.DepositTra(DepTra);
cus.savedata(cus);
cus.loadData(cus);
break;
case 2:
float WithTra;
cout << " Enter How much money you will withdraw? \n";
cin >> WithTra;
cus.WithdrawTra(WithTra);
cus.savedata(cus);
cus.loadData(cus);
break;
case 3:
cus.customerinfo(cus);
cus.savedata(cus);
cus.loadData(cus);
break;
case 4:
float trans_balance;
cout << "Enter Balance you will transfer : ";
cin >> trans_balance;
cus.transferBalance(cus2, trans_balance);
cout << "now customer two has balance : ";
cout << cus2.getBalance() << "\n";
cus.savedata(cus);
cus.loadData(cus);
break;
case 5:
cus.displayTransactionHistory();
default:
break;
}
}
}
break;
case 2:
registeracc();
cus.savedata(cus);
cus.hidendata(cus);
break;
default:
break;
}
}
}