-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
148 lines (118 loc) · 2.79 KB
/
Copy pathmain.cpp
File metadata and controls
148 lines (118 loc) · 2.79 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
#include <stdio.h>
#include <stdlib.h>
#include <string>
#include <vector>
#include <iostream>
#include <windows.h>
#include <unordered_map>
#include <thread>
#include <chrono>
#define Color_Red "\33[0:31m\\]" // Color Start
#define Color_end "\33[0m\\]" // To flush out prev settings
#define LOG_RED(X) printf("%s %s %s",Color_Red,X,Color_end)
using namespace std;
struct Bank{
private:
vector<string> v;
unordered_map<string, int> money;
void add_pos(string element){
v.push_back(element);
money[element] = 100;
}
void del_pos(string element){
int i;
i=0;
while(i<(int)v.size()&&v[i]!=element){
i++;
}
if (i<(int)v.size()) {
swap(v[i], v.back());
v.pop_back();
}
}
string get(string type){
if(type=="name"){
return v.back();
}else if(type=="money"){
return to_string(money[v.back()]);
}
return "error";
}
public:
string username;
void registerAccount(){
printf("Please enter Username: ");
cin >> username;
add_pos(username);
}
void remAccount(){
printf("Please enter Username: ");
cin >> username;
del_pos(username);
}
void infoAccount(){
if(v.size()>0){
cout << "\nName: ";
cout << get("name");
cout << "\nBalance: ";
cout << ((get("money")=="error")?"Error: No money var found!":get("money"));
cout << "\n";
}else{
system("color 4");
cout << "Error: no account created.";
while(!(GetKeyState(VK_SPACE) & 0x8000));
system("cls");
system("color 7");
}
}
void deposite(){
int amount;
printf("Pleas Enter amount: ");
cin >> amount;
money[v.back()]+=amount;
}
void withdraw(){
int amount;
printf("Pleas Enter amount: ");
cin >> amount;
if(money[v.back()]<amount){
system("cls");
system("color 4");
cout << "Error: not enough money.";
while(!(GetKeyState(VK_SPACE) & 0x8000));
system("cls");
system("color 7");
}
money[v.back()]-=amount;
}
void printAccount() {
for(auto i : v){
cout << (i+=" ");
}
cout << "\n";
}
};
int main() {
int command;
Bank bank;
do {
printf("Insert command: ");
scanf("%d", &command);
if (command == 1){
bank.registerAccount();
}else if (command == 2){
bank.remAccount();
}else if(command == 3){
bank.infoAccount();
printf("\nPress \"Space\" to continue.");
while(!(GetKeyState(VK_SPACE) & 0x8000));
}else if(command == 4){
bank.deposite();
}else if(command == 5){
bank.withdraw();
}
system("cls");
//bank.printAccount();
} while (command != 6);
return 0;
}