-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbookManage.cpp
More file actions
115 lines (106 loc) · 2.78 KB
/
bookManage.cpp
File metadata and controls
115 lines (106 loc) · 2.78 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
#include"bookManage.h"
#include "SearchBook.h"
#include <map>
#include <iostream>
#include <vector>
#include <algorithm>
#include <cstring>
#include <string>
#include "myLibType.h"
using namespace std;
extern vector<Book> books;
extern vector<Book> view_now;
bool Judgement(unsigned char c)
{
if(c>0x80)
return true;
else
return false;
}
Book *insertfindbook (wstring all)
{
for(auto &book:books)
{
if(all==Lib::String2Wstring(book.name+book.author+book.publisher))
{
return &book;
}
}
return nullptr;
}
vector<Book>::iterator insertfindbookbycnum (string cnum)
{
for(auto it=books.begin();it!=books.end();it++)
{
if(cnum==(*it).categoryNumber)
{
return it;
}
}
return books.end();
}
int Lib::addBook(std::string name,std::string author,std::string publisher,int num){//增加书籍
wstring w_name=Lib::String2Wstring(name);
wstring w_author=Lib::String2Wstring(author);
wstring w_publisher=Lib::String2Wstring(publisher);
if(w_name.substr(0,1)!=L"《"){
w_name=L"《"+w_name;
}
if(w_name.substr(w_name.length()-1,1)!=L"》"){
w_name=w_name+L"》";
}
name=Lib::Wstring2String(w_name);
Book *book=insertfindbook(w_name+w_author+w_publisher);
if(book==nullptr){
string cnum;
cnum=name+author+publisher;
string h_cnum=to_string(hash<string>()(cnum));
Book new_book={name,author,publisher,h_cnum,num};
books.push_back(new_book);
return 1;
}
else{
book->remaining+=num;
return 0;
}
return -1;
}
vector<Book> Lib::dispAll(){//显示全部书籍
view_now=books;
return view_now;
};
vector<Book> Lib::dispNow(){//显示某种书籍
return view_now;
}
int Lib::borrowBook(wstring name,wstring author,wstring publisher,int numBook) {
Book *book=insertfindbook(name+author+publisher);
if(book==nullptr)return 0;
if(numBook>book->remaining)return 2;
book->remaining-=numBook;
return 1;
}
int Lib::returnBook(wstring name,wstring author,wstring publisher,int numBook) {
Book *book=insertfindbook(name+author+publisher);
if(book==nullptr)return 0;
book->remaining+=numBook;
return 1;
}
int Lib::deleteBook(string cnum) {
auto book=insertfindbookbycnum(cnum);
if(book==books.end())return 0;
else{
books.erase(book);
return 1;
}
return -1;
}
void Lib::Synchronize(){
for(auto &vnbook:view_now){
for(const auto book:books){
if(vnbook.categoryNumber==book.categoryNumber){
vnbook=book;
break;
}
}
}
}