forked from Rustam-Z/cpp-programming
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathHeader.h
More file actions
249 lines (230 loc) · 13.2 KB
/
Copy pathHeader.h
File metadata and controls
249 lines (230 loc) · 13.2 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
#pragma once
#include<iostream>
#include<fstream>
#include<stdlib.h>
#include<string>
#include <vector>
#include <windows.h>
#include <ctime>
#include <conio.h>
using namespace std;
int accountNum, increaments;
long double balance = 0;
long double available;
long double borrow = 0;
struct accounts {
string name;
string password;
double balance;
double borrowed;
};
//function declaring//////////////////////////////////////////
void CheckBalance();
void Borrow();
void Deposit();
void Return();
void Menu(accounts oldData[]);
void MainMenu();
void outData(accounts oldData[]);
void inputNewData(accounts data);
void inputUpgradeData(accounts data[]);
///////////////////////////////////////////////////////////////
//function defintion///////////////////////////////////////////
void Menu(accounts oldData[]) {
char num = '1';
while (num != '0')
{
system("CLS");
cout << "\n 1.Deposit" << endl;
cout << "\n 2.Borrow money from bank" << endl;
cout << "\n 3.Return money to bank" << endl << endl;
cout << "\n If you want to quit from this section please press 0" << endl << endl;
num = _getch();
switch (num) {
case 49:
system("CLS");
Deposit();
oldData[accountNum].balance = ::balance;
inputUpgradeData(oldData);
break;
case 50:
system("CLS");
Borrow();
oldData[accountNum].balance = ::balance;
oldData[accountNum].borrowed = ::borrow;
inputUpgradeData(oldData);
break;
case 51:
system("CLS");
Return();
oldData[accountNum].balance = ::balance;
oldData[accountNum].borrowed = ::borrow;
inputUpgradeData(oldData);
break;
}
}
cout << "\n ";
}
void CheckBalance() {
system("CLS");
cout << "\n You balance: " << ::balance << "$" << endl << endl;
cout << "\n ";
system("pause");
}
void Deposit()
{
double money;
cout << "\n Please enter amount of money - ";
cin >> money;
if (money == 0)
{
cout << "\n You entered 0 value so now you are redirected to the menu" << endl;
Sleep(2000);
}
else if (money > 0)
{
::balance = ::balance + money;
cout << "\n Please wait for a while, while we are transfering money to your account" << endl;
Sleep(2000);
cout << "\n ";
cout << money << "$ amount of money was added to your balance" << endl << endl;
}
else
{
cout << "\n Error!" << endl;
cout << "\n Please enter valid amount of money!" << endl << endl;
}
cout << "\n ";
system("pause");
}
void Borrow()
{
long double borrow;
cout << "\n In during time in our bank we have " << ::available << "$" << endl;
cout << "\n How much do you want to borrow?" << endl;
cout << "\n ";
cin >> borrow;
if (borrow == 0)
{
cout << "\n You entered 0 value so now you are redirected to the menu" << endl << endl;
Sleep(2000);
}
else if (borrow <= ::available && borrow > 0)
{
cout << "\n We can give you such amount of money." << endl;
cout << "\n Please wait for a while, while we are transfering money to your account" << endl;
Sleep(3000);
::available = ::available - borrow;
::balance = ::balance + borrow;
::borrow = ::borrow + borrow;
cout << "\n Money is successfully transfered to your account." << endl << endl;
}
else if (::borrow < 0)
{
cout << "\n Error!" << endl;
cout << "\n Please enter valid amount of money!" << endl << endl;
}
else {
cout << "\n We are sorry but we cant give you such amount of money" << endl << endl;
}
cout << "\n ";
system("pause");
}
void Return()
{
char choise;
long double retr;
if (::borrow > 0) {
cout << "\n You have borrowed - " << ::borrow << "$" << endl;
cout << "\n If you want to return some amount of money please press SPACE or press anything to go back to menu." << endl;
choise = _getch();
if (choise == 32) {
cout << "\n How much do you want to return?" << endl;
cout << "\n ";
cin >> retr;
if (retr == 0)
{
cout << "\n You entered 0 value so now you are redirected to the menu" << endl;
Sleep(2000);
}
else if (retr > 0 && retr <= ::borrow) {
cout << "\n Please wait while we are taking from your account money back." << endl;
::borrow = ::borrow - retr;
::balance = ::balance - retr;
::available = ::available + retr;
Sleep(3000);
cout << "\n Money is successfully taken from your account." << endl << endl;
}
else
{
cout << "\n Error!" << endl;
cout << "\n Please enter valid amount of money!" << endl << endl;
}
}
}
else {
cout << "\n You haven't borrowed any money from us." << endl << endl;
}
cout << "\n ";
system("pause");
}
void outData(accounts oldData[]) {
ifstream file;
file.open("data.txt");
if (!file.is_open()) {
cout << "Error\n";
}
else {
//cout << "file is opened\n";
string str = "";
int i = 0, j = 0;
string strArr[4];
do {
getline(file, str, '|');
if (j < 4) {
strArr[j] = str;
j++;
}
else {
oldData[i].name = strArr[0];
oldData[i].password = strArr[1];
oldData[i].balance = stoi(strArr[2]);
oldData[i].borrowed = stoi(strArr[3]);
::increaments++;
j = 0;
strArr[j] = str;
j++;
i++;
}
//cout<<str<<"|";
}while (!file.eof());
}
}
void inputNewData(accounts data) {
ofstream file;
file.open("data.txt", ofstream::app);
file << data.name;
file << "|";
file << data.password;
file << "|";
file << data.balance;
file << "|";
file << data.borrowed;
file << "|";
file.close();
}
void inputUpgradeData(accounts data[]) {
ofstream file;
file.open("data.txt");
for (int i = 0; i <::increaments; i++) {
file << data[i].name;
file << "|";
file << data[i].password;
file << "|";
file << data[i].balance;
file << "|";
file << data[i].borrowed;
file << "|";
}
file.close();
}