c++图书管理系统后台管理员,完整代码和数据

#include<iostream>
#include<vector>
#include<cstring>
#include<map>
#include<fstream>
using namespace std;
//--------数据类---------

//基础类
class DemoStatic {
private:
	int static MaxBorrowNum;
	int static MaxBorrowTime;
public:
	static int getMaxBorrowNum() { return MaxBorrowNum; }
	static void setMaxBorrowNum(int num) { MaxBorrowNum = num; }
	static int getMaxBorrowTime() { return MaxBorrowTime; }
	static void setMaxBorrowTime(int num) { MaxBorrowTime = num; }
};
int DemoStatic::MaxBorrowNum = 20;
int DemoStatic::MaxBorrowTime = 60;

//日期类
class Date {
private:
	int y;
	int m;
	int d;
public:
	Date(int y, int m, int d) { this->y = y; this->m = m; this->d = d; }
	Date() {}
	friend istream& operator>>(istream& in, Date& date);
	friend ostream& operator<<(ostream& out, Date& date);
	Date operator + (const Date& date)const;
	bool operator < (const Date& d2) const { return y != d2.y ? y < d2.y : m != d2.m ? m < d2.m : d < d2.d; }
};

istream& operator>>(istream& in, Date& date)
{
	int a[] = { 0,31,28,31,30,31,30,31,31,30,31,30,31 };
	char ch;
	in >> date.y >> ch >> date.m >> ch >> date.d;

	if (date.y % 4 == 0 && date.y % 100 != 0 || date.y % 400 == 0) {
		a[2] = 29;
	}
	if (date.y < 2000 || date.y > 2100) {
		cout << "年份错误" << endl;
	}
	if (date.m < 1 || date.m > 12) {
		cout << "月份错误" << endl;
	}
	if (date.d < 1 || date.d > a[date.m]) {
		cout << "日期错误" << endl;
	}
	return in;
}

ostream& operator<<(ostream& out, Date& date)
{
	out << date.y << "/";
	if (date.m < 10) {
		out << "0" << date.m << "/";
	}
	else {
		out << date.m << "/";
	}
	if (date.d < 10) {
		out << "0" << date.d;
	}
	else {
		out << date.d;
	}
	return out;
}

Date Date::operator + (const Date& date) const {
	Date d1;
	d1.y = date.y + this->y;
	d1.m = date.m + this->m;
	d1.d = date.d + this->d;
	return d1;
}

//借阅记录类:包括日期、书号、读者学号、
//类型(借出/还回/续借)、图书类型(基础/文学休闲/专业);
class Record {
private:
	string bookId;
	string readerId;
	string type;
	string bookType;
	Date date;
public:
	Record(string bookId, string readerId, string type, string bookType, Date date);
	Record() {}

	string getBookId() { return bookId; }
	void setBookId(string bookId) { this->bookId = bookId; }

	string getReaderId() { return readerId; }
	void setReaderId(string readerId) { this->readerId = readerId; }

	string getType() { return type; }
	void setType(string type) { this->type = type; }

	string getBookType() { return bookType; }
	void setBookType(string bookType) { this->bookType = bookType; }

	Date getDate() { return date; }
	void setDate(Date date) { this->date = date; }

	friend istream& operator>>(istream& in, Record& r);
	friend ostream& operator<<(ostream& out, Record& r);
};

Record::Record(string bookId, string readerId, string type, string bookType, Date date) {
	this->date = date;
	this->bookId = bookId;
	this->readerId = readerId;
	this->type = type;
	this->bookType = bookType;
}
istream& operator>>(istream& in, Record& r) {
	in >> r.bookId;
	in >> r.readerId;
	in >> r.type;
	in >> r.bookType;
	in >> r.date;
	return in;
}
ostream& operator<<(ostream& out, Record& r) {
	out << r.bookId << " ";
	out << r.readerId << " ";
	out << r.type << " ";
	out << r.bookType << " ";
	out << r.date << endl;
	return out;
}
//读者类
class Reader {
private:
	string id;
	string name;
	string major;
	string rClass;
	int borrowedNum;
	bool exist;//用于判断是否被删除
public:
	Reader(string id, string name, string major, string rClass, int borrowedNum);
	Reader() { exist = true; }
	void borrowAndLend(int i) { borrowedNum += i; }

