This repository has been archived by the owner on Dec 5, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathEngine.h
293 lines (282 loc) · 9.1 KB
/
Engine.h
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
/*
OHEED IMRAN
CS-D
19I-0525
*/
#include "Database.h"
#include <cstdlib>
#include <ctime>
class Engine:public Database
{
private:
int FirstOptions;
int SecondOptions;
public:
Engine();
int getFirstOptions();
int getSecondaryOptions();
void setFirstOptions(int);
void setSecondOptions(int);
void Display_FirstOptions();
void Input_FirstOptions();
void Input_SecondOptions();
void Check_First_Options();
void Display_SecondOptions();
void Check_Second_Options();
};
Engine::Engine():Database("database.txt")
{
FirstOptions=0;
SecondOptions=0;
}
int Engine::getFirstOptions()
{
return FirstOptions;
}
int Engine::getSecondaryOptions()
{
return SecondOptions;
}
void Engine::setFirstOptions(int a)
{
FirstOptions=a;
}
void Engine::setSecondOptions(int b)
{
SecondOptions=b;
}
void Engine::Display_FirstOptions()
{
cout << "Welcome! "<<endl;
cout << "1- LOGIN TO YOUR CURRENT ACCOUNT. "<<endl;
cout << "2- Create Your New Account. "<<endl;
cout <<"3- Exit."<<endl;
Input_FirstOptions();
//now storing the cash in the atm
setNoOf_20_Bills(500);
setRemaining_Ammount(NoOf_20_Bills*20);
Check_First_Options();
}
void Engine::Input_FirstOptions()
{
cout << "Choose from the above Options: "<<endl;
cin>>FirstOptions;
}
void Engine::Check_First_Options()
{
if (FirstOptions==1)
{
Input_Account_Number();
Input_Pin();
if (FileSearch())
{
Display_SecondOptions();
}
else if (!FileSearch())
{
Display_FirstOptions();
}
}
else if (FirstOptions==2)
{
int tempB;
float temp2;
srand(time(0));
long long int temp;
temp=10000+(rand()%99999+1);
setAccount_Number(to_string(temp));
cout << "Your Randomnly Generated Account number is : "<<getAccount_Number()<<endl;
Input_Pin();
Input_UserIfo();
myFile.open(File_NAME,ios::app);
do
{
cout << "Enter The ammount you want to deposit in Your Bank Account(Non-Negative in Cents) : "<<endl;
cin>>tempB;
}while (tempB<0);
//now we have to convert this into dollars
temp2=tempB/100.0;
//now setting the balance
setBalance(to_string(temp2));
//calling the Function to write into the class
FileWrite();
FileWriteNewAccountUserInfo();
}
else if (FirstOptions==3)
{
cout << "Thank You For Visiting."<<endl;
}
else
{
cout << "You have entered Worng Option: "<<endl;
cout << "Choose From 1-3."<<endl;
Display_FirstOptions();
}
}
void Engine::Display_SecondOptions()
{
cout << "Welcome to the main Menue: "<<endl;
cout << "1- View My Balance. "<<endl;
cout << "2- WithDraw Cash. "<<endl;
cout << "3- Deposit Funds. "<<endl;
cout << "4- Exit."<<endl;
Input_SecondOptions();
Check_Second_Options();
}
void Engine::Input_SecondOptions()
{
do{
cout << "Enter your choice. "<<endl;
cin>>SecondOptions;
}while (SecondOptions>5 || SecondOptions <=0);
}
void Engine::Check_Second_Options()
{
switch(SecondOptions)
{
case 1:
cout << "Your Current Balance is: "<<Balance<<endl;
break;
//for withdrawa Options
case 2:
InputAgain:
double temp;
Display_Options();
if (atm_Options==1)
{
if (stof(Balance)>=20)
{
temp=stoi(Balance)-20;
setNoOf_20_Bills(getNoOf_20_Bills()-1);
setRemaining_Ammount(getRemaining_Ammount()-20);
cout <<getNoOf_20_Bills()<<endl;
cout << getRemaining_Ammount()<<endl;
Balance=to_string(temp);
UpdateBalance();
cout << "Transaction Succssful!"<<endl;
cout << "Thanks For Comming. "<<endl;
}
else
{
cout << "Your Balance is Less than the ammount you want to debit."<<endl;
cout << "Your Current Balance IS: "<<getBalance()<<endl;
goto InputAgain;
}
}
else if(atm_Options==2)
{
if (stof(Balance)>=40)
{
temp=stof(Balance)-40;
setNoOf_20_Bills(getNoOf_20_Bills()-2);
setRemaining_Ammount(getRemaining_Ammount()-40);
Balance=to_string(temp);
UpdateBalance();
cout << "Transaction Succssful!"<<endl;
cout << "Thanks For Comming. "<<endl;
}
else
{
cout << "Your Balance is Less than the ammount you want to debit."<<endl;
cout << "Your Current Balance IS: "<<getBalance()<<endl;
goto InputAgain;
}
}
else if(atm_Options==3)
{
if (stof(Balance)>60)
{
temp=stof(Balance)-60;
setNoOf_20_Bills(getNoOf_20_Bills()-3);
setRemaining_Ammount(getRemaining_Ammount()-60);
Balance=to_string(temp);
UpdateBalance();
cout << "Transaction Succssful!"<<endl;
cout << "Thanks For Comming. "<<endl;
}
else
{
cout << "Your Balance is Less than the ammount you want to debit."<<endl;
cout << "Your Current Balance IS: "<<getBalance()<<endl;
goto InputAgain;
}
}
else if (atm_Options==4)
{
if (stof(Balance)>100)
{
temp=stof(Balance)-100;
setNoOf_20_Bills(getNoOf_20_Bills()-5);
setRemaining_Ammount(getRemaining_Ammount()-100);
Balance=to_string(temp);
UpdateBalance();
cout << "Transaction Succssful!"<<endl;
cout << "Thanks For Comming. "<<endl;
}
else
{
cout << "Your Balance is Less than the ammount you want to debit."<<endl;
cout << "Your Current Balance IS: "<<getBalance()<<endl;
goto InputAgain;
}
}
else if (atm_Options==5)
{
if (stof(Balance)>200)
{
cout << getRemaining_Ammount()<<endl;
cout << getNoOf_20_Bills()<<endl;
temp=stof(Balance)-200;
setNoOf_20_Bills(getNoOf_20_Bills()-10);
setRemaining_Ammount(getRemaining_Ammount()-200);
Balance=to_string(temp);
UpdateBalance();
cout << "Transaction Succssful!"<<endl;
cout << "Thanks For Comming. "<<endl;
}
else
{
cout << "Your Balance is Less than the ammount you want to debit."<<endl;
cout << "Your Current Balance IS: "<<getBalance()<<endl;
goto InputAgain;
}
}
else if(atm_Options==6)
{
Display_SecondOptions();
}
break;
//now if the user wants to deposit dunds the money
case 3:
int temp_cash;
double convertedIntoDollars;
cout << "If You Want to Go Back, Press Zero: "<<endl;
do{
cout << "Enter the ammount You want to deposit in your bank account: "<<endl;
cin>>temp_cash;
}while(temp_cash<0);
if (temp_cash==0)
{
cout << "You Have Pressed Zero therefore, Taking you back."<<endl;
Display_FirstOptions();
}
//now converitng the cents inot dollars
cout << "Your Entered Ammount is (Ignoring the Decimal Point): "<<temp_cash<<endl;
convertedIntoDollars=(temp_cash/100.0);
//now storing it into the Account Balance.
setBalance(to_string(convertedIntoDollars+stof(getBalance())));
//now updating the balance in the database
UpdateBalance();
cout << "Your New Balnace Is : "<<getBalance()<<endl;
cout << "Thank You For Visisting. "<<endl;
break;
case 4:
cout << "Exiting..."<<endl;
Display_FirstOptions();
break;
default:
cout << "You have Entered Wrong Option."<<endl;
cout << "Enter Agaian: "<<endl;
Input_SecondOptions();
}
}