|
|
@ -2,54 +2,221 @@
|
|
|
|
#define DATA_H_INCLUDED
|
|
|
|
#define DATA_H_INCLUDED
|
|
|
|
|
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
|
|
|
|
#include "sqlist.h"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
struct Book {
|
|
|
|
|
|
|
|
int id; // 编号
|
|
|
|
|
|
|
|
string title; // 标题
|
|
|
|
|
|
|
|
int number; // 数量
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
SqList <Book> books;
|
|
|
|
|
|
|
|
|
|
|
|
// 函数声明
|
|
|
|
// 函数声明
|
|
|
|
void read_data(void); // 读取
|
|
|
|
bool bookempty(); // 书籍库判空
|
|
|
|
void save_data(void); // 保存
|
|
|
|
void input(Book& b); // 输入一本书的信息
|
|
|
|
void print_data(void); // 打印
|
|
|
|
void print(const Book& b);// 打印一本书的信息
|
|
|
|
void query_data(void); // 查询
|
|
|
|
int find(int id); // 根据 id 查找图书 || 若找到,返回元素的位序,找不到时返回 0
|
|
|
|
void add_data(void); // 添加
|
|
|
|
|
|
|
|
void update_data(void); // 修改
|
|
|
|
void DoAddBook(); // 添加图书
|
|
|
|
void delete_data(void); // 删除
|
|
|
|
void DoFindBook(); // 查找图书
|
|
|
|
void sort_data(void); // 排序
|
|
|
|
void DoDeleteBook(); // 删除图书
|
|
|
|
void make_chart(void); // 图表
|
|
|
|
void DoPrintBook(); // 打印所有图书
|
|
|
|
|
|
|
|
void DoRepaidBook(); // 归还图书
|
|
|
|
|
|
|
|
void DoBoorowBook(); // 借用图书
|
|
|
|
void read_data(void)
|
|
|
|
void DoReviseBook(); // 修改图书
|
|
|
|
{
|
|
|
|
void DoSortBook(); // 排序图书
|
|
|
|
printf("读取\n");
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 输入一本书的信息
|
|
|
|
|
|
|
|
void input(Book& b)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
cout << "ID : ";
|
|
|
|
|
|
|
|
cin >> b.id;
|
|
|
|
|
|
|
|
cin.ignore(1024, '\n'); // skip rest chars of the line
|
|
|
|
|
|
|
|
cout << "TITLE : ";
|
|
|
|
|
|
|
|
getline(cin, b.title);
|
|
|
|
|
|
|
|
cout << "Number : ";
|
|
|
|
|
|
|
|
while (1){
|
|
|
|
|
|
|
|
cin >> b.number;
|
|
|
|
|
|
|
|
if (b.number>0) break;
|
|
|
|
|
|
|
|
cout << "Number ERROR" << endl;
|
|
|
|
|
|
|
|
cout << "Input again" << endl;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
void save_data(void)
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 打印一本书的信息
|
|
|
|
|
|
|
|
void print(const Book& b)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
cout << "Book " << endl << endl
|
|
|
|
|
|
|
|
<<"**************** id: " << b.id << " ****************" << endl
|
|
|
|
|
|
|
|
<< "**** title: 《 " << b.title << " 》****" << endl
|
|
|
|
|
|
|
|
<< "************** Number: " << b.number << " **************" << endl << endl;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 根据 id 查找图书
|
|
|
|
|
|
|
|
// 若找到,返回元素的位序,找不到时返回 0
|
|
|
|
|
|
|
|
int find(int id)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
for (int i = 1; i <= books.length; i++)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
printf("保存\n");
|
|
|
|
if (id == books.elem[i].id){
|
|
|
|
|
|
|
|
return i;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
void print_data(void)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
printf("打印\n");
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
void query_data(void)
|
|
|
|
return 0; // not found
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 书籍库判空
|
|
|
|
|
|
|
|
bool bookempty()
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
int a=0;
|
|
|
|
|
|
|
|
for (int i=1;i<=books.length;i++)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
printf("查询\n");
|
|
|
|
if (find(i)==0) a++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
void add_data(void)
|
|
|
|
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;
|
|
|
|
|
|
|
|
books.length++;
|
|
|
|
|
|
|
|
print(book);
|
|
|
|
|
|
|
|
cout << "*******Added********" << endl;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 查找图书
|
|
|
|
|
|
|
|
void DoFindBook()
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
cout << endl << "Find Book" << endl <<endl;
|
|
|
|
|
|
|
|
int id;
|
|
|
|
|
|
|
|
cout << "Enter book ID: ";
|
|
|
|
|
|
|
|
cin >> id;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Book book;
|
|
|
|
|
|
|
|
if (find(id) == 0)
|
|
|
|
|
|
|
|
cout << "Not found" << endl;
|
|
|
|
|
|
|
|
else
|
|
|
|
{
|
|
|
|
{
|
|
|
|
puts("添加");
|
|
|
|
book = books.elem[find(id)];
|
|
|
|
|
|
|
|
cout << "Found" << endl;
|
|
|
|
|
|
|
|
cout << "************" << endl;
|
|
|
|
|
|
|
|
print(book);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
void update_data(void)
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 删除图书
|
|
|
|
|
|
|
|
void DoDeleteBook()
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
cout << endl << "Delete Book" << endl << endl;
|
|
|
|
|
|
|
|
int id;
|
|
|
|
|
|
|
|
cout << "Which book you wanna delelet?"<<endl;
|
|
|
|
|
|
|
|
cout << "Enter book ID: ";
|
|
|
|
|
|
|
|
cin >> id;
|
|
|
|
|
|
|
|
Book e;
|
|
|
|
|
|
|
|
if (find(id) == 0)
|
|
|
|
|
|
|
|
cout << "Not found" << endl;
|
|
|
|
|
|
|
|
else
|
|
|
|
{
|
|
|
|
{
|
|
|
|
puts("修改");
|
|
|
|
e = books.elem[find(id)];
|
|
|
|
}
|
|
|
|
print(e);
|
|
|
|
void delete_data(void)
|
|
|
|
for (int i = find(id); i < books.length; i++)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
puts("删除");
|
|
|
|
books.elem[i] = books.elem[i + 1];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
void sort_data(void)
|
|
|
|
--books.length;
|
|
|
|
{
|
|
|
|
cout << "************************" << endl;
|
|
|
|
puts("排序");
|
|
|
|
cout << "Deleted" << endl;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
void make_chart(void)
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 打印所有图书
|
|
|
|
|
|
|
|
void DoPrintBook()
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
cout << endl << "Print All Books" << endl <<endl;
|
|
|
|
|
|
|
|
int flag = 0;
|
|
|
|
|
|
|
|
for (int i = 0; i < books.length; i++)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
puts("图表");
|
|
|
|
Book e;
|
|
|
|
|
|
|
|
e = books.elem[i + 1];
|
|
|
|
|
|
|
|
print(e);
|
|
|
|
|
|
|
|
flag++;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
cout << "Total: ";
|
|
|
|
|
|
|
|
cout << flag;
|
|
|
|
|
|
|
|
cout << " books" << endl;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 归还图书
|
|
|
|
|
|
|
|
void DoRepaidBook()
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
cout << endl << "Repaid Book" << endl<<endl;
|
|
|
|
|
|
|
|
int id;
|
|
|
|
|
|
|
|
cout << "Which book you wanna repaid ? " << endl;
|
|
|
|
|
|
|
|
cin >> id;
|
|
|
|
|
|
|
|
cout << endl;
|
|
|
|
|
|
|
|
if (find(id)){
|
|
|
|
|
|
|
|
Book e;
|
|
|
|
|
|
|
|
e = books.elem[find(id)];
|
|
|
|
|
|
|
|
++books.elem[find(id)].number;
|
|
|
|
|
|
|
|
}else{
|
|
|
|
|
|
|
|
DoAddBook();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 借用图书
|
|
|
|
|
|
|
|
void DoBoorowBook()
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
cout << endl << "Boorow Book" << endl <<endl;
|
|
|
|
|
|
|
|
int id;
|
|
|
|
|
|
|
|
cout << "Which book you wanna boorow ? " << endl;
|
|
|
|
|
|
|
|
cin >> id;
|
|
|
|
|
|
|
|
cout << endl;
|
|
|
|
|
|
|
|
if (find(id)){
|
|
|
|
|
|
|
|
if (books.elem[find(id)].number>0) {
|
|
|
|
|
|
|
|
Book e;
|
|
|
|
|
|
|
|
e = books.elem[find(id)];
|
|
|
|
|
|
|
|
cout<< "*********"<< endl << "OK" << endl << "*********"<<endl;
|
|
|
|
|
|
|
|
--books.elem[find(id)].number;
|
|
|
|
|
|
|
|
}else cout << "***************************"<< endl
|
|
|
|
|
|
|
|
<< "Book empty" << endl << "***************************" << endl;
|
|
|
|
|
|
|
|
}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
|
|
|
|
#endif // DATA_H_INCLUDED
|