	string getId() { return id; }
	void setId(string id) { this->id = id; }

	string getName() { return name; }
	void setName(string name) { this->name = name; }

	string getMajor() { return major; }
	void setMajor(string major) { this->major = major; }

	string getRClass() { return rClass; }
	void setRClass(string id) { this->rClass = rClass; }

	void setExist(bool b) { exist = b; }
	bool getExist() { return exist; }
	friend ostream& operator<<(ostream& out, Reader& r);
};

ostream& operator<<(ostream& out, Reader& r) {
	out << r.id << " " << r.name << " " << r.major << " " << r.rClass << " " << r.borrowedNum << endl;
	return out;
}
Reader::Reader(string id, string name, string major, string rClass, int borrowedNum) {
	this->id = id;
	this->name = name;
	this->major = major;
	this->rClass = rClass;
	this->borrowedNum = borrowedNum;
	exist = true;
}
//图书类
class Book {
private:
	string id;
	string name;
	string author;
	string publisher;
	Date publishDate;
	string type;
	int allNum;
	int nowNum;
public:
	Book(string id, string name, string author, string publisher, Date publishDate, string type, int allNum, int nowNum);
	Book() {}
	friend ostream& operator<<(ostream& out, Book& b);
	string getId() { return id; }
	void setId(string id) { this->id = id; }

	string getName() { return name; }
	void setName(string name) { this->name = name; }

	string getAuthor() { return author; }
	void setAuthor(string author) { this->author = author; }

	string getPublisher() { return publisher; }
	void setPublisher(string publisher) { this->publisher = publisher; }

	Date getPublishDate() { return publishDate; }
	void setPublishDate(Date publishDate) { this->publishDate = publishDate; }

	string getType() { return type; }
	void setType(string type) { this->type = type; }

	void setAllNum(int num) { allNum = num; }
	int getAllNum() { return allNum; }
	void borrowAndLend(int i) { nowNum += i; }
};
Book::Book(string id, string name, string author, string publisher, Date publishDate, string type, int allNum, int nowNum)
{
	this->id = id;
	this->name = name;
	this->author = author;
	this->publisher = publisher;
	this->publishDate = publishDate;
	this->type = type;
	this->allNum = allNum;
	this->nowNum = nowNum;
}
ostream& operator<<(ostream& out, Book& b) {
	out << b.id << " " << b.name << " " << b.author << " " << b.publisher << " ";
	out << b.publishDate << " ";
	out << b.type << " " << b.allNum << " " << b.nowNum << endl;
	return out;
}
//----------操作类---------
class Operater {
private:
	vector<Book> v_Book;
	map<string, int> book_id;
	multimap<string, int> book_name;
	multimap<string, int>book_author;
	multimap<string, int>book_publisher;
	multimap<Date, int>book_publishDate;
	multimap<string, int>book_type;


	vector<Reader> v_Reader;
	map<string, int> read_id;
	multimap<string, int>read_name;
	multimap<string, int>read_major;
	multimap<string, int>read_rclass;


	vector<Record> v_Record;
	multimap<string, int> record_readerId;
	multimap<string, int> record_bookId;
	multimap<string, int> record_type;
	multimap<string, int> record_bookType;
	multimap<Date, int> record_Date;


public:
	//对图书的操作
	void loadBook();
	void saveBook();//保存向量里面的内容
	void addBook(string id, string name, string author, string publisher, Date publishDate, string type, int allNum, int nowNum);//加到vector和map
	void deleteBook(string id);//仅把书的总容量设置为0,并且保存时不再保存该书
	void updateBook(string id, string name, string author, string publisher, Date publishDate, string type, int allNum, int nowNum);
	int searchByBookId(string id);
	vector<Book> searchByBookName(string name);
	vector<Book> searchByBookAuthor(string author);
	vector<Book> searchByBookPublisher(string publisher);
	vector<Book> searchByBookPublisheDate(Date publishDate1, Date publishDate2);
	vector<Book> searchByBookType(string type);
	void refreshBookMap();

