-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathborrowAndReturnBookMenu.cpp
More file actions
332 lines (291 loc) · 6.67 KB
/
borrowAndReturnBookMenu.cpp
File metadata and controls
332 lines (291 loc) · 6.67 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
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
#include "borrowAndReturnBookMenu.h"
#include"User.h"
#include"Admin.h"
extern User* present_user;
extern Person* present_borrower;
extern Admin* present_admin;
extern vector<Admin> Admins;
extern vector<User> Users;
extern vector<Person>Borrowers;
extern vector<Book> Books;
/// <summary>
/// 1.借书的二级菜单
/// </summary>
/// <param name="Borrowers"></param>
/// <param name="Books"></param>
void borrowAndReturnBook_Menu(vector<Person>& Borrowers, vector<Book>& Books)
{
int nMainchoose;
//主菜单无限循环
while (1)
{
system("CLS"); //系统屏幕清空
//输出菜单主界面
printf("\t\t------------------------------\n");
printf("\t\t|********借书还书模块********|\n");
printf("\t\t| |\n");
printf("\t\t| 1.借阅图书 |\n");
printf("\t\t| |\n");
printf("\t\t| 2.归还图书 |\n");
printf("\t\t| |\n");
printf("\t\t| 0.返回上级菜单 |\n");
printf("\t\t| |\n");
printf("\t\t------------------------------ \n");
printf("\t\t 请选择功能序号:");
//用户根据界面提示输入数字
cin >> nMainchoose;
system("CLS");
//根据用户输入的数字看如何行动
switch (nMainchoose)
{
//转到借书函数
case 1:
borrowBook(Borrowers, Books);
system("PAUSE");
break;
//转到还书函数
case 2:
returnBook(Borrowers, Books);
system("PAUSE");
break;
//转到二级菜单:书库维护菜单选项显示
case 3:
break;
case 0:
return;
break;
//用户选择有误
default:
printf("选择有误,请重选!\n");
}//switch结束
}//while(1)函数结束
}
void borrowAndReturnBook_Menu()
{
int nMainchoose;
//主菜单无限循环
while (1)
{
system("CLS"); //系统屏幕清空
//输出菜单主界面
printf("\t\t------------------------------\n");
printf("\t\t|********借书还书模块********|\n");
printf("\t\t| |\n");
printf("\t\t| 1.借阅图书 |\n");
printf("\t\t| |\n");
printf("\t\t| 2.归还图书 |\n");
printf("\t\t| |\n");
printf("\t\t| 0.返回上级菜单 |\n");
printf("\t\t| |\n");
printf("\t\t------------------------------ \n");
printf("\t\t 请选择功能序号:");
//用户根据界面提示输入数字
cin >> nMainchoose;
system("CLS");
//根据用户输入的数字看如何行动
switch (nMainchoose)
{
//转到借书函数
case 1:
borrowBook();
system("PAUSE");
break;
//转到还书函数
case 2:
Book::Return_a_Book();
system("PAUSE");
break;
//转到二级菜单:书库维护菜单选项显示
case 3:
break;
case 0:
return;
break;
//用户选择有误
default:
printf("选择有误,请重选!\n");
}//switch结束
}//while(1)函数结束
}
int searchPerson(vector<Person>& Borrowers, int ID)
{
int n = 0;
for (Person& temp_Person : Borrowers)
{
if (ID == temp_Person.ID)
{
return n;//找到返回编号
}
n++;
}
return -1;//没有找到返回-1
}
/// <summary>
/// 1.1借书函数
/// </summary>
/// <param name="Borrowers"></param>
/// <param name="Books"></param>
void borrowBook(vector<Person>& Borrowers, vector<Book>& Books)
{
cout << " 当前为借书模块 " << endl;
int temp_ID;//暂存ID
int temp_BookID;
int temp_Number;//序号
bool searchStatus = false;
cout << "请输入用户ID:";
cin >> temp_ID;
//得到当前的序号
temp_Number = searchPerson(Borrowers, temp_ID);
if (temp_Number >= 0)
{
display_person_title();//显示表头
Borrowers[temp_Number].display();//显示信息
cout << "请检查信息是否正确" << endl;
cout << "请输入要借书的ID:";
cin >> temp_BookID;
//检查当前书的ID是否可以找到
for (Book& temp_book : Books)
{
if (temp_book.searchBookID(temp_BookID))
{
searchStatus = true;
Borrowers[temp_Number].borrow(temp_book);
//显示当前的信息
cout << "请检查以下信息是否正确" << endl;
display_book_title();
temp_book.display();
display_person_title();
Borrowers[temp_Number].display();
Borrowers[temp_Number].display_all_books(Books);
break;
}
}
//找到了书
if (searchStatus == true)
{
}
//没有找到
else
{
cout << "没有找到对应书ID,请重试" << endl;
}
}
//没有找到ID
else
{
cout << "没有找到对应ID,请重试" << endl;
}
}
void borrowBook()
{
cout << " 当前为借书模块 " << endl;
int temp_ID;//暂存ID
int temp_BookID;
int temp_Number;//序号
bool searchStatus = false;
temp_ID = (*present_borrower).ID;
//得到当前的序号
temp_Number = searchPerson(Borrowers, temp_ID);
if (temp_Number >=0)
{
display_person_title();//显示表头
Borrowers[temp_Number].display();//显示信息
cout << "请检查信息是否正确" << endl;
cout << "请输入要借书的ID:";
cin >> temp_BookID;
//检查当前书的ID是否可以找到
for (Book& temp_book : Books)
{
if (temp_book.searchBookID(temp_BookID))
{
searchStatus = true;
Borrowers[temp_Number].borrow(temp_book);
//显示当前的信息
cout << "请检查以下信息是否正确" << endl;
display_book_title();
temp_book.display();
display_person_title();
Borrowers[temp_Number].display();
Borrowers[temp_Number].display_all_books(Books);
break;
}
}
//找到了书
if (searchStatus == true)
{
}
//没有找到
else
{
cout << "没有找到对应书ID,请重试" << endl;
}
}
//没有找到ID
else
{
cout << "没有找到对应ID,请重试" << endl;
}
}
/// <summary>
/// 1.2总体还书函数
/// </summary>
/// <param name="Borrowers"></param>
/// <param name="Books"></param>
void returnBook(vector<Person>& Borrowers, vector<Book>& Books)
{
cout << " 当前为还书模块 " << endl;
int temp_ID;//暂存ID
int temp_BookID;
int temp_Number;//序号
bool searchStatus = false;
cout << "请输入用户ID:";
cin >> temp_ID;
//得到当前的序号
temp_Number = searchPerson(Borrowers, temp_ID);
//如果没有借书直接结束
if (Borrowers[temp_Number].BooksID.size() == 0)
{
cout << "当前没有借书" << endl;
return;
}
if (temp_Number >= 0)
{
display_person_title();//显示表头
Borrowers[temp_Number].display();//显示信息
Borrowers[temp_Number].display_all_books(Books);
cout << "请检查信息是否正确" << endl;
cout << "请输入要还书的ID:";
cin >> temp_BookID;
//检查当前书的ID是否可以找到
for (Book& temp_book : Books)
{
if (temp_book.searchBookID(temp_BookID))
{
searchStatus = true;
Borrowers[temp_Number].return_book(temp_book);
//显示当前的信息
cout << "请检查以下信息是否正确" << endl;
display_book_title();
temp_book.display();
display_person_title();
Borrowers[temp_Number].display();
Borrowers[temp_Number].display_all_books(Books);
break;
}
}
//找到了书
if (searchStatus == true)
{
}
//没有找到
else
{
cout << "没有找到对应书ID,请重试" << endl;
}
}
//没有找到ID
else
{
cout << "没有找到对应ID,请重试" << endl;
}
}