-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.cpp
274 lines (257 loc) · 10.9 KB
/
main.cpp
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
// *******************************************************************
// main.cpp (Hauptprogamm zum Bank-Beispiel)
// *******************************************************************
#include <iostream>
#include <string>
#include <cfloat>
#include "Observer.h"
#include "bank.h"
using namespace std;
// *******************************************************************
string stringInput(string message) {
string line;
cout << message << endl;
getline(cin, line);
return line;
}
int intInput(string message, long long int minLimit = LONG_LONG_MIN, long long int maxLimit = LONG_LONG_MAX) {
std::string line;
int num = 0;
//split onto multiple lines for readability
std::cout << message << endl;
while (!(std::istringstream{line} >> num)
&& (num <= minLimit || num >= maxLimit)
&& std::getline(std::cin, line)
) {
std::istringstream is{line};
if ((is >> num) && !(is >> line) && (num >= minLimit && num <= maxLimit)) {
return num;
}
std::cerr << "Invalid input, try again." << std::endl;
}
return 0;
}
// *******************************************************************
float floatInput(string message, float minLimit = FLT_MIN, float maxLimit = FLT_MAX) {
std::string line;
float num = 0;
//split onto multiple lines for readability
std::cout << message << endl;
while (!(std::istringstream{line} >> num)
&& (num <= minLimit || num >= maxLimit)
&& std::getline(std::cin, line)
) {
std::istringstream is{line};
if ((is >> num) && !(is >> line) && (num >= minLimit && num <= maxLimit)) {
return num;
}
std::cerr << "Invalid input, try again." << std::endl;
}
}
// *******************************************************************
int hauptMenue() {
cout << "\n\n";
cout << "+------------------------+\n";
cout << "| Menu: |\n";
cout << "+------------------------+\n\n";
cout << " (1) Read from file\n";
cout << " (2) Write to file\n";
cout << " (3) Data-Dialog\n";
cout << " (4) PayIn\n";
cout << " (5) Withdraw\n";
cout << " (6) Transfer\n";
cout << " (7) Get statement\n";
cout << " (8) Show users\n";
cout << " (9) Show accounts\n";
cout << " (10) Interest balance\n";
cout << " (11) Get Account Activities\n";
cout << " (12) Toggle autosave\n\n";
cout << " (13) Exit\n";
cout << "------------------------------------------------\n";
int choice;
choice = intInput("Please Choose", 1, 13);
return choice;
}
// *******************************************************************
int stammdatenMenue() {
cout << "\n\n";
cout << "+------------------------+\n";
cout << "| Data menu: |\n";
cout << "+------------------------+\n\n";
cout << " (1) New customer\n";
cout << " (2) Delete customer\n";
cout << " (3) Change customer\n";
cout << " (4) New account\n";
cout << " (5) Delete account\n\n";
cout << " (6) Return\n";
cout << " -----------------------------------------------\n";
int choice;
choice = intInput("Please Choose", 1, 6);
return choice;
}
// *******************************************************************
int main() {
int choice;
bank Bank("DKB");
Observer *obs = new Filesaver("users.dat", "data.dat");
Observer *obs1 = new CountObserver ("count.dat");
do {
choice = hauptMenue();
if (choice == 1) {
Bank.readFromFile("data.dat", "users.dat");
Bank.notifyObservers();
// lesen aus Datei
} else if (choice == 2) {
Bank.writeToFile("data.dat", "users.dat");
Bank.notifyObservers();
// schreiben in Datei
} else if (choice == 3) {
//===========================================================
int choice2;
do {
choice2 = stammdatenMenue();
if (choice2 == 1) {
//new customer
string name;
string street;
string postcode;
int nr;
name = stringInput("please enter the name");
street = stringInput("please enter the street");
nr = intInput("please enter your house number", 0);
postcode = stringInput("please enter the postcode");
Bank.newCustomer(name, Address(street, nr, postcode));
Bank.notifyObservers();
//Bank.newCustomer("Hans", Address("Mullerstr",33,"41065"));
} else if (choice2 == 2) {
//delete customer
int id;
id = intInput("Give the userID to delete the user", 0);
Bank.removeCustomer(id);
Bank.notifyObservers();
} else if (choice2 == 3) {
//change customer
int id;
id = intInput("Give the userID to change the user", 1);
string name;
string street;
string postcode;
int nr;
name = stringInput("please enter the name");
street = stringInput("please enter the street");
nr = intInput("please enter your house number");
postcode = stringInput("please enter the postcode");
Bank.editCustomer(id, name, Address(street, nr, postcode));
Bank.notifyObservers();
} else if (choice2 == 4) {
int id;
int choice3 = 0;
float balance;
id = intInput("Give the userID to Add an account", 1);
balance = floatInput("give starting Balance", 0);
do {
choice3 = intInput("for Giro enter 1, for Savingsaccount 2", 1, 2);
if (choice3 == 1) {
float dispolimit;
dispolimit = floatInput("What is the dispolimit?", 0);
Bank.createGiro(id, balance, dispolimit);
Bank.notifyObservers();
} else if (choice3 == 2) {
Bank.createSavingsAccount(id, balance);
Bank.notifyObservers();
}
} while ((choice3 != 1) && (choice3 != 2));
// final else statement add
} else if (choice2 == 5) {
// delete account
int number;
number = intInput("Please provide the account number to delete", 9000);
Bank.removeAccount(number);
Bank.notifyObservers();
} else if (choice2 != 6) {
cout << "no valid input!\n";
}
} while (choice2 != 6);
//============================================================
} else if (choice == 4) {
float amount;
int accountNr;
int PIN;
accountNr = intInput("Which account you want to payIn? (acountNr)", 9000);
PIN = intInput("Please enter your PIN 4 digits", 0);
while (!(Bank.PinVerification(accountNr, PIN))) {
PIN = intInput("Wrong PIN, please try again \n To exit press 0", 0);
}
amount = floatInput("please enter the amount you want to payIn", 0);
Bank.payIn(accountNr, amount);
// einzahlen
} else if (choice == 5) {
float amount;
int accountNr;
int PIN;
accountNr = intInput("Which account you want to withdrawl from? (acountNr)", 9000);
PIN = intInput("Please enter your PIN 4 digits", 0);
while (!(Bank.PinVerification(accountNr, PIN))) {
PIN = intInput("Wrong PIN, please try again \n To exit press 0", 0);
}
amount = floatInput("please enter the amount you want to withdrawl", 0);
Bank.withdraw(accountNr, amount);// auszahlen
} else if (choice == 6) {
float amount;
int accountNr;
int accountNrTo;
string message;
int PIN;
accountNr = intInput("Which account you want to transfer from? (acountNr)", 9000);
PIN = intInput("Please enter your PIN 4 digits", 0);
while (!(Bank.PinVerification(accountNr, PIN))) {
PIN = intInput("Wrong PIN, please try again \n To exit press 0", 0);
}
accountNrTo = intInput("Which account you want to transfer to? (acountNr)", 9000);
amount = floatInput("please enter the amount you want to transfer", 0);
message = stringInput("please enter a message :");
Bank.transfer(accountNr, accountNrTo, amount, message);
choice = 0;
} else if (choice == 7) {
int accountNr;
int PIN;
accountNr = intInput("Please give the account number to get your statement", 9000);
PIN = intInput("Please enter your PIN 4 digits", 0);
while (!(Bank.PinVerification(accountNr, PIN))) {
PIN = intInput("Wrong PIN, please try again. Press Escape to leave", 0);
}
cout << Bank.getstatement(accountNr) << endl;// Kontoauszug anzeigen
} else if (choice == 8) {
cout << Bank.customerList() << endl;// Kundenliste anzeigen
} else if (choice == 9) {
// Kontenliste anzeigen
cout << Bank.listOfAccounts() << endl;
} else if (choice == 10) { // Zinsgutschrift
} else if (choice == 11) {
int accountNr;
int PIN;
accountNr = intInput("Please give the account number to get your activities", 9000);
PIN = intInput("Please enter your PIN 4 digits", 0);
while (!(Bank.PinVerification(accountNr, PIN))) {
PIN = intInput("Wrong PIN, please try again. Press Escape to leave", 0);
}
cout << Bank.getAction(accountNr) << endl;
//get account activities
} else if (choice == 0) {
} else if (choice == 12) {
bool save = intInput("For turning on autosave press (1) for switching off (0)",0,1);
if(save){
Bank.logInObserver(obs);
Bank.logInObserver(obs1);
cout<<"Autosave is on";
}
else{
Bank.logOutObserver(obs);
cout<<"Autosave was switched off"<<endl;
}
} else if (choice != 13) {
cout << "no valid input!\n";
}
} while (choice != 13);
//Bank.writeToFile("data.dat", "users.dat");
}