-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
70 lines (69 loc) · 3.17 KB
/
main.cpp
File metadata and controls
70 lines (69 loc) · 3.17 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
#include <iostream>
#include <unordered_map>
#include "TokenScanner.h"
int main() {
std::string token;
AccountSystem accountSystem;
BookSystem bookSystem;
LogSystem logSystem;
while (getline(std::cin, token)) {
try {
std::string order;
TokenScanner scanner(token);
order = scanner.nextToken();
if (order.empty()) {
} else if (order == "quit") {
if (!scanner.hasMore) break;
else throw std::string("Invalid\n");
} else if (order == "exit") {
if (!scanner.hasMore) break;
else throw std::string("Invalid\n");
} else if (order == "su") {
scanner.su(accountSystem, logSystem);
} else if (order == "logout") {
if (!scanner.hasMore) scanner.logout(accountSystem, logSystem);
else throw std::string("Invalid\n");
} else if (order == "register") {
scanner.register_(accountSystem, logSystem);
} else if (order == "passwd") {
scanner.passwd(accountSystem, logSystem);
} else if (order == "useradd") {
scanner.useradd(accountSystem, logSystem);
} else if (order == "delete") {
scanner.delete_(accountSystem, logSystem);
} else if (order == "buy") {
if (accountSystem.login_stack.empty()) throw std::string("Invalid\n");
scanner.buy(accountSystem, bookSystem, logSystem);
} else if (order == "select") {
if (accountSystem.login_stack.empty()) throw std::string("Invalid\n");
scanner.select(accountSystem, bookSystem, logSystem);
} else if (order == "modify") {
if (accountSystem.login_stack.empty()) throw std::string("Invalid\n");
scanner.modify(accountSystem, bookSystem, logSystem);
} else if (order == "import") {
if (accountSystem.login_stack.empty()) throw std::string("Invalid\n");
scanner.import(accountSystem, bookSystem, logSystem);
} else if (order == "log") {
if (accountSystem.login_stack.empty()) throw std::string("Invalid\n");
logSystem.showLog();
} else if (order == "show") {
int point_ = scanner.point;
order = scanner.nextToken();
if (order == "finance") { // show finance
if (accountSystem.login_stack.empty()) throw std::string("Invalid\n");
scanner.show_finance(accountSystem, logSystem);
} else { // show in bookSystem
scanner.point = point_;
scanner.hasMore = true;
if (accountSystem.login_stack.empty()) throw std::string("Invalid\n");
scanner.show(accountSystem, bookSystem, logSystem);
}
} else {
throw std::string("Invalid\n");
}
}
catch (std::string error_out) {
std::cout << error_out;
}
}
}