-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
170 lines (161 loc) · 7.3 KB
/
Copy pathmain.cpp
File metadata and controls
170 lines (161 loc) · 7.3 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
#include "libraryDef.cpp"
#include "materialDef.cpp"
#include <ctime>
#include <iostream>
void signUp (library & lib) {
std::string id;
std::cout << "please enter your id: " << std::endl;
std::cin >> id;
lib.add_new_user(id);
}
int main() {
library lib;
borrower *user = nullptr;
admin admin;
std::string id{};
unsigned int book_id = 0;
std::string book_name{};
char c = 0;
std::string rights{};
int count = 0;
std::string password{};
while (true) {
std::cout << "Library Administration System. \n Please press E to enter your ID and password or press S to sign up." << std::endl;
std::cin >> c;
if (c == 'E'){
std::cout << "Please enter your id below.\n";
std::cin >> id;
if (lib.user_exists(id)) {
//polymorphism
user = search_by_b_id(std::string id);
std::cout << "Welcome " + user->get_name() << std::endl;
if (id[0] == 'S') {
rights = "student";
break;
} else if (id[0] == 'T') {
rights = "staff";
break;
} else if (id == "Admin"){
while (true) {
std::cout << "Please enter admin password." << std::endl;
std::cin >> password;
if (password == "dhiusousou12123") {
rights = "admin";
break;
} else if (count >= 4) {
std::cout << "You have entered incorrect password too many times. For security reasons, the program will end.\n";
return;
} else {
std::cout << "Incorrect password, you have " + std::to_string(4-count) + "chances" << std::endl;
++count;
}
}
}
} else {
std::cout << "ID not found, please press [M] to return to main menu or press [S] to sign up" << std::endl;
std::cin >> c;
if (c == 'S') {
signUp(lib);
} else if (c == 'M') {
break;
}
}
} else if (c == 'S') {
signUp (lib);
} else {
std::cout << "Invalid input." << std::endl;
}
}
if (rights == "student" || rights == "staff"){
while (true) {
std::cout << "Library Administration System.\nMenu: [S] Search [Q] Quit [P] Personal info" << std::endl;
std::cin >> c;
if (c == 'S') {
while (true){
std::cout << "[I] Search by id [N] Search by name" << std::endl;
std::cin >> c;
if (c == 'I'){
std::cout << "Please enter book id" << std::endl;
std::cin >> book_id;
materials *m = lib.search_by_id(book_id);
// print pointer content
// m.print();
}
else if (c == 'N')
{
std::cout << "Please enter book name" << std::endl;
std::cin >> book_name;
materials *m = lib.search_by_name(book_name);
}
else
{
std::cout << "Invalid input" << std::endl;
}
}
} else if (c == 'Q') {
std::cout << "Hope you have a nice day and enjoy your books." << std::endl;
return;
} else if (c == 'P') {
user->borrowed_list();
std::cout << "Return[R] Borrow[B]" << std::endl;
std::cin >> c;
std::cout << "Please enter the book's id" << std::endl;
std::cin >> book_id;
if (c == 'R') {
user->return_book(lib.search_by_id(book_id));
std::cout << (lib.search_by_id(book_id))->get_name() + "has been returned." << std::endl;
} else if (c = 'B') {
user->borrow_book(lib.search_by_id(book_id));
std::cout << (lib.search_by_id(book_id))->get_name() + "has been borrowed." << std::endl;
} else {
std::cout << "Invalid input." << std::endl;
}
} else {
std::cout << "Invalid input.\nMenu: [S] Search [Q] Quit [P] Personal info" << std::endl;
}
}
} else if (rights == "admin") {
while (true) {
std::cout << "Library Administration System.\nMenu: [S] Search [Q] Quit [E] Edit list state" << std::endl;
std::cin >> c;
if (c == 'S') {
while (true){
std::cout << "[I] Search by id [N] Search by name" << std::endl;
std::cin >> c;
if (c == 'I'){
std::cout << "Please enter book id" << std::endl;
std::cin >> book_id;
lib.search_by_id(book_id);
//print
} else if (c == 'N') {
std::cout << "Please enter book name" << std::endl;
std::cin >> book_name;
lib.search_by_name(book_name);
} else {
std::cout << "Invalid input" << std::endl;
}
}
} else if (c == 'Q'){
std::cout << "Hope you have a nice day." << std::endl;
return;
} else if (c == 'E'){
std::cout << "Return[R] Borrow[B]" << std::endl;
std::cin >> c;
std::cout << "Please enter the book's id" << std::endl;
std::cin >> book_id;
if (c == 'R') {
lib.set_state_list_return(lib.search_by_id(book_id));
std::cout << (lib.search_by_id(book_id))->get_name() + "has been returned." << std::endl;
} else if (c == 'B') {
lib.set_state_list_borrow(lib.search_by_id(book_id));
std::cout << (lib.search_by_id(book_id))->get_name() + "has been borrowed." << std::endl;
} else {
std::cout << "Invalid input." << std::endl;
}
} else {
std::cout << "Invalid input.\nMenu: [S] Search [Q] Quit [E] Edit list state" << std::endl;
}
}
}
return 0;
}