pull/9/head
yangtengze 2 years ago
parent aac2722502
commit 8c04dcff4d

@ -67,14 +67,12 @@
请选择1 请选择1
Find Book Find Book
Book data empty Book data empty
``` ```
``` ```
请选择1 请选择1
Find Book Find Book
Enter book ID: 1 Enter book ID: 1
Not found Not found
``` ```
@ -82,7 +80,6 @@ Not found
请选择1 请选择1
Find Book Find Book
Enter book ID: 1 Enter book ID: 1
Found Found
************ ************
@ -98,16 +95,13 @@ Book
请选择2 请选择2
Boorow Book Boorow Book
Book data empty Book data empty
``` ```
``` ```
请选择2 请选择2
Boorow Book Boorow Book
Enter book ID:2
Which book you wanna boorow ?
2
NOT FOUND THIS BOOK NOT FOUND THIS BOOK
``` ```
@ -115,9 +109,7 @@ NOT FOUND THIS BOOK
请选择2 请选择2
Boorow Book Boorow Book
Enter book ID:1
Which book you wanna boorow ?
1
********* *********
OK OK
@ -129,19 +121,17 @@ OK
请选择3 请选择3
Repaid Book Repaid Book
Enter book ID:2
Which book you wanna repaid ?
2
Add Book Add Book
ID : 1 ID : 2
TITLE : 1 TITLE : 1
Number : 1 Number : 1
Book Book
**************** id: 1 **************** **************** id: 2 ****************
**** title: 《 1 》**** **** title: 《 1 》****
************** Number: 1 ************** ************** Number: 1 **************
````` `````
@ -151,9 +141,7 @@ Book
请选择3 请选择3
Repaid Book Repaid Book
Enter book ID:1
Which book you wanna repaid ?
1
````` `````
### C4打印书籍 ### C4打印书籍
@ -208,8 +196,6 @@ Book
请选择6 请选择6
Delete Book Delete Book
Which book you wanna delelet?
Enter book ID: 4 Enter book ID: 4
Book Book
@ -219,13 +205,12 @@ Book
************************ ************************
Deleted Deleted
************************
``` ```
``` ```
请选择6 请选择6
Delete Book Delete Book
Which book you wanna delelet?
Enter book ID: 5 Enter book ID: 5
Not found Not found
``` ```
@ -235,9 +220,7 @@ Not found
请选择7 请选择7
Revise Book Revise Book
Enter book ID : 1
Which book you wanna revise ?
1
Original book number : 1 Original book number : 1
Revised number :2 Revised number :2
********************** **********************
@ -249,9 +232,7 @@ Revise success
请选择7 请选择7
Revise Book Revise Book
Enter book ID : 2
Which book you wanna revise ?
2
No such book No such book
`````` ``````
### C8排序图书 ### C8排序图书
@ -260,14 +241,12 @@ No such book
请选择8 请选择8
Sort Books Sort Books
Book data empty Book data empty
``` ```
``` ```
请选择8 请选择8
Sort Books Sort Books
***************************** *****************************
Sort success Sort success
``` ```
@ -329,7 +308,7 @@ Step 6: if 没找到 then 提示Not found
![find](Graph\DoFindBook.drawio.svg) ![find](Graph\DoFindBook.drawio.svg)
## DoDeleteBook ## DoDeleteBook
``` ```
Step 1: 提示删除图书和要删除那本书? Step 1: 提示删除图书
Step 2: 输入图书编号 Step 2: 输入图书编号
Step 3: if 存在此图书 then 输出图上述信息 并提示 Deleted Step 3: if 存在此图书 then 输出图上述信息 并提示 Deleted
Step 4: if 不存在此图书 then 提示 Not found Step 4: if 不存在此图书 then 提示 Not found
@ -344,9 +323,18 @@ Step 3: 显示总书籍个数
![print](Graph\DoPrintBook.drawio.svg) ![print](Graph\DoPrintBook.drawio.svg)
## DoRepaidBook ## DoRepaidBook
``` ```
Step 1: 提示归还图书和哪本书是要还的 Step 1: 提示归还图书
Step 2: 输入图书编号 Step 2: 输入图书编号
Step 3: if 存在该书 then 图书数量变化 1 Step 3: if 存在该书 then 图书数量变化 1
Step 4: if 不存在该书 then 添加此图书 Step 4: if 不存在该书 then 添加此图书
``` ```
![repaid](Graph\DoRepaidBook.drawio.svg) ![repaid](Graph\DoRepaidBook.drawio.svg)
## DoBoorowBook
```
Step 1: 提示借用图书
Step 2: if 图书库为空 then 提示 Books data empty
Step 3: 输入图书编号
Step 4: if 此书存在 if 数量不小于0 then 进行程序并提示 OK 以表示完成 else 提示 Book empty
Step 5: if 此书不存在 then 提示 NOT FOUND THIS BOOK
```
![boorow]()

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