|
|
|
@ -5,15 +5,19 @@
|
|
|
|
|
#include "sqlist.h"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 函数声明
|
|
|
|
|
struct Book {
|
|
|
|
|
int id; // 编号
|
|
|
|
|
string title; // 标题
|
|
|
|
|
int number; // 数量
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
void print_book(void); // 打印
|
|
|
|
|
void query_book(void); // 查询
|
|
|
|
|
void add_book(void); // 添加
|
|
|
|
|
void delete_book(void); // 删除
|
|
|
|
|
void boorow_book(void); // 借书
|
|
|
|
|
void repaid_book(void); // 还书
|
|
|
|
|
SqList <Book> books;
|
|
|
|
|
|
|
|
|
|
// 函数声明
|
|
|
|
|
bool bookempty(); // 书籍库判空
|
|
|
|
|
void input(Book& b); // 输入一本书的信息
|
|
|
|
|
void print(const Book& b);// 打印一本书的信息
|
|
|
|
|
int find(int id); // 根据 id 查找图书 || 若找到,返回元素的位序,找不到时返回 0
|
|
|
|
|
|
|
|
|
|
void DoAddBook(); // 添加图书
|
|
|
|
|
void DoFindBook(); // 查找图书
|
|
|
|
@ -21,54 +25,11 @@ void DoDeleteBook(); // 删除图书
|
|
|
|
|
void DoPrintBook(); // 打印所有图书
|
|
|
|
|
void DoRepaidBook(); // 归还图书
|
|
|
|
|
void DoBoorowBook(); // 借用图书
|
|
|
|
|
void DoReviseBook(); // 修改图书
|
|
|
|
|
void DoSortBook(); // 排序图书
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void repaid_book(void) // 还书
|
|
|
|
|
{
|
|
|
|
|
printf("还书\n");
|
|
|
|
|
DoRepaidBook();
|
|
|
|
|
}
|
|
|
|
|
void boorow_book(void) // 借书
|
|
|
|
|
{
|
|
|
|
|
printf("借书\n");
|
|
|
|
|
DoBoorowBook();
|
|
|
|
|
}
|
|
|
|
|
void query_book(void) // 查询
|
|
|
|
|
{
|
|
|
|
|
printf("查书\n");
|
|
|
|
|
DoFindBook();
|
|
|
|
|
}
|
|
|
|
|
void print_book(void) // 打印
|
|
|
|
|
{
|
|
|
|
|
printf("打印\n");
|
|
|
|
|
DoPrintBook();
|
|
|
|
|
}
|
|
|
|
|
void add_book(void) // 添加
|
|
|
|
|
{
|
|
|
|
|
puts("添加");
|
|
|
|
|
DoAddBook();
|
|
|
|
|
}
|
|
|
|
|
void delete_book(void) // 删除
|
|
|
|
|
{
|
|
|
|
|
puts("删除");
|
|
|
|
|
DoDeleteBook();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
struct Book {
|
|
|
|
|
int id; // 编号
|
|
|
|
|
string title; // 标题
|
|
|
|
|
int number; // 数量
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
SqList <Book> books;
|
|
|
|
|
|
|
|
|
|
// 输入一本书的信息
|
|
|
|
|
// 输入一本书的信息
|
|
|
|
|
void input(Book& b)
|
|
|
|
|
{
|
|
|
|
|
cout << "ID : ";
|
|
|
|
@ -108,10 +69,22 @@ int find(int id)
|
|
|
|
|
return 0; // not found
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 书籍库判空
|
|
|
|
|
bool bookempty()
|
|
|
|
|
{
|
|
|
|
|
int a=0;
|
|
|
|
|
for (int i=1;i<=books.length;i++)
|
|
|
|
|
{
|
|
|
|
|
if (find(i)==0) a++;
|
|
|
|
|
}
|
|
|
|
|
if (a==books.length) return true;
|
|
|
|
|
else return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 添加图书
|
|
|
|
|
void DoAddBook()
|
|
|
|
|
{
|
|
|
|
|
cout << endl << "Add Book"<< endl<<endl;
|
|
|
|
|
Book book;
|
|
|
|
|
input(book); //输入图书
|
|
|
|
|
books.elem[books.length + 1] = book;
|
|
|
|
@ -123,6 +96,7 @@ void DoAddBook()
|
|
|
|
|
// 查找图书
|
|
|
|
|
void DoFindBook()
|
|
|
|
|
{
|
|
|
|
|
cout << endl << "Find Book" << endl <<endl;
|
|
|
|
|
int id;
|
|
|
|
|
cout << "Enter book ID: ";
|
|
|
|
|
cin >> id;
|
|
|
|
@ -142,6 +116,7 @@ void DoFindBook()
|
|
|
|
|
// 删除图书
|
|
|
|
|
void DoDeleteBook()
|
|
|
|
|
{
|
|
|
|
|
cout << endl << "Delete Book" << endl << endl;
|
|
|
|
|
int id;
|
|
|
|
|
cout << "Which book you wanna delelet?"<<endl;
|
|
|
|
|
cout << "Enter book ID: ";
|
|
|
|
@ -166,6 +141,7 @@ void DoDeleteBook()
|
|
|
|
|
// 打印所有图书
|
|
|
|
|
void DoPrintBook()
|
|
|
|
|
{
|
|
|
|
|
cout << endl << "Print All Books" << endl <<endl;
|
|
|
|
|
int flag = 0;
|
|
|
|
|
for (int i = 0; i < books.length; i++)
|
|
|
|
|
{
|
|
|
|
@ -182,6 +158,7 @@ void DoPrintBook()
|
|
|
|
|
// 归还图书
|
|
|
|
|
void DoRepaidBook()
|
|
|
|
|
{
|
|
|
|
|
cout << endl << "Repaid Book" << endl<<endl;
|
|
|
|
|
int id;
|
|
|
|
|
cout << "Which book you wanna repaid ? " << endl;
|
|
|
|
|
cin >> id;
|
|
|
|
@ -198,6 +175,7 @@ void DoRepaidBook()
|
|
|
|
|
// 借用图书
|
|
|
|
|
void DoBoorowBook()
|
|
|
|
|
{
|
|
|
|
|
cout << endl << "Boorow Book" << endl <<endl;
|
|
|
|
|
int id;
|
|
|
|
|
cout << "Which book you wanna boorow ? " << endl;
|
|
|
|
|
cin >> id;
|
|
|
|
@ -210,9 +188,35 @@ void DoBoorowBook()
|
|
|
|
|
--books.elem[find(id)].number;
|
|
|
|
|
}else cout << "***************************"<< endl
|
|
|
|
|
<< "Book empty" << endl << "***************************" << endl;
|
|
|
|
|
}else throw "NOT FOUND THIS BOOK";
|
|
|
|
|
}else cout<< "NOT FOUND THIS BOOK"<<endl;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 修改图书
|
|
|
|
|
void DoReviseBook()
|
|
|
|
|
{
|
|
|
|
|
cout <<endl<< "Revise Book" <<endl <<endl;
|
|
|
|
|
int id;
|
|
|
|
|
printf( "Which book you wanna revise ?\n" );
|
|
|
|
|
cin >> id;
|
|
|
|
|
|
|
|
|
|
if ( find(id)!=0 ) {
|
|
|
|
|
printf ( "Original book number : %d\n", books.elem[id].number );
|
|
|
|
|
printf ( "Revised number :" );
|
|
|
|
|
int xiugai;
|
|
|
|
|
scanf ( "%d", &xiugai );
|
|
|
|
|
books.elem[id].number+=xiugai;
|
|
|
|
|
cout << "**********************" << endl;
|
|
|
|
|
printf ( "Revise success \n" );
|
|
|
|
|
}
|
|
|
|
|
else printf ( "No such book\n");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 排序图书
|
|
|
|
|
void DoSortBook()
|
|
|
|
|
{
|
|
|
|
|
cout << endl << "Sort Books" << endl << endl;
|
|
|
|
|
int a=0;
|
|
|
|
|
if (bookempty()) cout << "Book data empty"<< endl;
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
#endif // DATA_H_INCLUDED
|