-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmy_functions.cpp
More file actions
267 lines (203 loc) · 5.03 KB
/
my_functions.cpp
File metadata and controls
267 lines (203 loc) · 5.03 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
string date_time(){
auto now = chrono::system_clock::now();
time_t currentTime = chrono::system_clock::to_time_t(now);
tm localTime{};
#ifdef _WIN32
localtime_s(&localTime, ¤tTime);
#else
localtime_r(¤tTime, &localTime);
#endif
ostringstream oss;
oss << put_time(&localTime, "%Y-%m-%d %H:%M:%S");
return oss.str();
}
void universal_file(string fname, int accountnum, string password){
fstream myfile;
string bankname = "Dbank_";
string ext = ".txt";
string temp = fname;
//bankname.appenD(fname);
bankname.append(temp);
bankname.append(ext);
myfile.open(temp, ios::out);
myfile << accountnum << endl;
myfile << password << endl;
myfile.close();
}
void user_info(string name){
fstream myfile;
string bankname = "Dbank_";
string ext = ".txt";
string ext2 = "_info.txt";
string bankname2 = "Dbank_";
bankname2.append(name);
bankname2.append(ext);
myfile.open(bankname, ios::in);
string line;
int linenum = 0;
while(getline(myfile, line)){
linenum++;
if(linenum == 1){
myfile.close();
break;
}
}
bankname.append(line);
bankname.append(ext2);
myfile.open(bankname, ios::in);
while(getline(myfile, line)){
linenum++;
if(linenum == 2){
cout << "loading...." << endl;
break;
}
}
myfile.close();
bankname.append(line);
bankname.append(ext);
myfile.open(bankname);
while(getline(myfile, line)){
cout << line << endl;
}
}
void acc_balance(string name){
fstream myfile;
string line;
string ext = ".txt"
string bankname = "Dbank_";
string ext2 = "_balance.txt";
int balance;
string temp = bankname;
name.append(ext);
// string passw;
// cout << "Enter your password: ";
// cin >> passw;
myfile.open(name, ios::in);
int linecount = 0;
while(getline(myfile, line)){
linecount++;
if(linecount == 1){
myfile.close();
break;
}
}
bankname.append(line);
bankname.append(ext2);
myfile.open(bankname, ios::in);
while(getline(myfile, line)){
cout << line << endl;
}
cout << "\n";
cout << ".......................................";
}
void transfer(int r_acc_num, int amount, string s_name){
fstream myfile;
string ext = "_balance.txt";
string bankname = "Dbank_";
string line;
int linenum = 0;
long new_balance;
bankname.append(acc_num);
bankname.append(ext);
myfile.open(bankname, ios::out);
while(getline(myfile, line)){
new_balance = stol(line);
}
myfile.close();
new_balance = new_balance + amount;
myfile.open(bankname, ios::in);
myfile << new_balance << endl;
myfile.close();
update_history(s_acc_num, r_acc_num, amount);
}
void update_history(string s_a_n, string r_a_n, string ampunt){
fstream myfile;
string ext = "history.txt";
string bankname = "Dbank";
string temp = bankname;
string dt = date_time();
bankname.append(s_a_n);
bankname.append(ext);
myfile.open(bankname, ios::app);
myfile << "History: Account was Debited." << endl;
myfile << "Amount = " << amount << endl;
myfile << "Date & Time: " << dt << endl;
myfile << ".........." << endl;
myfile.close();
temp.append(r_a_n);
temp.append(ext);
myfile.open(temp, ios::app);
myfile << "History: Account was Credited." << endl;
myfile << "Amount = " << amount << endl;
myfile << "Date & Time: " << dt << endl;
myfile << ".........." << endl;
myfile.close();
}
void confirm_exit(){
cout << "Do you want to exit?\n\t1. Yes\n\t2. No\n";
int ans;
while(cin >> ans){
if(ans == 1){
cout << "Bye-bye\n";
cout << "..............................................................................\n";
exit(0);
}
if(ans == 2){
login();
}
cout << "Invalid options\n";
}
}
class check_input{
private:
string input;
public:
void assign(string inp){input = inp;}
bool check(){
for(int i = 0; i < input.size(); i++){
if(!isdigit(input[i])){
return false;
}
}
return true;
}
}
void take_password(){
cout << "Enter your Transaction pin: ";
string pin;
cin >> pin;
check_input Pin;
Pin.assign(pin);
bool check_correct = Pin.check();
if(check_correct == false){
cout << "Incorrect Password\n";
return false;
}
return true;
}
Sleep(5000);
FlushConsoleInputBuffer(GetStdHandle(STD_INPUT_HANDLE));
#ifdef _WIN32
#include <windows.h>
#endif
// Enable ANSI escape codes on Windows 10+
void enableVTMode() {
#ifdef _WIN32
HANDLE hOut = GetStdHandle(STD_OUTPUT_HANDLE);
if (hOut == INVALID_HANDLE_VALUE) return;
DWORD dwMode = 0;
if (!GetConsoleMode(hOut, &dwMode)) return;
dwMode |= ENABLE_VIRTUAL_TERMINAL_PROCESSING;
SetConsoleMode(hOut, dwMode);
#endif
}
// Deletes the typed input after Enter, keeping prompt intact
void clearUserInputOnly() {
// Move cursor up, go to end of prompt, clear from there
std::cout << "\x1b[1A" // Move cursor up one line
<< "\x1b[s" // Save cursor position
<< "\x1b[999C" // Move far right (max columns)
<< "\x1b[1K" // Clear from cursor to start of line
<< "\x1b[u"; // Restore cursor to saved position
std::cout.flush();
}