-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain.cpp
328 lines (322 loc) · 13.1 KB
/
main.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
#include "account.h"
#include "customer.h"
#include "transaction.h"
#include "debit_card.h"
#include <conio.h>
#include <iostream>
#include <fstream>
#include <windows.h>
using namespace std;
int main()
{
int resp;
while(1)
{
cout<<"\t\t----------------------ATM & BANK PORTAL----------------------\n";
cout<<"\n(1)Enter as Customer\n(2)Enter Bank\n(3)ATM\n(4)Exit\n\nEnter your option : ";
cin>>resp;
if(resp==1)
{
int opt;
cout<<"(1)Customer Login\n(2)New Customer(Sign-up)\n\nEnter your option : ";
cin>>opt;
if(opt==1)
{
char password[20];
long long int id;
Customer c(1);
cout<<"\nEnter your ID : ";
cin>>id;
cout<<"\nEnter Password : ";
cin.ignore();
cin.getline(password,20);
int op=get_customer(c,id,password);
if(op==1)
{
cout<<"\nLogged-in Successfully\n";
cout<<"\n(1)Display Details\n(2)My Transactions\n(3)Transfer Money";
if(c.get_CurrentAccount().get_AccountNum()==-1)
{
cout<<"\n(4)Create Current Account";
}
if(c.get_SavingsAccount().get_AccountNum()==-1)
{
cout<<"\n(5)Create Savings Account";
}
cout<<"\n\nEnter your option : ";
int option;
cin>>option;
if(option==1)
{
cout<<"\nYour Account Details :\n\n";
c.display();
}
else if(option==2)
{
int opt;
cout<<"\n(1)Savings Account\n(2)Current Account\n\nEnter your option : ";
cin>>opt;
cout<<"\nYour Transaction Details : \n\n";
if(opt==1)
{
cout<<"Savings Account\n----------------\n";
Transactions::display_transaction_of(c.get_SavingsAccount().get_AccountNum());
}
else if(opt==2)
{
cout<<"\nCurrent Account\n----------------\n";
Transactions::display_transaction_of(c.get_CurrentAccount().get_AccountNum());
}
else
{
cout<<"\nInvalid Option\n";
}
}
else if(option==3)
{
if(c.get_SavingsAccount().get_AccountNum()!=-1)
{
cout<<"\n(1)Transfer from Savings Account\n";
}
if(c.get_CurrentAccount().get_AccountNum()!=-1)
{
cout<<"(2)Transfer from Current Account\n";
}
cout<<"\nEnter your option : ";
int oppp;
cin>>oppp;
if(oppp==1)
{
Savings_account my_account;
Savings_account::get_account(c.get_SavingsAccount().get_AccountNum(),my_account);
cout<<"\nEnter Account Number of the Recipient : ";
int to_account;
float amount;
cin>>to_account;
Current_account acc1;
Savings_account acc2;
int n1,n2;
n1=Current_account::get_account(to_account,acc1);
n2=Savings_account::get_account(to_account,acc2);
if(n1==1)
{
cout<<"\nEnter Amount to Transfer : ";
cin>>amount;
if(my_account.debit(amount))
{
acc1.credit(amount);
cout<<"\nTransfer Successful\n";
Transfer t(my_account.get_AccountNum(),acc1.get_AccountNum(),amount);
}
}
if(n2==1)
{
cout<<"\nEnter Amount to Transfer : ";
cin>>amount;
if(my_account.debit(amount))
{
acc2.credit(amount);
cout<<"\nTransfer Successful\n";
Transfer t(my_account.get_AccountNum(),acc2.get_AccountNum(),amount);
}
}
if(n1==0 && n2==0)
{
cout<<"\nRecipient Account Does not exist\nTransfer Failed!!\n";
}
}
else if(oppp==2)
{
Current_account my_account;
Current_account::get_account(c.get_CurrentAccount().get_AccountNum(),my_account);
cout<<"\nEnter Account Number of the Recipient : ";
int to_account;
float amount;
cin>>to_account;
Current_account acc1;
Savings_account acc2;
int n1,n2;
n1=Current_account::get_account(to_account,acc1);
n2=Savings_account::get_account(to_account,acc2);
if(n1==1)
{
cout<<"\nEnter Amount to Transfer : ";
cin>>amount;
if(my_account.debit(amount))
{
acc1.credit(amount);
cout<<"\nTransfer Successful\n";
Transfer t(my_account.get_AccountNum(),acc1.get_AccountNum(),amount);
}
}
if(n2==1)
{
cout<<"\nEnter Amount to Transfer : ";
cin>>amount;
if(my_account.debit(amount))
{
acc2.credit(amount);
cout<<"\nTransfer Successful\n";
Transfer t(my_account.get_AccountNum(),acc2.get_AccountNum(),amount);
}
}
if(n1==0 && n2==0)
{
cout<<"\nRecipient Account Does not exist\nTransfer Failed!!\n";
}
}
}
else if(option==4)
{
Current_account acc(c.get_name());
c.set_CurrentAccount(acc);
}
else if(option==5)
{
Savings_account acc(c.get_name());
c.set_SavingAccount(acc);
}
}
else
{
cout<<"\nLogin Unsuccessful\n";
}
}
else if(opt==2)
{
cout<<"\nEnter Your Details :\n";
Customer c;
ofstream obj;
obj.open("customers.txt",ios::app);
obj.write((char *)&c,sizeof(c));
obj.close();
}
}
else if(resp==2)
{
cout<<"(*) Display ";
cout<<"\n\t(1)All Transactions\n\t(2)Credit Transactions\n\t(3)Debit Transactions\n\t(4)Transfer Transactions\n";
cout<<"\nEnter your Option : ";
int opt;
cin>>opt;
if(opt==1)
{
Transactions::display_all();
}
else if(opt==2)
{
cout<<"\n\nCrediting Details : \n--------------------\n";
Credited::display_all();
}
else if(opt==3)
{
cout<<"\nWithdrawal Details : \n--------------------\n";
Withdrawl::display_all();
}
else if(opt==4)
{
cout<<"\n\nTransfer Details : \n--------------------\n";
Transfer::display_all();
}
else
{
cout<<"Invalid Option!\n\n ";
}
}
else if(resp==3)
{
long long int card;
cout<<"\nEnter Your Card Number : ";
cin>>card;
Debit_card my_card;
if(Debit_card::get_card(card,my_card)==0)
{
cout<<"\nInvalid Debit Card Number! Contact your nearest branch\n";
}
else
{
if(my_card.access())
{
cout<<"(1)Change Pin\n(2)Credit\n(3)Withdraw\n";
cout<<"\nEnter your option : ";
int opt;
cin>>opt;
if(opt==1)
{
my_card.change_pin();
char type=my_card.get_type();
if(type=='c')
{
cout<<"\nUpdated Account Info :\n";
Current_account acc;
Current_account::get_account(my_card.get_AccountNum(),acc);
acc.set_debitcard(my_card);
Customer cust(1);
cust=get_customer(cust,acc.get_owner());
cust.set_CurrentAccount(acc);
}
else if(type=='s')
{
cout<<"\nUpdated Account Info :\n";
Savings_account acc;
Savings_account::get_account(my_card.get_AccountNum(),acc);
acc.set_debitcard(my_card);
Customer cust(1);
cust=get_customer(cust,acc.get_owner());
cust.set_SavingAccount(acc);
}
}
else if(opt==2)
{
cout<<"\nCredit Option : \n";
char type=my_card.get_type();
if(type=='c')
{
Current_account acc;
Current_account::get_account(my_card.get_AccountNum(),acc);
acc.credit();
}
else if(type=='s')
{
Savings_account acc;
Savings_account::get_account(my_card.get_AccountNum(),acc);
acc.credit();
}
}
else if(opt==3)
{
char type=my_card.get_type();
if(type=='c')
{
Current_account acc;
Current_account::get_account(my_card.get_AccountNum(),acc);
acc.debit();
}
else if(type=='s')
{
Savings_account acc;
Savings_account::get_account(my_card.get_AccountNum(),acc);
acc.debit();
}
}
else
{
cout<<"\nInvalid Option...Exiting ATM\n";
}
}
}
}
else if(resp==4)
{
break;
}
else
{
cout<<"\nInvalid Option...\n";
}
cout<<"\nEnter any key to continue...";
getch();
system("cls");
}
return 0;
}