-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCourse 08 Project 2 ATM System.cpp
More file actions
272 lines (230 loc) · 7.14 KB
/
Copy pathCourse 08 Project 2 ATM System.cpp
File metadata and controls
272 lines (230 loc) · 7.14 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
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
#include <iostream>
#include "MyBankDataLib.h"
#include "MyDateLib.h"
#include "MyHijriDateLib.h"
#include <limits>
#include <string>
using namespace std;
namespace bank = MyBankDataLib;
enum enATM { eQuickWithdraw = 1, eNormalWithdraw = 2, eDeposit = 3, eCheckBalance = 4, eChangePassword = 5, eLogout = 6 };
void ShowDate(bool FullDate = true)
{
if(FullDate)
{
MyDateLib::stDate MDate = MyDateLib::GetSystemDate();
cout << MyDateLib::PrintDate(MDate, 1);
MyHijriDateLib::stHijriDate HDate = MyHijriDateLib::ConvertMiladiToHijriTrastedUsingMiladiDay(MDate.Day, MDate.Month, MDate.Year);
cout << "\t | " << MyHijriDateLib::PrintHijriDate(HDate);
}
else
{
cout << MyDateLib::PrintDate(MyDateLib::GetSystemDate() , 1);
}
}
void Header(string Title)
{
ShowDate();
cout << "\n=========================================\n";
cout << "\t " << Title;
cout << "\n=========================================\n";
}
short GetQuickWithdrawChoiceAmount(short Choice)
{
short arr[] = { 20, 50, 100, 200, 400, 600, 800, 1000 };
return arr[Choice - 1];
}
void ShowQuickWithdrawScreen(bank::stClientData& Client)
{
system("cls");
short Choice;
ShowDate();
Header("Quick Withdraw");
cout << "\t[1] 20.\t";
cout << "\t[2] 50.\n";
cout << "\t[3] 100.";
cout << "\t[4] 200.\n";
cout << "\t[5] 400.";
cout << "\t[6] 600.\n";
cout << "\t[7] 800.";
cout << "\t[8] 1000.\n";
cout << "\t\t[9] Exit.";
cout << "\n=========================================\n";
cout << "Your Balance is " << to_string(Client.AccountBalance) << endl;
Choice = MyInputLib::ReadNumberInRange(1, 9, "Choose what do you want to do");
if (Choice == 9) return;
short Amount = GetQuickWithdrawChoiceAmount(Choice);
while (Amount > Client.AccountBalance)
{
cout << "\n [Transaction Denied]: Insufficient Balance!\n";
Choice = MyInputLib::ReadNumberInRange(1, 9, "Choose what do you want to do");
if (Choice == 9) return;
Amount = GetQuickWithdrawChoiceAmount(Choice);
}
bank::DepositClientBalanceByAccountNumberForATM(Client.AccountNumber, (Amount * -1));
Client.AccountBalance -= Amount;
}
void ShowNormalWithdrawScreen(bank::stClientData& Client)
{
system("cls");
ShowDate();
Header("Normal Withdraw");
cout << "Your Balance is " << to_string(Client.AccountBalance);
cout << "\n=========================================\n";
short Amount = MyInputLib::ReadPositiveNumber("Enter an Amount multiply of 5`s : ");
while (Amount > Client.AccountBalance || Amount%5 != 0)
{
cout << "\n [Transaction Denied]: Insufficient Balance!\n";
Amount = MyInputLib::ReadPositiveNumber("Enter an Amount multiply of 5`s : ");
}
bank::DepositClientBalanceByAccountNumberForATM(Client.AccountNumber, (Amount * -1));
Client.AccountBalance -= Amount;
}
void ShowDepositScreen(bank::stClientData& Client)
{
system("cls");
ShowDate();
Header("Normal Withdraw");
cout << "Your Balance is " << to_string(Client.AccountBalance);
cout << "\n=========================================\n";
short Amount = MyInputLib::ReadPositiveNumber("Enter an Amount multiply of 5`s : ");
while (Amount % 5 != 0)
{
cout << "\n [Transaction Denied]!\n";
Amount = MyInputLib::ReadPositiveNumber("Enter an Amount multiply of 5`s : ");
}
bank::DepositClientBalanceByAccountNumberForATM(Client.AccountNumber, (Amount));
Client.AccountBalance += Amount;
}
void GoBackToMainMenu()
{
cout << "\n\nPress any key to go back to Main Menu...";
system("pause>0");
}
void CheckBalanceScreen(const bank::stClientData& Client)
{
system("cls");
ShowDate();
Header("Check Balance");
cout << "Your Balance is " << to_string(Client.AccountBalance) << endl;
}
void ShowChangePasswordScreen(vector<bank::stClientData>& vClients, bank::stClientData& Client)
{
string PinCode = "";
string RePinCode = "";
char Answer = 'n';
system("cls");
ShowDate();
Header("Change Password/PinCode");
cout << "\nAre you sure you want to change PinCode? [Y/N] : ";
cin >> Answer;
cin.ignore(numeric_limits<streamsize>::max(), '\n');
if (Answer == 'y' || Answer == 'Y')
{
do
{
system("cls");
ShowDate();
Header("Change Password/PinCode");
PinCode = MyStringLib::ReadString("Enter New PinCode: ");
RePinCode = MyStringLib::ReadString("Re Enter New PinCode: ");
if (PinCode != RePinCode) cout << "\nInvalid New Password!\n";
} while (PinCode != RePinCode);
if (PinCode == RePinCode)
{
if (bank::UpdateClientPinCode(Client.AccountNumber, vClients, RePinCode))
{
cout << "\n[PinCode Changed Successfully].\n";
Client.PinCode = RePinCode;
}
else
cout << "\nSomething Wrong Happened!\n[Operation Failed].\n";
}
else
cout << "\n[Operation Failed].\n";
}
else return;
}
/*
bool UpdateClientPinCode(string AccountNumber, vector <stClientData>& vClients,string NewPinCode)
{
for (stClientData& c : vClients)
{
if (AccountNumber == c.AccountNumber)
{
c.PinCode == NewPinCode;
return true;
}
}
return false;
}
*/
void PerformATM_Screen(enATM ATMOptions, vector<bank::stClientData>& vClients, bank::stClientData& Client)
{
switch (ATMOptions)
{
case eQuickWithdraw: ShowQuickWithdrawScreen(Client);
GoBackToMainMenu();
break;
case eNormalWithdraw:ShowNormalWithdrawScreen(Client);
GoBackToMainMenu();
break;
case eDeposit:ShowDepositScreen(Client);
break;
case eCheckBalance: CheckBalanceScreen(Client);
GoBackToMainMenu();
break;
case eChangePassword: ShowChangePasswordScreen(vClients, Client);
GoBackToMainMenu();
break;
case eLogout:
break;
}
}
void ShowATM_MainMenuScreen(vector<bank::stClientData>& vClients, bank::stClientData& Client)
{
enATM Choice;
do {
system("cls");
system("color 0A");
ShowDate();
cout << "\n==========================================\n";
cout << "==========[ATM Main Menu Screen]==========";
cout << "\n==========================================\n";
cout << "\t[1] Quick Withdraw.\n";
cout << "\t[2] Normal Withdraw.\n";
cout << "\t[3] Deposit.\n";
cout << "\t[4] Check Balances.\n";
cout << "\t[5] ChangePassword.\n";
cout << "\t[6] Logout.\n";
cout << "==========================================\n";
Choice = (enATM)MyInputLib::ReadNumberInRange(1, 6, "Choose what do you want to do");
cin.ignore(std::numeric_limits<std::streamsize>::max(), '\n');
PerformATM_Screen(Choice, vClients,Client);
} while (Choice != enATM::eLogout);
}
void Login()
{
vector<bank::stClientData> vClients = bank::LoadClientsDataFromFile(bank::GetClientsFileName());
bank::stClientData Client;
string AccountNumber = "", PinCode = "";
do
{
system("cls");
Header("Login Screen");
AccountNumber = MyStringLib::ReadString("Enter Account Number: ");
PinCode = MyStringLib::ReadString("Enter PinCode: ");
while (!bank::FindClientByAccountNumberAndPinCode(AccountNumber, PinCode, Client, vClients))
{
system("cls");
Header("Login Screen");
cout << "\nInvalid AccountNumber/PinCode!\n";
AccountNumber = MyStringLib::ReadString("Enter Account Number: ");
string PinCode = MyStringLib::ReadString("Enter PinCode: ");
}
ShowATM_MainMenuScreen(vClients, Client);
} while (true);
}
int main()
{
Login();
}