	//对读者的操作
	void loadReader();
	void saveReader();
	void addReader(string id, string name, string major, string rClass, int borrowedNum);
	void deleteReader(string id);
	void updateReader(string id, string name, string major, string rClass, int borrowedNum);
	int searchByReadId(string id);
	vector<Reader> searchByReadName(string name);
	vector<Reader> searchByReadMajor(string major);
	vector<Reader> searchByReadRClass(string rClass);
	void refreshReaderMap();

	//对借阅记录的操作
	void loadRecord();
	void saveRecord();
	void addRecord(string bookId, string readerId, string type, string bookType, Date date);
	vector<Record> searchByRecordReaderId(string Sid);
	vector<Record> searchByRecordBookId(string bookId);
	vector<Record> searchByRecordType(string type);
	vector<Record> searchByRecordBookType(string bookType);
	vector<Record> searchByRecordDate(Date d1, Date d2);
	void refreshRecordMap();
};

void Operater::loadBook() {
	char fileName[50] = "2020214436book.txt";
	ifstream infile(fileName, ios::in);
	v_Book.clear();
	book_id.clear();
	string id;
	string name;
	string author;
	string publisher;
	Date publishDate;
	string type;
	int allNum;
	int nowNum;
	int i = 0;
	while (infile >> id) {
		infile >> name >> author >> publisher;
		infile >> publishDate;
		infile >> type >> allNum >> nowNum;
		Book b(id, name, author, publisher, publishDate, type, allNum, nowNum);
		v_Book.push_back(b);
		++i;
	}
	infile.close();
	refreshBookMap();
}
void Operater::saveBook() {
	char fileName[50] = "2020214436book.txt";
	ofstream outfile(fileName, ios::out);
	vector<Book>::iterator it;
	for (it = v_Book.begin(); it != v_Book.end(); it++) {
		if (it->getAllNum()) {
			outfile << *it;
		}
	}
	outfile.close();
}
void Operater::addBook(string id, string name, string author, string publisher, Date publishDate, string type, int allNum, int nowNum) {
	Book book(id, name, author, publisher, publishDate, type, allNum, nowNum);
	v_Book.push_back(book);

	int i = v_Book.size() - 1;
	book_id.insert(make_pair(id, i));
	book_name.insert(make_pair(name, i));
	book_author.insert(make_pair(author, i));
	book_publisher.insert(make_pair(publisher, i));
	book_publishDate.insert(make_pair(publishDate, i));
	book_type.insert(make_pair(type, i));
}
void Operater::deleteBook(string id) {
	map<string, int>::iterator n = book_id.find(id);
	if (n != book_id.end()) {
		v_Book.erase(v_Book.begin()+(n->second));
		refreshBookMap();
	}
	else {
		cout << "没有找到要删除的书籍" << endl;
	}
}
int Operater::searchByBookId(string id) {
	map<string, int>::iterator n = book_id.find(id);
	if (n != book_id.end() && v_Book[n->second].getAllNum() != 0) {
		cout << v_Book[n->second];
		return n->second;
	}
	else {
		cout << "没有找到任何结果" << endl;
		return -1;
	}
}
void Operater::updateBook(string id, string name, string author, string publisher, Date publishDate, string type, int allNum, int nowNum) {
	deleteBook(id);
	addBook(id, name, author, publisher, publishDate, type, allNum, nowNum);
}
vector<Book> Operater::searchByBookName(string name) {
	vector<Book> vb;
	auto ret = book_name.equal_range(name);
	multimap<string, int>::iterator first = ret.first;
	multimap<string, int>::iterator last = ret.second;
	if (first != last) {
		do {
			vb.push_back(v_Book[first->second]);
			first++;
		} while (first != last);
	}
	return vb;
}
vector<Book> Operater::searchByBookAuthor(string author) {
	vector<Book> vb;
	auto ret = book_author.equal_range(author);
	multimap<string, int>::iterator first = ret.first;
	multimap<string, int>::iterator last = ret.second;
	if (first != last) {
		do {
			vb.push_back(v_Book[first->second]);
			first++;
		} while (first != last);
	}
	return vb;
}
vector<Book> Operater::searchByBookPublisher(string publisher) {
	vector<Book> vb;
	auto ret = book_publisher.equal_range(publisher);
	multimap<string, int>::iterator first = ret.first;
	multimap<string, int>::iterator last = ret.second;
	if (first != last) {
		do {
			vb.push_back(v_Book[first->second]);
			first++;
		} while (first != last);
	}
	return vb;
}
vector<Book> Operater::searchByBookPublisheDate(Date publishDate1,Date publishDate2) {
	vector<Book> vb;
	multimap<Date, int>::iterator first = book_publishDate.lower_bound(publishDate1);
	multimap<Date, int>::iterator last = book_publishDate.upper_bound(publishDate2);
	while (first != last) {
		vb.push_back(v_Book[first->second]);
		first++;
	}

	return vb;
}
vector<Book> Operater::searchByBookType(string type) {
	vector<Book> vb;
	auto ret = book_type.equal_range(type);
	multimap<string, int>::iterator first = ret.first;
	multimap<string, int>::iterator last = ret.second;
	if (first != last) {
		do {
			vb.push_back(v_Book[first->second]);
			first++;
		} while (first != last);
	}
	return vb;
}
void Operater::refreshBookMap() {
	book_id.clear();
	book_name.clear();
	book_author.clear();
	book_publisher.clear();
	book_publishDate.clear();
	book_type.clear();

	vector<Book>::iterator it;
	int i = 0;
	for (it = v_Book.begin(); it != v_Book.end(); it++) {
		book_id.insert(make_pair(it->getId(), i));
		book_name.insert(make_pair(it->getName(), i));
		book_author.insert(make_pair(it->getAuthor(), i));
		book_publisher.insert(make_pair(it->getPublisher(), i));
		book_publishDate.insert(make_pair(it->getPublishDate(), i));
		book_type.insert(make_pair(it->getType(), i));
		++i;
	}
}

