-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTestSystem.cpp
More file actions
225 lines (205 loc) · 5.45 KB
/
TestSystem.cpp
File metadata and controls
225 lines (205 loc) · 5.45 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
#include"TestSystem.h"
using namespace std;
void test_system()
{
cout << "欢迎使用本系统";
chrono::system_clock::time_point now = *get_Now() + 30 * chrono::hours(24);
time_display(now);
cout << endl;
//生成测试Book对象结构体
InitBookStruct booklist {};
/*
10004,
"语文",
{"张三","张二"},
"教育出版社",
20,
0,
1
*/
booklist.ID = 10004;
booklist.Title = "语文";
booklist.Author = { "张三","张二" };
booklist.Press = "教育出版社";
booklist.Price = 20;
booklist.Status = 0;
booklist.BorrowStatus = 1;
vector<string> book_title = { "语文","数学","英语","物理","化学","生物","历史","政治","地理" };
//生成测试Person对象结构体
InitPersonStruct personlist;
personlist.ID = 10001;
personlist.Name = "张";
personlist.Age = 18;
personlist.Gender = Man;
personlist.PhoneNumber = 1234567890;
personlist.Type = StudentType;
personlist.BooksID = {};
personlist.BorrowedNumber = 0;
booklist.BorrowerID = 10001;
Book Book1(booklist);
//生成若干读者
vector<Person> Persons;
//生成编号唯一的书
vector<Book> Books;
size_t j = 0;
for (size_t i = 0; i < 20; i++)
{
booklist.ID++;
personlist.ID++;
personlist.Name = "张" + to_string(i);
booklist.Title = book_title[j++];
if (j == 8)
{
j = 0;
}
Book* p_temp_book = new Book(booklist);
Books.push_back(*p_temp_book);
delete(p_temp_book);
Person* p_temp_person = new Person(personlist);
Persons.push_back(*p_temp_person);
delete(p_temp_person);
}
cout << "以下为测试书籍显示函数" << endl;
//测试展示函数
display_book_title();
for (Book temp_book : Books)
{
temp_book.display();
}
cout << "以下为测试读者信息显示函数" << endl;
display_person_title();
for (Person temp_person : Persons)
{
temp_person.display();
temp_person.display_all_books(Books);
}
cout << "以下为测试借书函数" << endl;
//测试借书函数
size_t i = 0;
for (Person& temp_person : Persons)
{
temp_person.borrow(Books[i++]);
if (i == 8)
{
i = 0;
}
}
cout << "以下为测试书籍显示函数" << endl;
//测试展示函数
display_book_title();
for (Book temp_book : Books)
{
temp_book.display();
}
cout << "以下为测试读者信息显示函数" << endl;
display_person_title();
for (Person temp_person : Persons)
{
temp_person.display();
temp_person.display_all_books(Books);
}
cout << "以下为测试还书函数" << endl;
for (Book& temp_book : Books)
{
for (Person& temp_person : Persons)
{
temp_person.return_book(temp_book);
}
//temp_book.return_book();
//temp_book.display();
}
cout << "以下为测试书籍显示函数" << endl;
//测试展示函数
display_book_title();
for (Book temp_book : Books)
{
temp_book.display();
}
cout << "以下为测试借书函数" << endl;
//测试借书函数
for (Person& temp_person : Persons)
{
temp_person.borrow(Books[i++]);
if (i == 8)
{
i = 0;
}
}
cout << "以下为测试书籍显示函数" << endl;
//测试展示函数
display_book_title();
for (Book temp_book : Books)
{
temp_book.display();
}
//测试文件保存
person_file_save(Persons);
book_file_save(Books);
//system("Book.txt");
//测试文件读取
//生成编号唯一的书
vector<Person>person_read_test;
person_file_read(person_read_test);
personlist.Name = "王展鹏";
person_read_test.push_back(Person(personlist));
person_file_save(person_read_test);
system("Person.txt");
vector<Book>book_read_test;
book_file_read(book_read_test);
booklist.Title = "儒林外史";
book_read_test.push_back(Book(booklist));
//测试建立关系
for (Book& temp_book : book_read_test)
{
temp_book.BulidRelationship(person_read_test);
}
cout << "以下为测试书籍显示函数" << endl;
//测试展示函数
display_book_title();
for (Book temp_book : book_read_test)
{
temp_book.display();
}
book_file_save(book_read_test);
system("Book.txt");
//二次测试读与写
//生成编号唯一的书
vector<Person>person_read_test_2;
person_file_read(person_read_test_2);
personlist.Name = "王展鹏";
personlist.ID = 3242;
person_read_test_2.push_back(Person(personlist));
person_file_save(person_read_test_2);
system("Person.txt");
system("pause");
//cout << "以下为测试修改函数" << endl;
//cout << "以下为测试读者信息显示函数" << endl;
//display_person_title();
//for (Person temp_person : Persons)
//{
// temp_person.display();
// temp_person.display_all_books(Books);
//}
//cout << "以下为测试读者信息显示函数" << endl;
//display_person_title();
//for (Person temp_person : Persons)
//{
// temp_person.modify();
// temp_person.display();
// temp_person.display_all_books(Books);
//}
//
}
void mov_data_from_person_to_user()
{
extern vector<Person> Borrowers;
extern vector<User> Users;
Init_User User_Init;
for (Person &temp_person : Borrowers)
{
User_Init.id = temp_person.ID;
User_Init.name = temp_person.Name;
User_Init.password = "123456";
Users.push_back(User_Init);
}
}