|
|
|
@ -49,7 +49,7 @@ void input(Book& b)
|
|
|
|
|
// 打印一本书的信息
|
|
|
|
|
void print(const Book& b)
|
|
|
|
|
{
|
|
|
|
|
cout << "Book " << endl << endl
|
|
|
|
|
cout << endl << "Book " << endl
|
|
|
|
|
<<"**************** id: " << b.id << " ****************" << endl
|
|
|
|
|
<< "**** title: 《 " << b.title << " 》****" << endl
|
|
|
|
|
<< "************** Number: " << b.number << " **************" << endl << endl;
|
|
|
|
@ -84,43 +84,51 @@ bool bookempty()
|
|
|
|
|
// 添加图书
|
|
|
|
|
void DoAddBook()
|
|
|
|
|
{
|
|
|
|
|
if (books.length == 256) cout << "Books full" << endl;
|
|
|
|
|
cout << endl << "Add Book"<< endl<<endl;
|
|
|
|
|
if (books.length == 256) cout << "Books full" << endl;
|
|
|
|
|
else{
|
|
|
|
|
Book book;
|
|
|
|
|
input(book); //输入图书
|
|
|
|
|
books.elem[books.length + 1] = book;
|
|
|
|
|
books.length++;
|
|
|
|
|
print(book);
|
|
|
|
|
cout << "*******Added********" << endl;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 查找图书
|
|
|
|
|
void DoFindBook()
|
|
|
|
|
{
|
|
|
|
|
cout << endl << "Find Book" << endl <<endl;
|
|
|
|
|
cout << endl << "Find Book" << endl;
|
|
|
|
|
if (bookempty()) cout << "Book data empty"<< endl;
|
|
|
|
|
else {
|
|
|
|
|
int id;
|
|
|
|
|
cout << "Enter book ID: ";
|
|
|
|
|
cin >> id;
|
|
|
|
|
|
|
|
|
|
Book book;
|
|
|
|
|
if (find(id) == 0)
|
|
|
|
|
cout << "Not found" << endl;
|
|
|
|
|
{
|
|
|
|
|
cout << "************" << endl;
|
|
|
|
|
cout << "Not found" << endl;
|
|
|
|
|
cout << "************" << endl;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
book = books.elem[find(id)];
|
|
|
|
|
cout << "************" << endl;
|
|
|
|
|
cout << "Found" << endl;
|
|
|
|
|
cout << "************" << endl;
|
|
|
|
|
print(book);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 删除图书
|
|
|
|
|
void DoDeleteBook()
|
|
|
|
|
{
|
|
|
|
|
cout << endl << "Delete Book" << endl << endl;
|
|
|
|
|
cout << endl << "Delete Book" << endl;
|
|
|
|
|
int id;
|
|
|
|
|
cout << "Which book you wanna delelet?"<<endl;
|
|
|
|
|
cout << "Enter book ID: ";
|
|
|
|
|
cin >> id;
|
|
|
|
|
Book e;
|
|
|
|
@ -137,6 +145,7 @@ void DoDeleteBook()
|
|
|
|
|
--books.length;
|
|
|
|
|
cout << "************************" << endl;
|
|
|
|
|
cout << "Deleted" << endl;
|
|
|
|
|
cout << "************************" << endl;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -144,26 +153,25 @@ void DoDeleteBook()
|
|
|
|
|
void DoPrintBook()
|
|
|
|
|
{
|
|
|
|
|
cout << endl << "Print All Books" << endl <<endl;
|
|
|
|
|
int flag = 0;
|
|
|
|
|
int number = 0;
|
|
|
|
|
for (int i = 0; i < books.length; i++)
|
|
|
|
|
{
|
|
|
|
|
Book e;
|
|
|
|
|
e = books.elem[i + 1];
|
|
|
|
|
print(e);
|
|
|
|
|
flag++;
|
|
|
|
|
number++;
|
|
|
|
|
}
|
|
|
|
|
cout << "Total: ";
|
|
|
|
|
cout << flag;
|
|
|
|
|
cout << number;
|
|
|
|
|
cout << " books" << endl;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 归还图书
|
|
|
|
|
void DoRepaidBook()
|
|
|
|
|
{
|
|
|
|
|
cout << endl << "Repaid Book" << endl<<endl;
|
|
|
|
|
cout << endl << "Repaid Book" << endl;
|
|
|
|
|
int id;
|
|
|
|
|
cout << "Which book you wanna repaid ? " << endl;
|
|
|
|
|
cout << "Enter book ID :" << endl;
|
|
|
|
|
cout << "Enter book ID :";
|
|
|
|
|
cin >> id;
|
|
|
|
|
cout << endl;
|
|
|
|
|
if (find(id)){
|
|
|
|
@ -171,6 +179,7 @@ void DoRepaidBook()
|
|
|
|
|
e = books.elem[find(id)];
|
|
|
|
|
++books.elem[find(id)].number;
|
|
|
|
|
}else{
|
|
|
|
|
cout << "Add Book" << endl;
|
|
|
|
|
DoAddBook();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
@ -178,13 +187,12 @@ void DoRepaidBook()
|
|
|
|
|
// 借用图书
|
|
|
|
|
void DoBoorowBook()
|
|
|
|
|
{
|
|
|
|
|
cout << endl << "Boorow Book" << endl <<endl;
|
|
|
|
|
cout << endl << "Boorow Book" << endl ;
|
|
|
|
|
int id;
|
|
|
|
|
if (bookempty()) cout << "Book data empty"<< endl;
|
|
|
|
|
cout << "Which book you wanna boorow ? " << endl;
|
|
|
|
|
cout << "Enter book ID :" << endl;
|
|
|
|
|
if (bookempty()) cout << "Books data empty"<< endl;
|
|
|
|
|
else{
|
|
|
|
|
cout << "Enter book ID :";
|
|
|
|
|
cin >> id;
|
|
|
|
|
cout << endl;
|
|
|
|
|
if (find(id)){
|
|
|
|
|
if (books.elem[find(id)].number>0) {
|
|
|
|
|
Book e;
|
|
|
|
@ -193,25 +201,26 @@ void DoBoorowBook()
|
|
|
|
|
--books.elem[find(id)].number;
|
|
|
|
|
}else cout << "***************************"<< endl
|
|
|
|
|
<< "Book empty" << endl << "***************************" << endl;
|
|
|
|
|
}else cout<< "NOT FOUND THIS BOOK"<<endl;
|
|
|
|
|
}else cout<< "NOT FOUND THIS BOOK"<<endl;}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 修改图书
|
|
|
|
|
void DoReviseBook()
|
|
|
|
|
{
|
|
|
|
|
cout <<endl<< "Revise Book" <<endl <<endl;
|
|
|
|
|
cout <<endl<< "Revise Book" <<endl ;
|
|
|
|
|
int id;
|
|
|
|
|
printf( "Which book you wanna revise ?\n" );
|
|
|
|
|
cout << "Enter book ID :";
|
|
|
|
|
cin >> id;
|
|
|
|
|
|
|
|
|
|
if ( find(id)!=0 ) {
|
|
|
|
|
printf ( "Original book number : %d\n", books.elem[id].number );
|
|
|
|
|
printf ( "Original book number : %d\n", books.elem[find(id)].number );
|
|
|
|
|
printf ( "Revised number :" );
|
|
|
|
|
int xiugai;
|
|
|
|
|
scanf ( "%d", &xiugai );
|
|
|
|
|
books.elem[id].number+=xiugai;
|
|
|
|
|
books.elem[id].number=xiugai;
|
|
|
|
|
cout << "**********************" << endl;
|
|
|
|
|
printf ( "Revise success \n" );
|
|
|
|
|
cout << "**********************" << endl;
|
|
|
|
|
}
|
|
|
|
|
else printf ( "No such book\n");
|
|
|
|
|
}
|
|
|
|
@ -219,12 +228,12 @@ void DoReviseBook()
|
|
|
|
|
// 排序图书
|
|
|
|
|
void DoSortBook()
|
|
|
|
|
{
|
|
|
|
|
cout << endl << "Sort Books" << endl << endl;
|
|
|
|
|
cout << endl << "Sort Books" << endl;
|
|
|
|
|
int a=0;
|
|
|
|
|
if (bookempty()) cout << "Book data empty"<< endl;
|
|
|
|
|
else {
|
|
|
|
|
for (int i=1;i<books.length;i++)
|
|
|
|
|
for (int j=books.length;j>0;j--)
|
|
|
|
|
for (int i=1;i<books.length-1;i++)
|
|
|
|
|
for (int j=2;j<books.length;j++)
|
|
|
|
|
{
|
|
|
|
|
if (books.elem[i].id>books.elem[j].id) {
|
|
|
|
|
Book temp=books.elem[i];books.elem[i]=books.elem[j];books.elem[j]=temp;}
|
|
|
|
@ -232,5 +241,6 @@ void DoSortBook()
|
|
|
|
|
}
|
|
|
|
|
cout << "*****************************" <<endl;
|
|
|
|
|
cout << "Sort success"<<endl;
|
|
|
|
|
cout << "*****************************" <<endl;
|
|
|
|
|
}
|
|
|
|
|
#endif // DATA_H_INCLUDED
|