void Operater::loadReader() {
	string id;
	string name;
	string major;
	string rClass;
	int borrowedNum;
	int i = 0;
	char fileName[50] = "2020214436reader.txt";
	ifstream infile(fileName, ios::in);
	v_Reader.clear();
	read_id.clear();
	while (infile >> id) {
		infile >> name >> major >> rClass >> borrowedNum;
		Reader r(id, name, major, rClass, borrowedNum);
		v_Reader.push_back(r);
		++i;
	}
	infile.close();
	refreshReaderMap();
}
void Operater::saveReader() {
	char fileName[50] = "2020214436reader.txt";
	ofstream outfile(fileName, ios::out);
	vector<Reader>::iterator it;
	for (it = v_Reader.begin(); it != v_Reader.end(); it++) {
		if (it->getExist()) {
			outfile << *it;
		}
	}
	outfile.close();
}
void Operater::addReader(string id, string name, string major, string rClass, int borrowedNum) {
	Reader r(id, name, major, rClass, borrowedNum);
	v_Reader.push_back(r);
	int i = v_Reader.size() - 1;
	read_id.insert(make_pair(id, i));
	read_name.insert(make_pair(name, i));
	read_major.insert(make_pair(major, i));
	read_rclass.insert(make_pair(rClass, i));
}
void Operater::deleteReader(string id) {
	map<string, int>::iterator it = read_id.find(id);
	if (it != read_id.end()) {
		v_Reader.erase(v_Reader.begin() + (it->second));
		refreshReaderMap();
	}
	else {
		cout << "没有找到要删除的读者" << endl;
	}
}
int Operater::searchByReadId(string id) {
	map<string, int>::iterator n = read_id.find(id);
	if (n != read_id.end() && v_Reader[n->second].getExist()) {
		cout << v_Reader[n->second];
		return n->second;
	}
	else {
		cout << "没有找到任何结果" << endl;
	}
	return 0;
}
vector<Reader> Operater::searchByReadName(string name) {
	vector<Reader> vr;
	auto ret = read_name.equal_range(name);
	multimap<string, int>::iterator first = ret.first;
	multimap<string, int>::iterator last = ret.second;
	if (first != last) {
		do {
			vr.push_back(v_Reader[first->second]);
			first++;
		} while (first != last);
	}
	return vr;
}
vector<Reader> Operater::searchByReadMajor(string major) {
	vector<Reader> vr;
	auto ret = read_major.equal_range(major);
	multimap<string, int>::iterator first = ret.first;
	multimap<string, int>::iterator last = ret.second;
	if (first != last) {
		do {
			vr.push_back(v_Reader[first->second]);
			first++;
		} while (first != last);
	}
	return vr;
}
vector<Reader> Operater::searchByReadRClass(string rClass) {
	vector<Reader> vr;
	auto ret = read_rclass.equal_range(rClass);
	multimap<string, int>::iterator first = ret.first;
	multimap<string, int>::iterator last = ret.second;
	if (first != last) {
		do {
			vr.push_back(v_Reader[first->second]);
			first++;
		} while (first != last);
	}
	return vr;
}
void Operater::updateReader(string id, string name, string major, string rClass, int borrowedNum) {
	deleteReader(id);
	addReader(id, name, major, rClass, borrowedNum);
}
void Operater::refreshReaderMap() {
	read_id.clear();
	read_name.clear();
	read_major.clear();
	read_rclass.clear();

	vector<Reader>::iterator it;
	int i = 0;
	for (it = v_Reader.begin(); it != v_Reader.end(); ++it) {
		read_id.insert(make_pair(it->getId(), i));
		read_name.insert(make_pair(it->getName(), i));
		read_major.insert(make_pair(it->getMajor(), i));
		read_rclass.insert(make_pair(it->getRClass(), i));
		++i;
	}
}

void Operater::loadRecord() {
	char fileName[50] = "2020214436record.txt";
	ifstream infile(fileName, ios::in);
	v_Record.clear();
	record_Date.clear();
	string bookId;
	string readerId;
	string type;
	string bookType;
	Date date;
	int i = 0;
	while (infile >> bookId) {
		infile >> readerId >> type >> bookType;
		infile >> date;
		Record r(bookId, readerId, type, bookType, date);
		v_Record.push_back(r);
		++i;
	}
	infile.close();
	refreshRecordMap();
}
void Operater::saveRecord() {
	char fileName[50] = "2020214436record.txt";
	ofstream outfile(fileName, ios::out);
	vector<Record>::iterator it;
	for (it = v_Record.begin(); it != v_Record.end(); it++) {
		outfile << *it;
	}
	outfile.close();
}
void Operater::addRecord(string bookId, string readerId, string type, string bookType, Date date) {
	if (!strcmp(type.c_str(), "借出")) {
		map<string, int>::iterator n = book_id.find(bookId);
		if (n != book_id.end()) {
			v_Book[n->second].borrowAndLend(-1);
			//图书现存数量减一
		}
		else {
			cout << "没有找到该书" << endl;
		}
		n = read_id.find(readerId);
		if (n != read_id.end()) {
			v_Reader[n->second].borrowAndLend(1);
			//读者借阅数量加一
		}
		else {
			cout << "没有找到该读者" << endl;
		}
	}
	else if (!strcmp(type.c_str(), "还回")) {
		map<string, int>::iterator n = book_id.find(bookId);
		if (n != book_id.end()) {
			v_Book[n->second].borrowAndLend(1);
			//图书现存数量加一
		}
		else {
			cout << "没有找到该书" << endl;
		}
		n = read_id.find(readerId);
		if (n != read_id.end()) {
			v_Reader[n->second].borrowAndLend(-1);
			//读者借阅数量减一
		}
		else {
			cout << "没有找到该读者" << endl;
		}
	}
	Record r(bookId, readerId, type, bookType, date);
	v_Record.push_back(r);
	int i = v_Record.size() - 1;
	record_readerId.insert(make_pair(readerId, i));
	record_bookId.insert(make_pair(bookId, i));
	record_type.insert(make_pair(type, i));
	record_bookType.insert(make_pair(bookType, i));
	record_Date.insert(make_pair(date, i));
}
vector<Record> Operater::searchByRecordDate(Date d1, Date d2) {
	vector<Record> vr;
	multimap<Date, int>::iterator low = record_Date.lower_bound(d1);
	multimap<Date, int>::iterator high = record_Date.upper_bound(d2);
	while (low != high) {
		vr.push_back(v_Record[low->second]);
		low++;
	}
	return vr;
}
vector<Record> Operater::searchByRecordReaderId(string Sid) {
	//按读者学号查询
	vector<Record> vr;
	auto ret = record_readerId.equal_range(Sid);
	multimap<string, int>::iterator first = ret.first;
	multimap<string, int>::iterator last = ret.second;
	if (first != last) {
		do {
			vr.push_back(v_Record[first->second]);
			first++;
		} while (first != last);
	}
	return vr;
}
vector<Record> Operater::searchByRecordBookId(string bookId) {
	vector<Record> vr;
	auto ret = record_bookId.equal_range(bookId);
	multimap<string, int>::iterator first = ret.first;
	multimap<string, int>::iterator last = ret.second;
	if (first != last) {
		do {
			vr.push_back(v_Record[first->second]);
			first++;
		} while (first != last);
	}
	return vr;
}
vector<Record> Operater::searchByRecordType(string type) {
	vector<Record> vr;
	auto ret = record_type.equal_range(type);
	multimap<string, int>::iterator first = ret.first;
	multimap<string, int>::iterator last = ret.second;
	if (first != last) {
		do {
			vr.push_back(v_Record[first->second]);
			first++;
		} while (first != last);
	}
	return vr;
}
vector<Record> Operater::searchByRecordBookType(string bookType) {
	vector<Record> vr;
	auto ret = record_bookType.equal_range(bookType);
	multimap<string, int>::iterator first = ret.first;
	multimap<string, int>::iterator last = ret.second;
	if (first != last) {
		do {
			vr.push_back(v_Record[first->second]);
			first++;
		} while (first != last);
	}
	return vr;
}
void Operater::refreshRecordMap() {
	record_readerId.clear();
	record_bookId.clear();
	record_type.clear();
	record_bookType.clear();
	record_Date.clear();
	vector<Record>::iterator it;
	int i = 0;
	for (it = v_Record.begin(); it != v_Record.end(); ++it) {
		record_readerId.insert(make_pair(it->getReaderId(),i));
		record_bookId.insert(make_pair(it->getBookId(), i));
		record_type.insert(make_pair(it->getType(), i));
		record_bookType.insert(make_pair(it->getBookType(), i));
		record_Date.insert(make_pair(it->getDate(), i));
		++i;
	}
}
class Test {
private:
	Operater oper;
	void outputBook(vector<Book> vb) {
		for (vector<Book>::iterator it = vb.begin(); it != vb.end(); ++it) {
			cout << *it;
		}
	}
	void outputReader(vector<Reader> vr) {
		for (vector<Reader>::iterator it = vr.begin(); it != vr.end(); ++it) {
			cout << *it;
		}
	}
	void outputRecord(vector<Record> vr) {
		for (vector<Record>::iterator it = vr.begin(); it != vr.end(); ++it) {
			cout << *it;
		}
	}
public:
	void testBook() {
		oper.loadBook();
		Date d1(2021, 10, 11);
		oper.addBook("ISBN-978-138110", "生物化学", "孟庆伟", "中国农业出版社", d1, "专业", 11, 6);
		oper.addBook("ISBN-978-135433", "高等数学", "田祥", "中国农业出版社", d1, "专业", 12, 3);
		oper.deleteBook("ISBN-978-290459");

		vector<Book> vb1=oper.searchByBookAuthor("林德华");
		outputBook(vb1);
		cout << "-----------------------" << endl;
		oper.searchByBookId("ISBN-978-237456");//按照书号查找会直接输出
		cout << "-----------------------" << endl;
		vector<Book> vb2=oper.searchByBookName("Java程序设计");
		outputBook(vb2);
		cout << "-----------------------" << endl;
		Date d2(2022, 8, 13);
		Date d3(2022, 10, 11);
		vector<Book> vb3 = oper.searchByBookPublisheDate(d2,d3);
		outputBook(vb3);
		cout << "-----------------------" << endl;
		vector<Book> vb4 = oper.searchByBookPublisher("清华大学出版社");
		outputBook(vb4);
		cout << "-----------------------" << endl;
		vector<Book> vb5 = oper.searchByBookType("基础");
		outputBook(vb5);
		cout << "-----------------------" << endl;
		Date d4(2022, 9, 21);
		oper.updateBook("ISBN-978-290457", "Java程序设计", "李梦玉", "清华大学出版社", d4, "基础", 200, 50);//按照书号查找后修改
		oper.saveBook();
	}
	void testReader() {
		oper.loadReader();
		oper.addReader("2020214456","王志杰","计算机","4班",5);
		oper.deleteReader("2020214471");
		oper.searchByReadId("2020214436");//直接输出
		cout << "-----------------------" << endl;
		vector<Reader> vr1=oper.searchByReadName("王光明");
		outputReader(vr1);
		cout << "-----------------------" << endl;
		vector<Reader> vr2 = oper.searchByReadMajor("计算机");
		outputReader(vr2);
		cout << "-----------------------" << endl;
		vector<Reader> vr3 = oper.searchByReadRClass("4班");
		outputReader(vr3);
		cout << "-----------------------" << endl;
		vector<Reader> vr4 = oper.searchByReadRClass("20班");
		outputReader(vr4);//没有找到什么都不输出
		cout << "-----------------------" << endl;
		oper.updateReader("2020214436", "林怀钦", "计算机", "4班", 6);
		oper.saveReader();
	}
	void testRecord() {
		oper.loadBook();
		oper.loadReader();
		oper.loadRecord();
		Date d1(2022, 5, 22);
		oper.addRecord("ISBN-978-237456","2020214436", "借出", "基础",d1);

		vector<Record> vr1 = oper.searchByRecordBookId("ISBN-978-237456");
		outputRecord(vr1);
		cout << "-----------------------" << endl;
		vector<Record> vr2 = oper.searchByRecordReaderId("2020214436");
		outputRecord(vr2);
		cout << "-----------------------" << endl;
		vector<Record> vr3 = oper.searchByRecordType("借出");
		outputRecord(vr3);
		cout << "-----------------------" << endl;
		vector<Record> vr4 = oper.searchByRecordBookType("基础");
		outputRecord(vr4);
		cout << "-----------------------" << endl;
		Date d2(2022, 1, 9);
		Date d3(2022, 5, 22);
		vector<Record> vr5 = oper.searchByRecordDate(d2,d3);
		outputRecord(vr5);
		cout << "-----------------------" << endl;
		oper.saveRecord();
		oper.saveReader();
		oper.saveBook();
	}
};
int main() {
	Test t1;
	t1.testBook();
	t1.testReader();
	t1.testRecord();
}

数据文件
2020214436book.txt
ISBN-978-237456 c++程序设计 林德华 清华大学出版社 2022/10/11 基础 100 50
ISBN-978-290457 Java程序设计 李梦玉 清华大学出版社 2022/09/21 基础 100 50
ISBN-978-290459 python程序设计 陈翔 机械工业出版社 2022/08/13 基础 100 50

2020214436reader.txt
2020214436 林怀钦 计算机 4班 5
2021219033 王光明 物联网 1班 5
2020214471 刘振杰 大数据 1班 5

2020214436record.txt
ISBN-978-237456 2020214471 借出 文学 2022/01/19
ISBN-978-290457 2021219033 续借 专业 2022/02/11
ISBN-978-290459 2020214436 还回 基础 2022/04/18
ISBN-978-237456 2020214471 借出 基础 2022/04/19

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值