C++图书管理系统及相应文件的创建与输出

数据类:
基础类:读者最大借书量、最长借书时间(按天计算)。这两个都是类成员;
日前类:包括年月日,重载输入运算符时,要进行数据的合法性检验;重载输出运算符时,按照“年/月/日”形式输出,重载+运算符;
借阅记录类:包括日期、书号、读者学号、类型(借出/还回/续借)、图书类型(基础/文学休闲/专业);
读者类:学号、姓名、专业、班级、已借图书数量、借阅记录向量;
图书类∶书号、书名、作者、出版社、出版日期、图书类型(基础/文学休闲/专业)、馆藏总量、在馆数量、借阅记录向量;


操作类:
数据成员:图书/学生/借阅记录向量;
成员函数:对图书进行文件读写、在图书向量内完成对图书基本信息的增删查改;
对学生进行文件读写、在学生向量内完成对学生基本信息的增删查改;借阅记录的管理和统计功能后续添加;
作业要求:
程序能够正常运行,数据文件要经过多次运行测试,每次运行,内容要有相应的变化。数据用真实的,不要出现张三、李四这样的名字,数据不要在记事本中添加,一起通过程序搞定。

(三份修改后的作业)

//客户端
#include<bits/stdc++.h>
#include<iostream>
#include<fstream>
#include<vector>
#include<map>
using namespace std;
//Bor:借阅记录,Re:读者记录,Bk:图书记录
string iType1[4] = { "","借出","还回","续借" };//操作类型:借出,还回,续借;
string BookType1[4] = { "","基础","文学休闲","专业" };//图书续借类型:基础,文学休闲,专业;


//基础类:读者最大借书量、最长借书时间(按天计算);
class basic
{
    int MaxBorNum=20;//最大借书量:20本
    int MaxBorTime=60;//最长借书时间:60天
public:
    int GetMaxBorNum(){return this->MaxBorNum;};
    void SetMaxBorNum(int MaxBorNum){this->MaxBorNum=MaxBorNum;};
    int GetMaxBorTime(){return this->MaxBorTime;};
    void SetMaxBorTime(int MaxBorTime){this->MaxBorTime=MaxBorTime;};
};

//日前类:包括年月日,重载输入运算符时,要进行数据的合法性检验;重载输出运算符时,按照“年/月/日”形式输出;重载+运算符;
class date
{
    int year;
    int month;
    int day;
    friend ostream& operator<<(ostream& out, date& d);
    friend istream& operator>>(istream& in, date& d);
public:
    date(int year, int month, int day);
    date();
    date(int year)
    {
        this->year=year;
        this->month=0;
        this->day=0;
    }
    int GetYear() { return this->year; };
    void SetYear(int year) { this->year = year; };
    int GetMonth() { return this->month; };
    void SetMonth(int month) { this->month = month; };
    int GetDay() { return this->day; };
    void SetDay(int day) { this->day = day; };
    bool operator==(const date& d);
    date& operator+(int day);
    bool operator<(date d);
    bool operator>(date d);
};

date::date(int year, int month, int day)
{
    this->year = year;
    this->month = month;
    this->day = day;
}

date::date()
{
    this->year = 0;
    this->month = 0;
    this->day = 0;
}

ostream& operator<<(ostream& out, date& d)
{
    if(d.GetYear()==0||d.GetDay()==0)
    {
        out<<d.year;
    }else
    {
        out << d.year << "/" << d.month << "/" << d.day;
    }
    return out;
}

istream& operator>>(istream& in, date& d)
{
    int year,month,day;
    char op;int flag=0;
    while(in>>year>>op>>month>>op>>day)
    {
        if (d.year >= 1900 && d.year <= 2022 && d.month >= 1 && d.month <= 12)
        {
            if ((d.month == 1 || d.month == 3 || d.month == 5 || d.month == 7 || d.month == 8 || d.month == 10 || d.month == 12) && (d.day >= 1 && d.day <= 31))
            {
                flag=1;
            }
            else if ((d.month == 4 || d.month == 6 || d.month == 9 || d.month == 11) && d.day >= 1 && d.day <= 30)
            {
                flag=1;
            }
            else if (d.month == 2)
            {
                if (((d.year % 4 == 0 && d.year % 100 != 0) || (d.year % 400 == 0)) && (d.day >= 1 && d.year <= 29))
                {
                    flag=1;
                }
                else if (d.day >= 1 && d.day <= 28)
                {
                    flag=1;
                }
            }
            if(flag==1)
            {
                d.SetYear(year);
                d.SetMonth(month);
                d.SetDay(day);
            }
        }
    }
    return in;
}

bool date::operator==(const date& d)
{
    if (d.day == this->day && d.month == this->month && d.year == this->year)
    {
        return true;
    }
    else return false;
}


bool date::operator<(date d)
{
    if(this->GetYear()==d.GetYear())
    {
        if(this->GetMonth()==d.GetMonth())
        {
            return this->GetDay()<d.GetDay();
        }
        else
            return this->GetMonth()<d.GetMonth();
    }
    else
        return this->GetYear()<d.GetYear();
}

bool date::operator>(date d)
{
    if(this->GetYear()==d.GetYear())
    {
        if(this->GetMonth()==d.GetMonth())
        {
            return this->GetDay()>d.GetDay();
        }
        else
            return this->GetMonth()>d.GetMonth();
    }
    else
        return this->GetYear()>d.GetYear();
}

date& date::operator+(int day)
{
    int month[]={0,31,28,31,30,31,30,31,31,30,31,30,31};
    int x=0;
    while(x<day)
    {
        x++;
        if(this->GetMonth()==12)
        {
            if(this->GetDay()==month[this->GetMonth()])
            {
                this->SetYear(this->GetYear()+1);
                this->SetMonth(1);
                this->SetDay(1);
            }
            else
            {
                this->SetDay(this->GetDay()+1);
            }
        }
        else if(this->GetMonth()!=2)
        {
            if(this->GetDay()==month[this->GetMonth()])
            {
                this->SetMonth(this->GetMonth()+1);
                this->SetDay(1);
            }
            else
            {
                this->SetDay(this->GetDay()+1);
            }
        }
        else if(this->GetMonth()==2)
        {
            if((this->year % 4 == 0 && this->year % 100 != 0) || (this->year % 400 == 0))
            {
                month[this->GetMonth()]=29;
            }
            if(this->GetDay()==month[this->GetMonth()])
            {
                this->SetMonth(this->GetMonth()+1);
                this->SetDay(1);
            }
            else
            {
                this->SetDay(this->GetDay()+1);
            }
        }
    }
    return *this;
}

//借阅记录类:包括日期、书号、读者学号、类型(借出/还回/续借)、图书类型(基础/文学休闲/专业);
class BorrowingRecord
{
    date d;
    string BookNum;
    string ID;
    string iType2;
    int iType3=0;
    string BookType2;
    int BookType3=0;
    friend ostream& operator<<(ostream& out, BorrowingRecord& br);
    friend istream& operator>>(istream& in, BorrowingRecord& br);
public:
    BorrowingRecord(date d, string BookNum, string ID, int iType3, int BookType3);
    BorrowingRecord();
    date GetDate() { return this->d; };
    void SetDate(date d) { this->d = d; };
    string GetBookNum() { return this->BookNum; };
    void SetBookNum(string BookNum) { this->BookNum = BookNum; };
    string GetID() { return this->ID; };
    void SetID(string ID) { this->ID = ID; };
    string GetiType2() { return this->iType2; };
    void SetiType2(int iType3) { this->iType2 = iType1[iType3]; };
    string GetBookType2() { return this->BookType2; };
    void SetBookType2(string BookType2) { this->BookType2 = BookType2; };
    int GetBookType3(){return this->BookType3;};
    void SetBookType3(int BookType3){this->BookType3=BookType3;};
    bool operator==(const BorrowingRecord& br)
    {
        if (this->d == br.d && this->BookNum == br.BookNum && this->ID == br.ID && this->iType2 == br.iType2 && this->BookType2 == br.BookType2)
        {
            return true;
        }
        else return false;
    };
};

BorrowingRecord::BorrowingRecord(date d, string BookNum, string ID, int iType3, int BookType3)
{
    this->d = d;
    this->BookNum = BookNum;
    this->ID = ID;
    this->iType2 = iType1[iType3];
    this->BookType2 = BookType1[BookType3];
}

BorrowingRecord::BorrowingRecord()
{
    this->d = d;
    this->BookNum = "";
    this->ID = "";
    this->iType2 = iType1[0];
    this->BookType2 = BookType1[0];
}

ostream& operator<<(ostream& out, BorrowingRecord& br)
{
    out<< br.d << " " << br.BookNum << " " << br.ID << " " << br.iType2 << " " << br.BookType2<<endl;
    return out;
}

istream& operator>>(istream& in, BorrowingRecord& br)
{
    in>> br.d >> br.BookNum >> br.ID >> br.iType2 >> br.BookType2;
    return in;
}

//读者类:学号、姓名、专业、班级、已借图书数量;
class Reader
{
    string ID;
    string name;
    string major;
    string Class;
    int borSum=0;
    vector<BorrowingRecord> v;
    friend ostream& operator<<(ostream& out, Reader& r);
    friend istream& operator>>(istream& in, Reader& r);
public:
    Reader();
    Reader(string ID, string name, string major, string Class, int borSum);
    int GetborSum(){return this->borSum;};
    void SetborSum(int borSum){this->borSum=borSum;};
    string GetID() { return this->ID; };
    void SetID(string ID) { this->ID = ID; };
    bool operator==(const Reader& r)
    {
        if (this->ID == r.ID && this->name == r.name && this->major == r.major && this->Class == r.Class && this->borSum == r.borSum && this->v == r.v)
        {
            return true;
        }
        else return false;
    };
};

Reader::Reader(string ID, string name, string major, string Class, int borSum)
{
    this->ID = ID;
    this->name = name;
    this->major = major;
    this->Class = Class;
    this->borSum = borSum;
}

Reader::Reader()
{
    this->ID = "";
    this->name = "";
    this->major = "";
    this->Class = "";
    this->borSum = 0;
}

ostream& operator<<(ostream& out, Reader& r)
{
    out << " " << r.ID << " " << r.name << " " << r.major << " " << r.Class << " " << r.borSum << endl;
    return out;
}

istream& operator>>(istream& in, Reader& r)
{
    in>> r.ID>>r.name>>r.major>>r.Class>>r.borSum;
    return in;
}

//图书类:书号、书名、作者、出版社、出版日期、图书类型(基础/文学休闲/专业)、馆藏总量、在馆数量;
class Books
{
    string bookNum;
    string bookName;
    string bookAuthor;
    string press;
    date pressDate;
    string BookType2;
    int BookType3=0;
    int sum=0;
    int sumNow=0;
    friend ostream& operator<<(ostream& out, Books& bk);
    friend istream& operator>>(istream& in, Books& bk);
public:
    Books(){};
    Books(string bookNum, string bookName, string bookAuthor, string press, date pressDate, int BookType3, int sum, int sumNow);
    string GetbookNum(){return this->bookNum;};
    void SetbookNum(string bookNum){this->bookNum=bookNum;};
    string GetbookName(){return this->bookName;};
    void SetbookName(string bookName){this->bookName=bookName;};
    string GetbookAuthor(){return this->bookAuthor;};
    void SetbookAuthor(string bookAuthor){this->bookAuthor=bookAuthor;};
    string Getpress(){return this->press;};
    void Setpress(string press){this->press=press;};
    date GetpressDate(){return this->pressDate;};
    void SetpressDate(date pressDate){this->pressDate=pressDate;};
    string GetBookType2(){return this->BookType2;};
    void SetBookType2(int BookType3){this->BookType2 = BookType1[BookType3];};
    int GetBookType3(){return this->BookType3;};
    void SetBookType3(int BookType3){this->BookType3=BookType3;};
    int Getsum(){return this->sum;};
    void Setsum(int sum){this->sum=sum;};
    int GetsumNow(){return this->sumNow;};
    void SetsumNow(int sumNow){this->sumNow=sumNow;};

    bool operator==(const Books& bk)
    {
        if (this->bookNum == bk.bookNum && this->bookName == bk.bookName && this->bookAuthor == bk.bookAuthor && this->BookType2 == bk.BookType2
            && this->BookType3 == bk.BookType3 && this->sum == bk.sum && this->sumNow == bk.sumNow)
        {
            return true;
        }
        else return false;
    };
};

Books::Books(string bookNum, string bookName, string bookAuthor, string press, date pressDate, int BookType3, int sum, int sumNow)
{
    this->bookNum = bookNum;
    this->bookName = bookName;
    this->bookAuthor = bookAuthor;
    this->press = press;
    this->pressDate = pressDate;
    this->BookType2 = BookType1[BookType3];
    this->sum = sum;
    this->sumNow = sumNow;
}

ostream& operator<<(ostream& out, Books& bk)
{
    out << bk.bookNum << " " << bk.bookName << " " << bk.bookAuthor << " " << bk.press << " " << bk.pressDate
        << " " << bk.BookType2 << " " << bk.sum << " " << bk.sumNow << endl;
    return out;
}

istream& operator>>(istream& in, Books& bk)
{
    in >> bk.bookNum >> bk.bookName >> bk.bookAuthor >> bk.press >> bk.pressDate>> bk.BookType2 >> bk.sum >> bk.sumNow ;
    return in;
}

//日期类按照日期升序排序
class comapreDate
{
public://仿函数
    bool operator()(date a1, date a2)
    {
        if (a1.GetYear() == a2.GetYear())
        {
            if (a1.GetMonth() == a2.GetMonth())
            {
                return a1.GetDay() < a2.GetDay();
            }
            else return a1.GetMonth() < a2.GetMonth();
        }
        else return a1.GetYear() < a2.GetYear();
    }
};

//图书借阅操作类
class BRoperation
{
    multimap<string,int> mbr1;//书号
    multimap<string,int> mbr2;//学号
    multimap<date, int,comapreDate> mbr3;//日期
public:
    vector<BorrowingRecord> vbr;
    BRoperation()
    {
        BRopIs();
    };
    BRoperation(BorrowingRecord r)
    {
        vbr.push_back(r);
        BRopIs();
    };
    ~BRoperation()
    {
        BRopOs();
    };
    void BRopOs();//文件读出
    void BRopIs();//文件写入
    void BRopAdd(BorrowingRecord br1);//添加一条借阅记录
    void BRopQuery1(date d);//按照日期查询
    void BRopQuery2(date d1,date d2);//按照时间范围查询
    void BRopQuery3(string BookNum);//按照书号查询
    void BRopQuery4(string ID);//按照学号查询
};

void BRoperation::BRopQuery1(date d)
{
    multimap<date, int,comapreDate>::iterator it=mbr3.find(d);
    if(it!=mbr3.end())
    {
         cout << vbr[it->second]<<endl;
    }
}

void BRoperation::BRopQuery2(date d1,date d2)
{
    multimap<date, int,comapreDate>::iterator it1,it2,it;
    it1=mbr3.lower_bound(d1);
    it2=mbr3.upper_bound(d2);
    for(it=it1;it!=it2;it++)
    {
        cout<<vbr[it->second]<<endl;
    }
}

void BRoperation::BRopQuery3(string BookNum)
{
    multimap<string,int>::iterator it=mbr1.find(BookNum);
    if(it!=mbr1.end())
    {
        cout << vbr[it->second]<<endl;
    }
}

void BRoperation::BRopQuery4(string ID)
{
    multimap<string,int>::iterator it=mbr2.find(ID);
    if(it!=mbr2.end())
    {
        cout << vbr[it->second]<<endl;
    }
}

void BRoperation::BRopOs()
{
    ofstream ofs;
    ofs.open("record.txt", ios::out);
    for (vector<BorrowingRecord>::iterator it = this->vbr.begin(); it != this->vbr.end(); it++)
    {
        ofs << (*it) << endl;
    }cout << endl;
    ofs.close();
}

void BRoperation::BRopIs()
{
    BorrowingRecord record;
    ifstream ifs;
    ifs.open("record.txt", ios::in);
    if (!ifs.is_open())
    {
        return;
    }
    while(ifs>>record)
    {
        vbr.push_back(record);
        mbr1.insert(make_pair(record.GetBookNum(),vbr.size()-1));
        mbr2.insert(make_pair(record.GetID(),vbr.size()-1));
        mbr3.insert(make_pair(record.GetDate(),vbr.size()-1));
    }
    ifs.close();
}

void BRoperation::BRopAdd(BorrowingRecord br1)
{
    vbr.push_back(br1);
    mbr1.insert(make_pair(br1.GetBookNum(),vbr.size()-1));
    mbr2.insert(make_pair(br1.GetID(),vbr.size()-1));
    mbr3.insert(make_pair(br1.GetDate(),vbr.size()-1));
}

//操作类
class operation
{
    vector<Books> vbk;
    Reader r;
    date d;
    basic bc;
    multimap<string, int> mbk1;//图书类:按书号查找
    multimap<date, int,comapreDate> mbk2;//图书类:按出版日期查找
    multimap<string, int> mbk3;//图书类:按书名查找
    multimap<string, int> mbk4;//图书类:按图书类型查找
    multimap<string, int> mbk5;//图书类:按作者查找
    multimap<string, int> mbk6;//图书类:按出版社查找
public:
    BRoperation brop;
    operation(Reader r,date d);
    void bookInsert(Books& b);//添加一本书

    //按书名、书号、出版社、出版日期查询图书;
    void query01(string bookName);
    int query02(string bookNum);
    void query03(string press);
    void query04(date d);

    //按书名模糊查询图书;
    void query05(string bookName);

    //按书名+作者、出版社+作者查询图书;
    void query06(string bookName,string bookAuthor);
    void query07(string press,string bookAuthor);

    //输入起止出版日期,查询指定时间段出版的图书;
    void query08(date d1,date d2);

    //按书号查询图书借阅情况;
    void query09(string bookNum);

    // 按时间段/图书类型查询本人的借阅情况;
    void query10(date d1,date d2);
    void query11(string BookType2);

    void BorrowBook(string bookNum);//借书;
    void RenewBook(string bookNum);//续借;
    void ReturnBook(string bookNum);//还书;

    //显示本人的图书借阅信息;
    void Display(string name);
};

operation::operation(Reader r,date d)
{
    this->r=r;
    this->d=d;
}

void operation::bookInsert(Books& b1)
{
    multimap<string,int>::iterator it=mbk1.find(b1.GetbookNum());
    if(it==mbk1.end())
    {
        b1.Setsum(b1.Getsum()+1);
        b1.SetsumNow(b1.GetsumNow()+1);
        vbk.push_back(b1);
        mbk1.insert(make_pair(b1.GetbookNum(),vbk.size()-1));
        mbk2.insert(make_pair(b1.GetpressDate(),vbk.size()-1));
        mbk3.insert(make_pair(b1.GetbookName(),vbk.size()-1));
        mbk4.insert(make_pair(b1.GetBookType2(),vbk.size()-1));
        mbk5.insert(make_pair(b1.GetbookAuthor(),vbk.size()-1));
        mbk6.insert(make_pair(b1.Getpress(),vbk.size()-1));
    }
    else
    {
        b1.Setsum(vbk[it->second].Getsum()+1);
        b1.SetsumNow(vbk[it->second].GetsumNow()+1);
        vbk[it->second]=b1;
    }
}

void operation::query01(string bookName)
{
    multimap<string,int>::iterator it=mbk3.find(bookName);
    if(it==mbk3.end())
    {
        return;
    }
    else
    {
        cout<<vbk[it->second]<<endl;
    }
}

int operation::query02(string bookNum)
{
    multimap<string,int>::iterator it=mbk1.find(bookNum);
    if(it==mbk1.end())
    {
        return -1;
    }
    else
    {
        cout<<vbk[it->second]<<endl;
        return it->second;
    }
}

void operation::query03(string press)
{
    multimap<string,int>::iterator it=mbk6.find(press);
    if(it==mbk6.end())
    {
        return;
    }
    else
    {
        cout<<vbk[it->second]<<endl;
    }
}

void operation::query04(date d)
{
    multimap<date, int,comapreDate>::iterator it=mbk2.find(d);
    if(it==mbk2.end())
    {
        return;
    }
    else
    {
        cout<<vbk[it->second]<<endl;
    }
}

void operation::query05(string bookName)
{
    for(multimap<string,int>::iterator it=mbk3.begin();it!=mbk3.end();it++)
    {
        string m=it->first;
        int a=it->second;int k=0;
        for (int i=0;i<m.size();i++)
        {
            for(int j=0;j<bookName.size();j++)
            {
                if(m[i]==bookName[j]) k++;
            }
        }
        if(k>=bookName.size())
        {
            cout<<vbk[it->second]<<endl;
        }
    }
}

void operation::query06(string bookName,string bookAuthor)
{
    for(vector<Books>::iterator it=vbk.begin();it!=vbk.end();it++)
    {
        if((*it).GetbookName()==bookName&&(*it).GetbookAuthor()==bookAuthor)
        {
            cout<<(*it)<<endl;
        }
    }
}

void operation::query07(string press,string bookAuthor)
{
    for(vector<Books>::iterator it=vbk.begin();it!=vbk.end();it++)
    {
        if((*it).Getpress()==press&&(*it).GetbookAuthor()==bookAuthor)
        {
            cout<<(*it)<<endl;
        }
    }
}

void operation::query08(date d1,date d2)
{
    multimap<date, int,comapreDate>::iterator it1,it2,it;
    it1=mbk2.lower_bound(d1);
    it2=mbk2.upper_bound(d2);
    for(it=it1;it!=it2;it++)
    {
    cout<<vbk[it->second]<<endl;
    }
}

void operation::query09(string bookNum)
{
    for(vector<BorrowingRecord>::iterator it=brop.vbr.begin();it!=brop.vbr.end();it++)
    {
        if((*it).GetBookNum()==bookNum)
        {
            cout<<(*it)<<endl;
        }
    }
}

void operation::query10(date d1,date d2)
{
    for(vector<BorrowingRecord>::iterator it=brop.vbr.begin();it!=brop.vbr.end();it++)
    {
        if((*it).GetDate()>d1&&(*it).GetDate()<d2)
        {
            cout<<(*it)<<endl;
        }
    }
}

void operation::query11(string BookType2)
{
    for(vector<BorrowingRecord>::iterator it=brop.vbr.begin();it!=brop.vbr.end();it++)
    {
        if((*it).GetBookType2()==BookType2)
        {
            cout<<(*it)<<endl;
        }
    }
}

void operation::BorrowBook(string bookNum)
{
    int flag=0;
    if(r.GetborSum()<bc.GetMaxBorNum())
    {
        flag=1;
        r.SetborSum(r.GetborSum()+1);
    }
    for(vector<Books>::iterator it=this->vbk.begin();it!=this->vbk.end();it++)
    {
        if((*it).GetbookNum()==bookNum&&flag==1)
        {
            (*it).SetsumNow((*it).GetsumNow()-1);
            BorrowingRecord v1(this->d,bookNum,this->r.GetID(),1,(*it).GetBookType3());
            v1.SetBookType2((*it).GetBookType2());
            brop.vbr.push_back(v1);
            break;
        }
    }
}

void operation::ReturnBook(string bookNum)
{
    int flag=0;
    if(r.GetborSum()<bc.GetMaxBorNum())
    {
        flag=1;
        r.SetborSum(r.GetborSum()-1);
    }
    for(vector<Books>::iterator it=this->vbk.begin();it!=this->vbk.end();it++)
    {
        if((*it).GetbookNum()==bookNum&&flag==1)
        {
            (*it).SetsumNow((*it).GetsumNow()+1);
            BorrowingRecord v1(this->d,bookNum,this->r.GetID(),2,(*it).GetBookType3());
            v1.SetBookType2((*it).GetBookType2());
            brop.vbr.push_back(v1);
            break;
        }
    }
}

void operation::RenewBook(string bookNum)
{
    for(vector<Books>::iterator it=this->vbk.begin();it!=this->vbk.end();it++)
    {
        if((*it).GetbookNum()==bookNum)
        {
            BorrowingRecord v1(this->d,bookNum,this->r.GetID(),3,(*it).GetBookType3());
            v1.SetBookType2((*it).GetBookType2());
            brop.vbr.push_back(v1);
            break;
        }
    }
}

void operation::Display(string ID)
{
    for(vector<BorrowingRecord>::iterator it=brop.vbr.begin();it!=brop.vbr.end();it++)
    {
        if((*it).GetID()==ID)
        {
            cout<<(*it)<<endl;
        }
    }
}

void testDate()
{
    date d1(2020,10,10);
    cout<<d1<<endl;
    date d2=d1+100;
    cout<<d2<<endl;
}

void testBook()
{
    date d1(2018, 11, 28);
    Books bk1("ISBN-1234","三国演义","罗贯中","北京大学出版社",d1,2,300,20);
    cout<<bk1<<endl;
}

void testBRoperation()
{
    date d1(2019,10,15);
    date d2(2020,4,3);
    date d3(2021,10,11);
    date d4(2022,1,1);
    BorrowingRecord br1(d1,"ISBN-1234","2020215679",1,2);
    BorrowingRecord br2(d2,"ISBN-1235","2020215678",2,2);
    BorrowingRecord br3(d3,"ISBN-1236","2020215677",3,2);
    BorrowingRecord br4(d4,"ISBN-1237","2020215676",1,2);
    BRoperation brop1;
    brop1.BRopAdd(br1);
    brop1.BRopAdd(br2);
    brop1.BRopAdd(br3);
    brop1.BRopAdd(br4);
    brop1.BRopQuery1(d1);
    brop1.BRopQuery2(d1,d3);
    brop1.BRopQuery3("ISBN-1237");
    brop1.BRopQuery4("2020215679");
    cout<<"----------------"<<endl;
}

void testoperation()
{
    date d1(2019,10,15);
    date d2(2020,4,3);
    date d3(2021,10,11);
    date d4(2022,1,1);
    date d11(1999);
    date d12(2001);
    date d13(2015);
    date d14(2018);
    BorrowingRecord br1(d1,"ISBN-1234","2020215679",1,2);
    BorrowingRecord br2(d2,"ISBN-1235","2020215678",2,2);
    BorrowingRecord br3(d3,"ISBN-1236","2020215677",3,2);
    BorrowingRecord br4(d4,"ISBN-1237","2020215676",1,2);
    Books bk1("ISBN-111234","三国演义","罗贯中","北京大学出版社",d11,2,300,20);
    Books bk2("ISBN-111235","概率论与数理统计","张伟","高等教育出版社",d12,1,100,3);
    Books bk3("ISBN-111236","数学统计","李华","机械工业出版社",d13,3,230,10);
    Books bk4("ISBN-111237","假如给我三天光明","海伦凯勒","清华大学出版社",d14,2,800,750);
    Reader r1("2020211999","刘帆","材料化学","材料2班",3);
    date d21(2022,5,29);
    operation op(r1,d21);
    op.brop.BRopAdd(br1);
    op.brop.BRopAdd(br2);
    op.brop.BRopAdd(br3);
    op.brop.BRopAdd(br4);
    op.bookInsert(bk1);
    op.bookInsert(bk2);
    op.bookInsert(bk3);
    op.bookInsert(bk4);
    op.query01("数学统计");
    op.query02("ISBN-111237");
    op.query03("北京大学出版社");
    op.query04(d12);
    op.query05("统计");
    op.query06("数学统计","李华");
    op.query07("清华大学出版社","海伦凯勒");
    op.query08(d12,d13);
    op.query09("ISBN-1236");
    op.query10(d1,d3);
    op.query11("文学休闲");
    op.BorrowBook("ISBN-111234");
    op.ReturnBook("ISBN-111235");
    op.RenewBook("ISBN-111236");
    cout<<"----------------"<<endl;
    op.Display("2020211999");
    cout<<"----------------"<<endl;
}

int main()
{
    testDate();
    testBook();
    testBRoperation();
    testoperation();
}
#include<bits/stdc++.h>
#include<iostream>
#include<fstream>
#include<vector>
#include<map>
using namespace std;
//Bor:借阅记录,Re:读者记录,Bk:图书记录
string iType1[4] = { "","借出","还回","续借" };//操作类型:借出,还回,续借;
string BookType1[4] = { "","基础","文学休闲","专业" };//图书续借类型:基础,文学休闲,专业;


//基础类:读者最大借书量、最长借书时间(按天计算);
class basic
{
    int MaxBorNum=20;//最大借书量:20本
    int MaxBorTime=60;//最长借书时间:60天
public:
    int GetMaxBorNum(){return this->MaxBorNum;};
    void SetMaxBorNum(int MaxBorNum){this->MaxBorNum=MaxBorNum;};
    int GetMaxBorTime(){return this->MaxBorTime;};
    void SetMaxBorTime(int MaxBorTime){this->MaxBorTime=MaxBorTime;};
};

//日前类:包括年月日,重载输入运算符时,要进行数据的合法性检验;重载输出运算符时,按照“年/月/日”形式输出;重载+运算符;
class date
{
    int year;
    int month;
    int day;
    friend ostream& operator<<(ostream& out, date& d);
    friend istream& operator>>(istream& in, date& d);
public:
    date(int year, int month, int day);
    date();
    date(int year)
    {
        this->year=year;
        this->month=0;
        this->day=0;
    }
    int GetYear() { return this->year; };
    void SetYear(int year) { this->year = year; };
    int GetMonth() { return this->month; };
    void SetMonth(int month) { this->month = month; };
    int GetDay() { return this->day; };
    void SetDay(int day) { this->day = day; };
    bool operator==(const date& d);
    date& operator+(int day);
    bool operator<(date d);
    bool operator>(date d);
};

date::date(int year, int month, int day)
{
    this->year = year;
    this->month = month;
    this->day = day;
}

date::date()
{
    this->year = 0;
    this->month = 0;
    this->day = 0;
}

ostream& operator<<(ostream& out, date& d)
{
    if(d.GetYear()==0||d.GetDay()==0)
    {
        out<<d.year;
    }else
    {
        out << d.year << "/" << d.month << "/" << d.day;
    }
    return out;
}

istream& operator>>(istream& in, date& d)
{
    int year,month,day;
    char op;int flag=0;
    while(in>>year>>op>>month>>op>>day)
    {
        if (d.year >= 1900 && d.year <= 2022 && d.month >= 1 && d.month <= 12)
        {
            if ((d.month == 1 || d.month == 3 || d.month == 5 || d.month == 7 || d.month == 8 || d.month == 10 || d.month == 12) && (d.day >= 1 && d.day <= 31))
            {
                flag=1;
            }
            else if ((d.month == 4 || d.month == 6 || d.month == 9 || d.month == 11) && d.day >= 1 && d.day <= 30)
            {
                flag=1;
            }
            else if (d.month == 2)
            {
                if (((d.year % 4 == 0 && d.year % 100 != 0) || (d.year % 400 == 0)) && (d.day >= 1 && d.year <= 29))
                {
                    flag=1;
                }
                else if (d.day >= 1 && d.day <= 28)
                {
                    flag=1;
                }
            }
            if(flag==1)
            {
                d.SetYear(year);
                d.SetMonth(month);
                d.SetDay(day);
            }
        }
    }
    return in;
}

bool date::operator==(const date& d)
{
    if (d.day == this->day && d.month == this->month && d.year == this->year)
    {
        return true;
    }
    else return false;
}


bool date::operator<(date d)
{
    if(this->GetYear()==d.GetYear())
    {
        if(this->GetMonth()==d.GetMonth())
        {
            return this->GetDay()<d.GetDay();
        }
        else
            return this->GetMonth()<d.GetMonth();
    }
    else
        return this->GetYear()<d.GetYear();
}

bool date::operator>(date d)
{
    if(this->GetYear()==d.GetYear())
    {
        if(this->GetMonth()==d.GetMonth())
        {
            return this->GetDay()>d.GetDay();
        }
        else
            return this->GetMonth()>d.GetMonth();
    }
    else
        return this->GetYear()>d.GetYear();
}

date& date::operator+(int day)
{
    int month[]={0,31,28,31,30,31,30,31,31,30,31,30,31};
    int x=0;
    while(x<day)
    {
        x++;
        if(this->GetMonth()==12)
        {
            if(this->GetDay()==month[this->GetMonth()])
            {
                this->SetYear(this->GetYear()+1);
                this->SetMonth(1);
                this->SetDay(1);
            }
            else
            {
                this->SetDay(this->GetDay()+1);
            }
        }
        else if(this->GetMonth()!=2)
        {
            if(this->GetDay()==month[this->GetMonth()])
            {
                this->SetMonth(this->GetMonth()+1);
                this->SetDay(1);
            }
            else
            {
                this->SetDay(this->GetDay()+1);
            }
        }
        else if(this->GetMonth()==2)
        {
            if((this->year % 4 == 0 && this->year % 100 != 0) || (this->year % 400 == 0))
            {
                month[this->GetMonth()]=29;
            }
            if(this->GetDay()==month[this->GetMonth()])
            {
                this->SetMonth(this->GetMonth()+1);
                this->SetDay(1);
            }
            else
            {
                this->SetDay(this->GetDay()+1);
            }
        }
    }
    return *this;
}

//借阅记录类:包括日期、书号、读者学号、类型(借出/还回/续借)、图书类型(基础/文学休闲/专业);
class BorrowingRecord
{
    date d;
    string BookNum;
    string ID;
    string iType2;
    int iType3;
    string BookType2;
    int BookType3;
    friend ostream& operator<<(ostream& out, BorrowingRecord& br);
    friend istream& operator>>(istream& in, BorrowingRecord& br);
public:
    BorrowingRecord(date d, string BookNum, string ID, int iType3, int BookType3);
    BorrowingRecord();
    date GetDate() { return this->d; };
    void SetDate(date d) { this->d = d; };
    string GetBookNum() { return this->BookNum; };
    void SetBookNum(string BookNum) { this->BookNum = BookNum; };
    string GetID() { return this->ID; };
    void SetID(string ID) { this->ID = ID; };
    string GetiType2() { return this->iType2; };
    void SetiType2(int iType3) { this->iType2 = iType1[iType3]; };
    string GetBookType2() { return this->BookType2; };
    void SetBookType2(int BookType3) { this->BookType2 = BookType1[BookType3]; };
    bool operator==(const BorrowingRecord& br)
    {
        if (this->d == br.d && this->BookNum == br.BookNum && this->ID == br.ID && this->iType2 == br.iType2 && this->BookType2 == br.BookType2)
        {
            return true;
        }
        else return false;
    };
};

BorrowingRecord::BorrowingRecord(date d, string BookNum, string ID, int iType3, int BookType3)
{
    this->d = d;
    this->BookNum = BookNum;
    this->ID = ID;
    this->iType2 = iType1[iType3];
    this->BookType2 = BookType1[BookType3];
}

BorrowingRecord::BorrowingRecord()
{
    this->d = d;
    this->BookNum = "";
    this->ID = "";
    this->iType2 = iType1[0];
    this->BookType2 = BookType1[0];
}

ostream& operator<<(ostream& out, BorrowingRecord& br)
{
    out<< br.d << " " << br.BookNum << " " << br.ID << " " << br.iType2 << " " << br.BookType2<<endl;
    return out;
}

istream& operator>>(istream& in, BorrowingRecord& br)
{
    in>> br.d >> br.BookNum >> br.ID >> br.iType2 >> br.BookType2;
    return in;
}

//读者类:学号、姓名、专业、班级、已借图书数量;
class Reader
{
    string ID;
    string name;
    string major;
    string Class;
    int borSum;
    vector<BorrowingRecord> v;
    friend ostream& operator<<(ostream& out, Reader& r);
    friend istream& operator>>(istream& in, Reader& r);
public:
    Reader(string ID, string name, string major, string Class, int borSum);
    int GetborSum(){return this->borSum;};
    void SetborSum(int borSum){this->borSum=borSum;};
    string GetID() { return this->ID; };
    void SetID(string ID) { this->ID = ID; };
    bool operator==(const Reader& r)
    {
        if (this->ID == r.ID && this->name == r.name && this->major == r.major && this->Class == r.Class && this->borSum == r.borSum && this->v == r.v)
        {
            return true;
        }
        else return false;
    };
};

Reader::Reader(string ID, string name, string major, string Class, int borSum)
{
    this->ID = ID;
    this->name = name;
    this->major = major;
    this->Class = Class;
    this->borSum = borSum;
}

ostream& operator<<(ostream& out, Reader& r)
{
    out << " " << r.ID << " " << r.name << " " << r.major << " " << r.Class << " " << r.borSum << endl;
    return out;
}

istream& operator>>(istream& in, Reader& r)
{
    in>> r.ID>>r.name>>r.major>>r.Class>>r.borSum;
    return in;
}

//图书类:书号、书名、作者、出版社、出版日期、图书类型(基础/文学休闲/专业)、馆藏总量、在馆数量;
class Books
{
    string bookNum;
    string bookName;
    string bookAuthor;
    string press;
    date pressDate;
    string BookType2;
    int BookType3;
    int sum;
    int sumNow;
    friend ostream& operator<<(ostream& out, Books& bk);
    friend istream& operator>>(istream& in, Books& bk);
public:
    Books(){};
    Books(string bookNum, string bookName, string bookAuthor, string press, date pressDate, int BookType3, int sum, int sumNow);
    string GetbookNum(){return this->bookNum;};
    void SetbookNum(string bookNum){this->bookNum=bookNum;};
    string GetbookName(){return this->bookName;};
    void SetbookName(string bookName){this->bookName=bookName;};
    string GetbookAuthor(){return this->bookAuthor;};
    void SetbookAuthor(string bookAuthor){this->bookAuthor=bookAuthor;};
    string Getpress(){return this->press;};
    void Setpress(string press){this->press=press;};
    date GetpressDate(){return this->pressDate;};
    void SetpressDate(date pressDate){this->pressDate=pressDate;};
    string GetBookType2(){return this->BookType2;};
    void SetBookType2(int BookType3){this->BookType2 = BookType1[BookType3];};
    int GetBookType3(){return this->BookType3;};
    void SetBookType3(int BookType3){this->BookType3=BookType3;};
    int Getsum(){return this->sum;};
    void Setsum(int sum){this->sum=sum;};
    int GetsumNow(){return this->sumNow;};
    void SetsumNow(int sumNow){this->sumNow=sumNow;};

    bool operator==(const Books& bk)
    {
        if (this->bookNum == bk.bookNum && this->bookName == bk.bookName && this->bookAuthor == bk.bookAuthor && this->BookType2 == bk.BookType2
            && this->BookType3 == bk.BookType3 && this->sum == bk.sum && this->sumNow == bk.sumNow)
        {
            return true;
        }
        else return false;
    };
};

Books::Books(string bookNum, string bookName, string bookAuthor, string press, date pressDate, int BookType3, int sum, int sumNow)
{
    this->bookNum = bookNum;
    this->bookName = bookName;
    this->bookAuthor = bookAuthor;
    this->press = press;
    this->pressDate = pressDate;
    this->BookType2 = BookType1[BookType3];
    this->sum = sum;
    this->sumNow = sumNow;
}

ostream& operator<<(ostream& out, Books& bk)
{
    out << bk.bookNum << " " << bk.bookName << " " << bk.bookAuthor << " " << bk.press << " " << bk.pressDate
        << " " << bk.BookType2 << " " << bk.sum << " " << bk.sumNow << endl;
    return out;
}

istream& operator>>(istream& in, Books& bk)
{
    in >> bk.bookNum >> bk.bookName >> bk.bookAuthor >> bk.press >> bk.pressDate>> bk.BookType2 >> bk.sum >> bk.sumNow ;
    return in;
}


//日期类按照日期升序排序
class comapreDate
{
public://仿函数
    bool operator()(date a1, date a2)
    {
        if (a1.GetYear() == a2.GetYear())
        {
            if (a1.GetMonth() == a2.GetMonth())
            {
                return a1.GetDay() < a2.GetDay();
            }
            else return a1.GetMonth() < a2.GetMonth();
        }
        else return a1.GetYear() < a2.GetYear();
    }
};

//操作类
class operation
{
    vector<Books> vbk;
    multimap<string, int> mbk1;//图书类:按书号查找
    multimap<date, int,comapreDate> mbk2;//图书类:按出版日期查找
    multimap<string, int> mbk3;//图书类:按书名查找
    multimap<string, int> mbk4;//图书类:按图书类型查找
    multimap<string, int> mbk5;//图书类:按作者查找
public:
    ~operation()
    {
        bookOS();
    };
    operation(vector<Books> vbk);
    operation(Books bk1);
    void bookOS();//读文件
    void bookIS();//写文件
    void bookInsert(Books& b);//添加一本书
    void bookDel(string bookNum);//删除一本书:按书号
    void bookRenew();//重写借阅记录
    void bookfind_name(string n);//查找:按书名
    int bookfind_num(string n,int flag);//查找:按书号
    void bookfind_date(date d);//查找:按日期
    void bookfind_dateRange(date d1,date d2);//查找:按日期范围
    void book_update(string bookNum,Books b);//根据学号修改一本图书的信息
    void bookfind_vague(string n);//模糊查找:按照书名
    void FindNameAndAuthor(string bookName,string bookAuthor);//查找:按照书名和作者
    void FindPressAndAuthor(string press,string bookAuthor);//查找:按照出版社和作者
    void search_bookType(string bookType);//搜查:按照图书类型
    void search_bookAuthor(string Author);//搜查:按照作者
};

operation::operation(Books b1)
{
    vbk.push_back(b1);
    bookIS();
    mbk1.insert(make_pair(b1.GetbookNum(),vbk.size()-1));
    mbk2.insert(make_pair(b1.GetpressDate(),vbk.size()-1));
    mbk3.insert(make_pair(b1.GetbookName(),vbk.size()-1));
    mbk4.insert(make_pair(b1.GetBookType2(),vbk.size()-1));
    mbk5.insert(make_pair(b1.GetbookAuthor(),vbk.size()-1));
}

operation::operation(vector<Books> vbk)
{
    this->vbk=vbk;
    bookIS();
}

void operation::bookOS()
{
    fstream ofs("2020215679book.txt",ios::out);
    for(vector<Books>::iterator it=vbk.begin();it!=vbk.end();it++)
    {
        ofs<<*it;
    }
    ofs.close();
}

void operation::bookIS()
{
    Books book;
    ifstream ifs("2020215679book.txt",ios::in);
    if(!ifs) return;
    while(ifs>>book)
    {
        vbk.push_back(book);
        mbk1.insert(make_pair(book.GetbookNum(),vbk.size()-1));
        mbk2.insert(make_pair(book.GetpressDate(),vbk.size()-1));
        mbk3.insert(make_pair(book.GetbookName(),vbk.size()-1));
        mbk4.insert(make_pair(book.GetBookType2(),vbk.size()-1));
        mbk5.insert(make_pair(book.GetbookAuthor(),vbk.size()-1));
    }
}

void operation::bookInsert(Books& b1)
{
    multimap<string,int>::iterator it=mbk1.find(b1.GetbookNum());
    if(it==mbk1.end())
    {
        b1.Setsum(b1.Getsum()+1);
        b1.SetsumNow(b1.GetsumNow()+1);
        vbk.push_back(b1);
        mbk1.insert(make_pair(b1.GetbookNum(),vbk.size()-1));
        mbk2.insert(make_pair(b1.GetpressDate(),vbk.size()-1));
        mbk3.insert(make_pair(b1.GetbookName(),vbk.size()-1));
        mbk4.insert(make_pair(b1.GetBookType2(),vbk.size()-1));
        mbk5.insert(make_pair(b1.GetbookAuthor(),vbk.size()-1));
    }
    else
    {
        b1.Setsum(vbk[it->second].Getsum()+1);
        b1.SetsumNow(vbk[it->second].GetsumNow()+1);
        vbk[it->second]=b1;
    }
}

void operation::bookDel(string bookNum)
{
    int index=bookfind_num(bookNum,0);
    if(index!=-1)
    {
        vbk.erase(vbk.begin()+index);
        bookRenew();
    }
}

void operation::bookRenew()
{
    mbk1.clear();
    mbk2.clear();
    mbk3.clear();
    mbk4.clear();
    mbk5.clear();
    int index=0;
    for(vector<Books>::iterator it=vbk.begin();it!=vbk.end();it++)
    {
        index=it-vbk.begin();
        mbk1.insert(make_pair(it->GetbookNum(),index));
        mbk2.insert(make_pair(it->GetpressDate(),index));
        mbk3.insert(make_pair(it->GetbookName(),index));
        mbk4.insert(make_pair(it->GetBookType2(),index));
        mbk5.insert(make_pair(it->GetbookAuthor(),index));
    }
}

void operation::bookfind_name(string n)
{
    multimap<string,int>::iterator it=mbk3.find(n);
    if(it==mbk3.end())
    {
        return;
    }
    else
    {
        cout<<vbk[it->second]<<endl;
    }
}

int operation::bookfind_num(string n,int flag)
{
    multimap<string,int>::iterator it=mbk1.find(n);
    if(it==mbk1.end())
    {
        return -1;
    }
    else
    {
        cout<<vbk[it->second]<<endl;
        return it->second;
    }
}

void operation::bookfind_date(date d)
{
    multimap<date, int,comapreDate>::iterator it=mbk2.find(d);
    if(it==mbk2.end())
    {
        return;
    }
    else
    {
        cout<<vbk[it->second]<<endl;
    }
}

void operation::bookfind_dateRange(date d1,date d2)
{
     multimap<date, int,comapreDate>::iterator it1,it2,it;
     it1=mbk2.lower_bound(d1);
     it2=mbk2.upper_bound(d2);
     for(it=it1;it!=it2;it++)
     {
        cout<<vbk[it->second]<<endl;
     }
}

void operation::book_update(string bookNum,Books b)
{
    multimap<string,int>::iterator it=mbk1.find(bookNum);
    if(it==mbk1.end())
    {
        return;
    }
    else
    {
        vbk[it->second]=b;
        bookRenew();
    }
}

void operation::bookfind_vague(string n)
{
    for(multimap<string,int>::iterator it=mbk3.begin();it!=mbk3.end();it++)
    {
        string m=it->first;
        int a=it->second;int k=0;
        for (int i=0;i<m.size();i++)
        {
            for(int j=0;j<n.size();j++)
            {
                if(m[i]==n[j]) k++;
            }
        }
        if(k>=n.size())
        {
            cout<<vbk[it->second]<<endl;
        }
    }
}

void operation::FindNameAndAuthor(string bookName,string bookAuthor)
{
    for(vector<Books>::iterator it=vbk.begin();it!=vbk.end();it++)
    {
        if((*it).GetbookName()==bookName&&(*it).GetbookAuthor()==bookAuthor)
        {
            cout<<(*it)<<endl;
        }
    }
}

void operation::FindPressAndAuthor(string press,string bookAuthor)
{
    for(vector<Books>::iterator it=vbk.begin();it!=vbk.end();it++)
    {
        if((*it).Getpress()==press&&(*it).GetbookAuthor()==bookAuthor)
        {
            cout<<(*it)<<endl;
        }
    }
}

void operation::search_bookType(string bookType)
{
    for(vector<Books>::iterator it=vbk.begin();it!=vbk.end();it++)
    {
        if((*it).GetBookType2()==bookType)
        {
            cout<<(*it)<<endl;
        }
    }
}

void operation::search_bookAuthor(string Author)
{
    for(vector<Books>::iterator it=vbk.begin();it!=vbk.end();it++)
    {
        if((*it).GetbookAuthor()==Author)
        {
            cout<<(*it)<<endl;
        }
    }
}

//图书借阅操作类
class BRoperation
{
    vector<BorrowingRecord> vbr;
    multimap<string,int> mbr1;//书号
    multimap<string,int> mbr2;//学号
    multimap<date, int,comapreDate> mbr3;//日期

public:
    BRoperation()
    {
        BRopIs();
    };
    BRoperation(BorrowingRecord r)
    {
        vbr.push_back(r);
        BRopIs();
    };
    ~BRoperation()
    {
        BRopOs();
    };
    void BRopOs();//文件读出
    void BRopIs();//文件写入
    void BRopAdd(BorrowingRecord br1);//添加一条借阅记录
    void BRopQuery1(date d);//按照日期查询
    void BRopQuery2(date d1,date d2);//按照时间范围查询
    void BRopQuery3(string BookNum);//按照书号查询
    void BRopQuery4(string ID);//按照学号查询
};



void BRoperation::BRopQuery1(date d)
{
    multimap<date, int,comapreDate>::iterator it=mbr3.find(d);
    if(it!=mbr3.end())
    {
         cout << vbr[it->second]<<endl;
    }
}


void BRoperation::BRopQuery2(date d1,date d2)
{
    multimap<date, int,comapreDate>::iterator it1,it2,it;
    it1=mbr3.lower_bound(d1);
    it2=mbr3.upper_bound(d2);
    for(it=it1;it!=it2;it++)
    {
        cout<<vbr[it->second]<<endl;
    }
}

void BRoperation::BRopQuery3(string BookNum)
{
    multimap<string,int>::iterator it=mbr1.find(BookNum);
    if(it!=mbr1.end())
    {
        cout << vbr[it->second]<<endl;
    }
}

void BRoperation::BRopQuery4(string ID)
{
    multimap<string,int>::iterator it=mbr2.find(ID);
    if(it!=mbr2.end())
    {
        cout << vbr[it->second]<<endl;
    }
}

void BRoperation::BRopOs()
{
    ofstream ofs;
    ofs.open("2020215679record.txt", ios::out);
    for (vector<BorrowingRecord>::iterator it = this->vbr.begin(); it != this->vbr.end(); it++)
    {
        ofs << (*it) << endl;
    }cout << endl;
    ofs.close();
}

void BRoperation::BRopIs()
{
    BorrowingRecord record;
    ifstream ifs;
    ifs.open("2020215679record.txt", ios::in);
    if (!ifs.is_open())
    {
        return;
    }
    while(ifs>>record)
    {
        vbr.push_back(record);
        mbr1.insert(make_pair(record.GetBookNum(),vbr.size()-1));
        mbr2.insert(make_pair(record.GetID(),vbr.size()-1));
        mbr3.insert(make_pair(record.GetDate(),vbr.size()-1));
    }
    ifs.close();
}


void BRoperation::BRopAdd(BorrowingRecord br1)
{
    vbr.push_back(br1);
    mbr1.insert(make_pair(br1.GetBookNum(),vbr.size()-1));
    mbr2.insert(make_pair(br1.GetID(),vbr.size()-1));
    mbr3.insert(make_pair(br1.GetDate(),vbr.size()-1));

}

void testDate()
{
    date d1(2020,10,10);
    cout<<d1<<endl;
    date d2=d1+100;
    cout<<d2<<endl;
}

void testBook()
{
    date d1(2018, 11, 28);
    Books bk1("ISBN-1234","三国演义","罗贯中","北京大学出版社",d1,2,300,20);
    cout<<bk1<<endl;
}

void testRecod()
{
    date d1(2019,10,11);
    BorrowingRecord br1(d1,"ISBN-1234","2020215679",1,2);
    cout<<br1<<endl;
}

void testBRoperation()
{

    date d1(2019,10,15);
    date d2(2020,4,3);
    date d3(2021,10,11);
    date d4(2022,1,1);
    BorrowingRecord br1(d1,"ISBN-1234","2020215679",1,2);
    BorrowingRecord br2(d2,"ISBN-1235","2020215678",2,2);
    BorrowingRecord br3(d3,"ISBN-1236","2020215677",3,2);
    BorrowingRecord br4(d4,"ISBN-1237","2020215676",1,2);
    BRoperation brop1;
    brop1.BRopAdd(br1);
    brop1.BRopAdd(br2);
    brop1.BRopAdd(br3);
    brop1.BRopAdd(br4);
    brop1.BRopQuery1(d1);
    brop1.BRopQuery2(d1,d3);
    brop1.BRopQuery3("ISBN-1237");
    brop1.BRopQuery4("2020215679");
    cout<<endl;
}

void testOperation()
{
    date d1(2019,10,15);
    date d2(2020,4,3);
    date d3(2021,10,11);
    date d4(2022,1,1);
    date d11(1999);
    date d12(2001);
    date d13(2015);
    date d14(2018);
    BorrowingRecord br1(d1,"ISBN-1234","2020215679",1,2);
    BorrowingRecord br2(d2,"ISBN-1235","2020215678",2,2);
    BorrowingRecord br3(d3,"ISBN-1236","2020215677",3,2);
    BorrowingRecord br4(d4,"ISBN-1237","2020215676",1,2);
    Books bk1("ISBN-111234","三国演义","罗贯中","北京大学出版社",d11,2,300,20);
    Books bk2("ISBN-111235","概率论与数理统计","张伟","高等教育出版社",d12,1,100,3);
    Books bk3("ISBN-111236","数学统计","李华","机械工业出版社",d13,3,230,10);
    Books bk4("ISBN-111237","假如给我三天光明","海伦凯勒","清华大学出版社",d14,2,800,750);
    operation op(bk1);
    op.bookInsert(bk2);
    op.bookInsert(bk3);
    op.bookInsert(bk4);
    op.bookfind_date(d11);
    op.bookfind_dateRange(d11,d13);
    op.bookfind_name("数学统计");
    op.bookfind_num("ISBN-111237",0);
    op.bookfind_vague("三");
    op.FindNameAndAuthor("三国演义","罗贯中");
    op.FindPressAndAuthor("高等教育出版社","张伟");

    BRoperation brop1;
    brop1.BRopAdd(br1);
    brop1.BRopAdd(br2);
    brop1.BRopAdd(br3);
    brop1.BRopAdd(br4);
    brop1.BRopQuery1(d1);
    brop1.BRopQuery2(d1,d3);
    brop1.BRopQuery3("ISBN-1237");
    brop1.BRopQuery4("2020215679");
}

int main()
{
    testDate();
    testBook();
    testRecod();
    testBRoperation();
    testOperation();
    return 0;
}

#include<bits/stdc++.h>
#include<iostream>
#include<fstream>
#include<vector>
#include<map>
using namespace std;
//Bor:借阅记录,Re:读者记录,Bk:图书记录
string iType1[4] = { "","Lend","Return","Renew" };//操作类型:借出,还回,续借
string BookType1[4] = { "","Basics","LiteraryLeisure","Professional" };//图书类型:基础,文学休闲,专业

//基础类:读者最大借书量、最长借书时间(按天计算);
class basic
{
    int MaxBorNum=20;//最大借书量:20本
    int MaxBorTime=60;//最长借书时间:60天
public:
    int GetMaxBorNum(){return this->MaxBorNum;};
    void SetMaxBorNum(int MaxBorNum){this->MaxBorNum=MaxBorNum;};
    int GetMaxBorTime(){return this->MaxBorTime;};
    void SetMaxBorTime(int MaxBorTime){this->MaxBorTime=MaxBorTime;};
};

//日前类:包括年月日,重载输入运算符时,要进行数据的合法性检验;重载输出运算符时,按照“年/月/日”形式输出;重载+运算符;
class date
{
    int year;
    int month;
    int day;
    friend ostream& operator<<(ostream& out, date& d);
public:
    date(int year, int month, int day);
    date();
    int GetYear() { return this->year; };
    void SetYear(int year) { this->year = year; };
    int GetMonth() { return this->month; };
    void SetMonth(int month) { this->month = month; };
    int GetDay() { return this->day; };
    void SetDay(int day) { this->day = day; };
    bool operator==(const date& d);
    date& operator+(int day);
    bool operator<=(date d);
    bool operator>=(date d);
};

date::date(int year, int month, int day)
{
    this->year = year;
    this->month = month;
    this->day = day;
}

date::date()
{
    this->year = 0;
    this->month = 0;
    this->day = 0;
}

ostream& operator<<(ostream& out, date& d)
{
    if (d.year >= 2000 && d.year <= 2022 && d.month >= 1 && d.month <= 12)
    {
        if ((d.month == 1 || d.month == 3 || d.month == 5 || d.month == 7 || d.month == 8 || d.month == 10 || d.month == 12) && (d.day >= 1 && d.day <= 31))
        {
            out << d.year << "/" << d.month << "/" << d.day;
        }
        else if ((d.month == 4 || d.month == 6 || d.month == 9 || d.month == 11) && d.day >= 1 && d.day <= 30)
        {
            out << d.year << "/" << d.month << "/" << d.day;
        }
        else if (d.month == 2)
        {
            if (((d.year % 4 == 0 && d.year % 100 != 0) || (d.year % 400 == 0)) && (d.day >= 1 && d.year <= 29))
            {
                out << d.year << "/" << d.month << "/" << d.day;
            }
            else if (d.day >= 1 && d.day <= 28)
            {
                out << d.year << "/" << d.month << "/" << d.day;
            }
            else  out << "Date input error!";
        }
        else  out << "Date input error!";
    }
    else  out << "Date input error!";
    return out;
}

bool date::operator==(const date& d)
{
    if (d.day == this->day && d.month == this->month && d.year == this->year)
    {
        return true;
    }
    else return false;
}

bool date::operator<=(date d)
{
    if(this->GetYear()==d.GetYear())
    {
        if(this->GetMonth()==d.GetMonth())
        {
            return this->GetDay()<=d.GetDay();
        }
        else
            return this->GetMonth()<=d.GetMonth();
    }
    else
        return this->GetYear()<=d.GetYear();
}

bool date::operator>=(date d)
{
    if(this->GetYear()==d.GetYear())
    {
        if(this->GetMonth()==d.GetMonth())
        {
            return this->GetDay()>=d.GetDay();
        }
        else
            return this->GetMonth()>=d.GetMonth();
    }
    else
        return this->GetYear()>=d.GetYear();
}

date& date::operator+(int day)
{
    int month[]={0,31,28,31,30,31,30,31,31,30,31,30,31};
    int x=0;
    while(x<day)
    {
        x++;
        if(this->GetMonth()==12)
        {
            if(this->GetDay()==month[this->GetMonth()])
            {
                this->SetYear(this->GetYear()+1);
                this->SetMonth(1);
                this->SetDay(1);
            }
            else
            {
                this->SetDay(this->GetDay()+1);
            }
        }
        else if(this->GetMonth()!=2)
        {
            if(this->GetDay()==month[this->GetMonth()])
            {
                this->SetMonth(this->GetMonth()+1);
                this->SetDay(1);
            }
            else
            {
                this->SetDay(this->GetDay()+1);
            }
        }
        else if(this->GetMonth()==2)
        {
            if((this->year % 4 == 0 && this->year % 100 != 0) || (this->year % 400 == 0))
            {
                month[this->GetMonth()]=29;
            }
            if(this->GetDay()==month[this->GetMonth()])
            {
                this->SetMonth(this->GetMonth()+1);
                this->SetDay(1);
            }
            else
            {
                this->SetDay(this->GetDay()+1);
            }
        }
    }
    return *this;
}

//借阅记录类:包括日期、书号、读者学号、类型(借出/还回/续借)、图书类型(基础/文学休闲/专业);
class BorrowingRecord
{
    date d;
    string BookNum;
    string ID;
    string iType2;
    int iType3;
    string BookType2;
    int BookType3;
    friend ostream& operator<<(ostream& out, BorrowingRecord& br);
public:
    BorrowingRecord(date d, string BookNum, string ID, int iType3, int BookType3);
    BorrowingRecord();
    date GetDate() { return this->d; };
    void SetDate(date d) { this->d = d; };
    string GetBookNum() { return this->BookNum; };
    void SetBookNum(string BookNum) { this->BookNum = BookNum; };
    string GetID() { return this->ID; };
    void SetID(string ID) { this->ID = ID; };
    string GetiType2() { return this->iType2; };
    void SetiType2(int iType3) { this->iType2 = iType1[iType3]; };
    string GetBookType2() { return this->BookType2; };
    void SetBookType2(int BookType3) { this->BookType2 = BookType1[BookType3]; };
    bool operator==(const BorrowingRecord& br)
    {
        if (this->d == br.d && this->BookNum == br.BookNum && this->ID == br.ID && this->iType2 == br.iType2 && this->BookType2 == br.BookType2)
        {
            return true;
        }
        else return false;
    };
};

BorrowingRecord::BorrowingRecord(date d, string BookNum, string ID, int iType3, int BookType3)
{
    this->d = d;
    this->BookNum = BookNum;
    this->ID = ID;
    this->iType2 = iType1[iType3];
    this->BookType2 = BookType1[BookType3];
}

BorrowingRecord::BorrowingRecord()
{
    this->d = d;
    this->BookNum = "";
    this->ID = "";
    this->iType2 = iType1[0];
    this->BookType2 = BookType1[0];
}

ostream& operator<<(ostream& out, BorrowingRecord& br)
{
    out << "BorDate:" << br.d << " BorBookNum:" << br.BookNum << " BorReaderID:" << br.ID << " BorType:" << br.iType2 << " BorBookType:" << br.BookType2;
    return out;
}


//读者类:学号、姓名、专业、班级、已借图书数量;
class Reader
{
    string ID;
    string name;
    string major;
    string Class;
    int borSum;
    vector<BorrowingRecord> v;
    friend ostream& operator<<(ostream& out, Reader& br);
public:
    Reader(string ID, string name, string major, string Class, int borSum);
    int GetborSum(){return this->borSum;};
    void SetborSum(int borSum){this->borSum=borSum;};
    string GetID() { return this->ID; };
    void SetID(string ID) { this->ID = ID; };
    bool operator==(const Reader& r)
    {
        if (this->ID == r.ID && this->name == r.name && this->major == r.major && this->Class == r.Class && this->borSum == r.borSum && this->v == r.v)
        {
            return true;
        }
        else return false;
    };
};

Reader::Reader(string ID, string name, string major, string Class, int borSum)
{
    this->ID = ID;
    this->name = name;
    this->major = major;
    this->Class = Class;
    this->borSum = borSum;
}

ostream& operator<<(ostream& out, Reader& r)
{
    out << "ReaderID:" << r.ID << " ReaderName:" << r.name << " ReaderMajor:" << r.major << " ReaderClass:" << r.Class << " ReaderBorSum:" << r.borSum << endl;
    return out;
}


//图书类:书号、书名、作者、出版社、出版日期、图书类型(基础/文学休闲/专业)、馆藏总量、在馆数量;
class Books
{
    string bookNum;
    string bookName;
    string bookAuthor;
    string press;
    date pressDate;
    string BookType2;
    int BookType3;
    int sum;
    int sumNow;
    vector<BorrowingRecord> v;
    friend ostream& operator<<(ostream& out, Books& bk);
public:
    Books(string bookNum, string bookName, string bookAuthor, string press, date pressDate, int BookType3, int sum, int sumNow);
    string GetbookNum(){return this->bookNum;};
    void SetbookNum(string bookNum){this->bookNum=bookNum;};
    string GetbookName(){return this->bookName;};
    void SetbookName(string bookName){this->bookName=bookName;};
    string GetbookAuthor(){return this->bookAuthor;};
    void SetbookAuthor(string bookAuthor){this->bookAuthor=bookAuthor;};
    string Getpress(){return this->press;};
    void Setpress(string press){this->press=press;};
    date GetpressDate(){return this->pressDate;};
    void SetpressDate(date pressDate){this->pressDate=pressDate;};
    string GetBookType2(){return this->BookType2;};
    void SetBookType2(int BookType3){this->BookType2 = BookType1[BookType3];};
    int GetBookType3(){return this->BookType3;};
    void SetBookType3(int BookType3){this->BookType3=BookType3;};
    int Getsum(){return this->sum;};
    void Setsum(int sum){this->sum=sum;};
    int GetsumNow(){return this->sumNow;};
    void SetsumNow(int sumNow){this->sumNow=sumNow;};

    bool operator==(const Books& bk)
    {
        if (this->bookNum == bk.bookNum && this->bookName == bk.bookName && this->bookAuthor == bk.bookAuthor && this->BookType2 == bk.BookType2
            && this->BookType3 == bk.BookType3 && this->sum == bk.sum && this->sumNow == bk.sumNow && this->v == bk.v)
        {
            return true;
        }
        else return false;
    };
};

Books::Books(string bookNum, string bookName, string bookAuthor, string press, date pressDate, int BookType3, int sum, int sumNow)
{
    this->bookNum = bookNum;
    this->bookName = bookName;
    this->bookAuthor = bookAuthor;
    this->press = press;
    this->pressDate = pressDate;
    this->BookType2 = BookType1[BookType3];
    this->sum = sum;
    this->sumNow = sumNow;
}

ostream& operator<<(ostream& out, Books& bk)
{
    out << "BooksNum:" << bk.bookNum << " BooksName:" << bk.bookName << " BooksAuthor:" << bk.bookAuthor << " BooksPress:" << bk.press << " BooksPressDate:" << bk.pressDate
        << " BooksType:" << bk.BookType2 << " BooksSum:" << bk.sum << " BooksSumNow:" << bk.sumNow << endl;
    return out;
}

//操作类
class operation
{
    vector<Books> vbk;
    string ID;
    date d;
    basic bc;
public:
    operation(vector<Books>& vbk,string ID,date d);
    //按书名、书号、出版社、出版日期查询图书;
    void query01(string bookName);
    void query02(string bookNum);
    void query03(string press);
    void query04(date d);

    //按书名模糊查询图书;
    void query05(string bookName);

    //按书名+作者、出版社+作者查询图书;
    void query06(string bookName,string bookAuthor);
    void query07(string press,string bookAuthor);

    //输入起止出版日期,查询指定时间段出版的图书;
    void query08(date da,date d2);

    //按书号查询图书借阅情况;
    void query09(vector<BorrowingRecord>& vbr,string bookNum);

    // 按时间段/图书类型查询本人的借阅情况;
    void query10(vector<BorrowingRecord>& vbr,date d1,date d2);
    void query11(vector<BorrowingRecord>& vbr,string BookType2);

    void BorrowBook(vector<BorrowingRecord>& vbr,vector<Reader>& vr,string bookNum);//借书;
    void RenewBook(vector<BorrowingRecord>& vbr,string bookNum);//续借;
    void ReturnBook(vector<BorrowingRecord>& vbr,string bookNum);//还书;

    //显示本人的图书借阅信息;
    void Display(vector<BorrowingRecord>& vbr,string name);
};

operation::operation(vector<Books>& vbk,string ID,date d)
{
    this->vbk=vbk;
    this->ID=ID;
    this->d=d;
}

void operation::query01(string bookName)
{
    cout<<"Query bookName:"<<endl;
    for(vector<Books>::iterator it=this->vbk.begin();it!=this->vbk.end();it++)
    {
        if((*it).GetbookName()==bookName)
        {
            cout<<(*it)<<endl;
        }
    }
}

void operation::query02(string bookNum)
{
    cout<<"Query bookNum:"<<endl;
    for(vector<Books>::iterator it=this->vbk.begin();it!=this->vbk.end();it++)
    {
        if((*it).GetbookNum()==bookNum)
        {
            cout<<(*it)<<endl;
        }
    }
}

void operation::query03(string press)
{
    cout<<"Query press:"<<endl;
    for(vector<Books>::iterator it=this->vbk.begin();it!=this->vbk.end();it++)
    {
        if((*it).Getpress()==press)
        {
            cout<<(*it)<<endl;
        }
    }
}

void operation::query04(date d)
{
    cout<<"Query date:"<<endl;
    for(vector<Books>::iterator it=this->vbk.begin();it!=this->vbk.end();it++)
    {
        if((*it).GetpressDate()==d)
        {
            cout<<(*it)<<endl;
        }
    }
}

void operation::query05(string bookName)
{
    cout<<"Query FuzzybookName:"<<endl;
    for(vector<Books>::iterator it=this->vbk.begin();it!=this->vbk.end();it++)
    {
        int pos=(*it).GetbookName().find(bookName);
        if(pos!=-1)
        {
            cout<<(*it)<<endl;
        }
    }
}

void operation::query06(string bookName,string bookAuthor)
{
    cout<<"Query bookName AND bookAuthor:"<<endl;
    for(vector<Books>::iterator it=this->vbk.begin();it!=this->vbk.end();it++)
    {
        if((*it).GetbookName()==bookName&&(*it).GetbookAuthor()==bookAuthor)
        {
            cout<<(*it)<<endl;
        }
    }
}

void operation::query07(string press,string bookAuthor)
{
    cout<<"Query press AND bookAuthor:"<<endl;
    for(vector<Books>::iterator it=this->vbk.begin();it!=this->vbk.end();it++)
    {
        if((*it).Getpress()==press&&(*it).GetbookAuthor()==bookAuthor)
        {
            cout<<(*it)<<endl;
        }
    }
}

void operation::query08(date d1,date d2)
{
    cout<<"Query BeginDate AND EndDate:"<<endl;
    for(vector<Books>::iterator it=this->vbk.begin();it!=this->vbk.end();it++)
    {
        if((*it).GetpressDate()>=d1&&(*it).GetpressDate()<=d2)
        {
            cout<<(*it)<<endl;
        }
    }
}

void operation::query09(vector<BorrowingRecord>& vbr,string bookNum)
{
    cout<<"Query BR bookNum:"<<endl;
    for(vector<BorrowingRecord>::iterator it=vbr.begin();it!=vbr.end();it++)
    {
        if((*it).GetBookNum()==bookNum)
        {
            cout<<(*it)<<endl;
        }
    }
}

void operation::query10(vector<BorrowingRecord>& vbr,date d1,date d2)
{
    cout<<"Query BR BeginDate AND EndDate:"<<endl;
    for(vector<BorrowingRecord>::iterator it=vbr.begin();it!=vbr.end();it++)
    {
        if((*it).GetDate()>=d1&&(*it).GetDate()<=d2)
        {
            cout<<(*it)<<endl;
        }
    }
}

void operation::query11(vector<BorrowingRecord>& vbr,string BookType2)
{
    cout<<"Query BR BookType:"<<endl;
    for(vector<BorrowingRecord>::iterator it=vbr.begin();it!=vbr.end();it++)
    {
        if((*it).GetBookType2()==BookType2)
        {
            cout<<(*it)<<endl;
        }
    }
}

void operation::BorrowBook(vector<BorrowingRecord>& vbr,vector<Reader>& vr,string bookNum)
{
    int flag=0;
    for(vector<BorrowingRecord>::iterator it1=vbr.begin();it1!=vbr.end();it1++)
    {
        for(vector<Reader>::iterator it2=vr.begin();it2!=vr.end();it2++)
        {
            if((*it1).GetID()==(*it2).GetID()&&(*it2).GetborSum()<bc.GetMaxBorNum())
            {
                flag=1;
                (*it2).SetborSum((*it2).GetborSum()+1);
                break;
            }
        }
    }
    for(vector<Books>::iterator it=this->vbk.begin();it!=this->vbk.end();it++)
    {
        if(flag==1)
        {
            (*it).SetsumNow((*it).GetsumNow()-1);
            BorrowingRecord v1(this->d,(*it).GetbookNum(),this->ID,1,(*it).GetBookType3());
            vbr.push_back(v1);
        }
    }
}

void operation::RenewBook(vector<BorrowingRecord>& vbr,string bookNum)
{
    for(vector<Books>::iterator it=this->vbk.begin();it!=this->vbk.end();it++)
    {
        if((*it).GetbookNum()==bookNum)
        {
            (*it).SetsumNow((*it).GetsumNow()+1);
            BorrowingRecord v1(this->d,(*it).GetbookNum(),this->ID,2,(*it).GetBookType3());
            vbr.push_back(v1);
        }
    }
}

void operation::ReturnBook(vector<BorrowingRecord>& vbr,string bookNum)
{
    for(vector<Books>::iterator it=this->vbk.begin();it!=this->vbk.end();it++)
    {
        if((*it).GetbookNum()==bookNum)
        {
            BorrowingRecord v1(this->d,(*it).GetbookNum(),this->ID,3,(*it).GetBookType3());
            vbr.push_back(v1);
        }
    }
}

void operation::Display(vector<BorrowingRecord>& vbr,string ID)
{
    for(vector<BorrowingRecord>::iterator it=vbr.begin();it!=vbr.end();it++)
    {
        if((*it).GetID()==ID)
        {
            cout<<(*it)<<endl;
        }
    }
}

//图书借阅操作类
class BRoperation
{
    vector<BorrowingRecord> vbr;
public:
    BRoperation(vector<BorrowingRecord>& vbr)
    {
        this->vbr = vbr;
    };
    ~BRoperation()
    {
        vbr.clear();
    };
    void BRopQuery1(date d);//按照日期查询
    void BRopQuery2(string ID);//按照学号查询
    void BRopQuery3(string BookNum);//按照书号查询
    void BRopQuery4(string BookType2);//按照图书类型查询
    void BRopOs();//文件读出
    void BRopIs();//文件写入
    void BRopAdd(BorrowingRecord br1);//添加一条借阅记录
};


void BRoperation::BRopQuery1(date d)
{
    cout << "QueryDate:" << endl;
    for (vector<BorrowingRecord>::iterator it = this->vbr.begin(); it != this->vbr.end(); it++)
    {
        if ((*it).GetDate() == d)
        {
            cout << (*it) << endl;
        }
    }
}


void BRoperation::BRopQuery2(string ID)
{
    cout << "QueryID:" << endl;
    for (vector<BorrowingRecord>::iterator it = this->vbr.begin(); it != this->vbr.end(); it++)
    {
        if ((*it).GetID() == ID)
        {
            cout << (*it) << endl;
        }
    }
}

void BRoperation::BRopQuery3(string BookNum)
{
    cout << "QueryBookNum:" << endl;
    for (vector<BorrowingRecord>::iterator it = this->vbr.begin(); it != this->vbr.end(); it++)
    {
        if ((*it).GetBookNum() == BookNum)
        {
            cout << (*it) << endl;
        }
    }
}

void BRoperation::BRopQuery4(string BookType2)
{
    cout << "QueryBookType:" << endl;
    for (vector<BorrowingRecord>::iterator it = this->vbr.begin(); it != this->vbr.end(); it++)
    {
        if ((*it).GetBookType2() == BookType2)
        {
            cout << (*it) << endl;
        }
    }
}

void BRoperation::BRopOs()
{
    ofstream ofs;
    ofs.open("record.txt", ios::out);
    for (vector<BorrowingRecord>::iterator it = this->vbr.begin(); it != this->vbr.end(); it++)
    {
        ofs << (*it) << endl;
    }cout << endl;
}

void BRoperation::BRopIs()
{
    ifstream ifs;
    ifs.open("record.txt", ios::in);
    if (!ifs.is_open())
    {
        cout << "文件打开失败" << endl;
        return;
    }
    char c;
    while ((c = ifs.get()) != EOF)
    {
        cout << c;
    }

    ifs.close();
}


void BRoperation::BRopAdd(BorrowingRecord br1)
{
    this->vbr.push_back(br1);
}

int main()
{
    vector<BorrowingRecord> vbr;
    date d1(2011,9,10);
    Books bk1("111","三国演义","罗贯中","北京大学出版社",d1,2,300,200);

    date d2(2018,12,1);
    Books bk2("222","水浒传","施耐庵","中国华侨出版社",d2,2,500,150);

    date d3(2017,6,25);
    Books bk3("333","C++程序设计基础","林伟健","电子工业出版社",d3,3,1000,500);

    date d4(2019,8,16);
    Books bk4("444","高等数学基础","杨中兵","高等教育出版社",d4,1,2000,50);
    vector<Books> bk;
    bk.push_back(bk1);
    bk.push_back(bk2);
    bk.push_back(bk3);
    bk.push_back(bk4);

    date d11(2019,10,11);
    BorrowingRecord br1(d11,"111","1",1,2);
    date d12(2019,11,15);
    BorrowingRecord br2(d12,"222","2",1,2);
    date d13(2019,12,7);
    BorrowingRecord br3(d13,"111","1",2,2);
    date d14(2020,1,1);
    BorrowingRecord br4(d14,"333","3",1,3);
    date d15(2020,1,10);
    BorrowingRecord br5(d15,"222","2",2,2);
    date d16(2020,5,15);
    BorrowingRecord br6(d16,"444","4",1,1);
    vbr.push_back(br1);
    vbr.push_back(br2);
    vbr.push_back(br3);
    vbr.push_back(br4);
    vbr.push_back(br5);
    vbr.push_back(br6);

    vector<Reader> vr;
    Reader r1("1","赵巍","计算机科学与技术","计算机四班",15);
    Reader r2("2","刘帆","材料化学","材料二班",18);
    Reader r3("3","程宇皓","文化产业管理","公管五班",10);
    Reader r4("4","董春航","通信工程","通信一班",8);

    //图书借阅操作类
    BRoperation brop(vbr);
    date d21(2020,6,10);
    BorrowingRecord br7(d21,"111","4",1,1);
    brop.BRopAdd(br7);
    brop.BRopQuery1(d21);
    brop.BRopQuery2("3");
    brop.BRopQuery3("333");
    brop.BRopQuery4("LiteraryLeisure");
    brop.BRopOs();
    cout<<"Istream:"<<endl;
    brop.BRopIs();
    cout<<endl;

    //图书操作类
    date d5(2020,11,28);
    operation op1(bk,"1",d5);
    op1.query01("三国演义");
    op1.query02("222");
    op1.query03("电子工业出版社");
    op1.query04(d4);
    op1.query05("基础");
    op1.query06("三国演义","罗贯中");
    op1.query07("中国华侨出版社","施耐庵");
    op1.query08(d3,d4);
    op1.query09(vbr,"111");
    op1.query10(vbr,d13,d15);
    op1.query11(vbr,"Basics");
    op1.BorrowBook(vbr,vr,"333");
    op1.ReturnBook(vbr,"222");
    op1.RenewBook(vbr,"444");
}
#include<bits/stdc++.h>
#include<iostream>
#include<fstream>
#include<vector>
#include<map>
using namespace std;
string iType1[4] = { "","Lend","Return","Renew" };//操作类型:借出,还回,续借
string BookType1[4] = { "","Basics","LiteraryLeisure","Professional" };//图书类型:基础,文学休闲,专业

//日前类:包括年月日,重载输入运算符时,要进行数据的合法性检验;重载输出运算符时,按照“年/月/日”形式输出;重载+运算符;
class date
{
    int year;
    int month;
    int day;
    friend ostream& operator<<(ostream& out, date& d);
public:
    date(int year, int month, int day);
    date();
    int GetYear() { return this->year; };
    void SetYear(int year) { this->year = year; };
    int GetMonth() { return this->month; };
    void SetMonth(int month) { this->month = month; };
    int GetDay() { return this->day; };
    void SetDay(int day) { this->day = day; };
    bool operator==(const date& d)
    {
        if (d.day == this->day && d.month == this->month && d.year == this->year)
        {
            return true;
        }
        else return false;
    };
};

date::date(int year, int month, int day)
{
    this->year = year;
    this->month = month;
    this->day = day;
}

date::date()
{
    this->year = 0;
    this->month = 0;
    this->day = 0;
}

ostream& operator<<(ostream& out, date& d)
{
    if (d.year >= 2000 && d.year <= 2022 && d.month >= 1 && d.month <= 12)
    {
        if ((d.month == 1 || d.month == 3 || d.month == 5 || d.month == 7 || d.month == 8 || d.month == 10 || d.month == 12) && (d.day >= 1 && d.day <= 31))
        {
            out << d.year << "/" << d.month << "/" << d.day;
        }
        else if ((d.month == 4 || d.month == 6 || d.month == 9 || d.month == 11) && d.day >= 1 && d.day <= 30)
        {
            out << d.year << "/" << d.month << "/" << d.day;
        }
        else if (d.month == 2)
        {
            if (((d.year % 4 == 0 && d.year % 100 != 0) || (d.year % 400 == 0)) && (d.day >= 1 && d.year <= 29))
            {
                out << d.year << "/" << d.month << "/" << d.day;
            }
            else if (d.day >= 1 && d.day <= 28)
            {
                out << d.year << "/" << d.month << "/" << d.day;
            }
            else  out << "Date input error!";
        }
        else  out << "Date input error!";
    }
    else  out << "Date input error!";
    return out;
}

//借阅记录类:包括日期、书号、读者学号、类型(借出/还回/续借)、图书类型(基础/文学休闲/专业);
class BorrowingRecord
{
    date d;
    string BookNum;
    string ID;
    string iType2;
    int iType3;
    string BookType2;
    int BookType3;
    friend ostream& operator<<(ostream& out, BorrowingRecord& br);
public:
    BorrowingRecord(date d, string BookNum, string ID, int iType3, int BookType3);
    BorrowingRecord();
    date GetDate() { return this->d; };
    void SetDate(date d) { this->d = d; };
    string GetBookNum() { return this->BookNum; };
    void SetBookNum(string BookNum) { this->BookNum = BookNum; };
    string GetID() { return this->ID; };
    void SetID(string ID) { this->ID = ID; };
    string GetiType2() { return this->iType2; };
    void SetiType2(int iType3) { this->iType2 = iType1[iType3]; };
    string GetBookType2() { return this->BookType2; };
    void SetBookType2(int BookType3) { this->BookType2 = BookType1[BookType3]; };
    bool operator==(const BorrowingRecord& br)
    {
        if (this->d == br.d && this->BookNum == br.BookNum && this->ID == br.ID && this->iType2 == br.iType2 && this->BookType2 == br.BookType2)
        {
            return true;
        }
        else return false;
    };
};

BorrowingRecord::BorrowingRecord(date d, string BookNum, string ID, int iType3, int BookType3)
{
    this->d = d;
    this->BookNum = BookNum;
    this->ID = ID;
    this->iType2 = iType1[iType3];
    this->BookType2 = BookType1[BookType3];
}

BorrowingRecord::BorrowingRecord()
{
    this->d = d;
    this->BookNum = "";
    this->ID = "";
    this->iType2 = iType1[0];
    this->BookType2 = BookType1[0];
}

ostream& operator<<(ostream& out, BorrowingRecord& br)
{
    out << "BorDate:" << br.d << " BorBookNum:" << br.BookNum << " BorReaderID:" << br.ID << " BorType:" << br.iType2 << " BorBookType:" << br.BookType2;
    return out;
}


//读者类:学号、姓名、专业、班级、已借图书数量、借阅记录向量;
class Reader
{
    string ID;
    string name;
    string major;
    string Class;
    int borSum;
    vector<BorrowingRecord> v;
    friend ostream& operator<<(ostream& out, Reader& br);
public:
    Reader(string ID, string name, string major, string Class, int borSum, vector<BorrowingRecord> v);
    bool operator==(const Reader& r)
    {
        if (this->ID == r.ID && this->name == r.name && this->major == r.major && this->Class == r.Class && this->borSum == r.borSum && this->v == r.v)
        {
            return true;
        }
        else return false;
    };
};

Reader::Reader(string ID, string name, string major, string Class, int borSum, vector<BorrowingRecord> v)
{
    this->ID = ID;
    this->name = name;
    this->major = major;
    this->Class = Class;
    this->borSum = borSum;
    this->v = v;
}

ostream& operator<<(ostream& out, Reader& r)
{
    out << "ReaderID:" << r.ID << " ReaderName:" << r.name << " ReaderMajor:" << r.major << " ReaderClass:" << r.Class << " ReaderBorSum:" << r.borSum << endl;
    for (vector<BorrowingRecord>::iterator it = r.v.begin(); it != r.v.end(); it++)
    {
        out << (*it) << endl;
    }
    return out;
}

//图书类:书号、书名、作者、出版社、出版日期、图书类型(基础/文学休闲/专业)、馆藏总量、在馆数量、借阅记录向量;
class Books
{
    string bookNum;
    string bookName;
    string bookAuthor;
    string press;
    date pressDate;
    string BookType2;
    int BookType3;
    int sum;
    int sumNow;
    vector<BorrowingRecord> v;
    friend ostream& operator<<(ostream& out, Books& bk);
public:
    Books(string bookNum, string bookName, string bookAuthor, string press, date pressDate, int BookType3, int sum, int sumNow, vector<BorrowingRecord> v);
    bool operator==(const Books& bk)
    {
        if (this->bookNum == bk.bookNum && this->bookName == bk.bookName && this->bookAuthor == bk.bookAuthor && this->BookType2 == bk.BookType2
            && this->BookType3 == bk.BookType3 && this->sum == bk.sum && this->sumNow == bk.sumNow && this->v == bk.v)
        {
            return true;
        }
        else return false;
    };
};

Books::Books(string bookNum, string bookName, string bookAuthor, string press, date pressDate, int BookType3, int sum, int sumNow, vector<BorrowingRecord> v)
{
    this->bookNum = bookNum;
    this->bookName = bookName;
    this->bookAuthor = bookAuthor;
    this->press = press;
    this->pressDate = pressDate;
    this->BookType2 = BookType1[BookType3];
    this->sum = sum;
    this->sumNow = sumNow;
    this->v = v;
}

ostream& operator<<(ostream& out, Books& bk)
{
    out << "BooksNum:" << bk.bookNum << " BooksName:" << bk.bookName << " BooksAuthor:" << bk.bookAuthor << " BooksPress:" << bk.press << " BooksPressDate:" << bk.pressDate
        << " BooksType:" << bk.BookType2 << " BooksSum:" << bk.sum << " BooksSumNow:" << bk.sumNow << endl;
    for (vector<BorrowingRecord>::iterator it = bk.v.begin(); it != bk.v.end(); it++)
    {
        out << (*it) << endl;
    }
    return out;
}

//日期类按照日期升序排序
class comapreDate
{
public://仿函数
    bool operator()(date a1, date a2)
    {
        if (a1.GetYear() == a2.GetYear())
        {
            if (a1.GetMonth() == a2.GetMonth())
            {
                return a1.GetDay() < a2.GetDay();
            }
            else return a1.GetMonth() < a2.GetMonth();
        }
        else return a1.GetYear() < a2.GetYear();
    }
};

//字符串按照字典序排序
class compareString
{
public://仿函数
    bool operator()(string a1, string a2)
    {
        return a1 < a2;
    }
};

//操作类
class operation
{
    vector<Books> vbk;//图书类
    vector<Reader> vr;//读者类
    vector<BorrowingRecord> vbr;//借阅记录类
    multimap<string, int, compareString> mbk1;//图书类:按书号查找
    multimap<date, int, comapreDate> mbk2;//图书类:按日期查找
    multimap<string, int, compareString> mbk3;//图书类:按学号查找
    multimap<string, int, compareString> mbk4;//图书类:按类型查找
    multimap<string, int, compareString> mbk5;//图书类:按图书类型查找

//    multimap<string,int,compareString> mr1;//读者类:按学号查找
//    multimap<date,int,comapreDate> mr2;//读者类:按日期查找
//
//    multimap<string,int,compareString> mbr1;//借阅记录类:按字符串查找
//    multimap<date,int,comapreDate> mbr2;//借阅记录类:按日期查找

public:
    operation(vector<Books>& vbk, vector<Reader>& vr, vector<BorrowingRecord>& vbr)
    {
        this->vbk = vbk; this->vr = vr; this->vbr = vbr;
    };
    void BooksAdd(BorrowingRecord br1, Reader r1, Books bk1);//图书类:增加一条数据
    void BookDelete(BorrowingRecord br1, Reader r1, Books bk1);//图书类:删除一条数据
    void BooksUpdate();//图书类:修改一条数据
    void BooksQueryStr(string BookNum);//图书类:查询符合要求的数据,按照字符串
    void BooksQueryDate(date d);//图书类:查询符合要求的数据,按照日期
    void BooksOs();//图书类:写入文件
    void BooksIs();//图书类:读出文件

    void ReaderOs();//读者类:写入文件
    void ReaderIs();//读者类:读出文件

    void BorrowingRecordOs();//借阅记录类:写入文件
    void BorrowingRecordIs();//借阅记录类:读出文件

};

void operation::BooksAdd(BorrowingRecord br1, Reader r1, Books bk1)
{
    int i;
    this->vbr.push_back(br1);
    this->vr.push_back(r1);
    this->vbk.push_back(bk1);
    i = vbr.size();
    mbk1.insert(make_pair(br1.GetBookNum(), i - 1));//书号
    mbk2.insert(make_pair(br1.GetDate(), i - 1));//时间
    mbk3.insert(make_pair(br1.GetID(), i - 1));//学号
    mbk4.insert(make_pair(br1.GetiType2(), i - 1));//类型
    mbk3.insert(make_pair(br1.GetBookType2(), i - 1));//图书类型
}

void operation::BookDelete(BorrowingRecord br1, Reader r1, Books bk1)
{
    for (vector<BorrowingRecord>::iterator it = this->vbr.begin(); it != this->vbr.end(); it++)
    {
        if ((*it) == br1) vbr.erase(it, ++it);
    }

    for (vector<Reader>::iterator it = this->vr.begin(); it != this->vr.end(); it++)
    {
        if ((*it) == r1) vr.erase(it, ++it);
    }

    for (vector<Books>::iterator it = this->vbk.begin(); it != this->vbk.end(); it++)
    {
        if ((*it) == bk1) vbk.erase(it, ++it);
    }

    multimap<string, int, compareString>::iterator it1 = mbk1.find(br1.GetBookNum());
    if (it1 != this->mbk1.end())
    {
        mbk1.erase(it1, ++it1);
    }

    multimap<date, int, comapreDate>::iterator it2 = mbk2.find(br1.GetDate());
    if (it2 != this->mbk2.end())
    {
        mbk2.erase(it2, ++it2);
    }

    multimap<string, int, compareString>::iterator it3 = mbk3.find(br1.GetID());
    if (it3 != this->mbk3.end())
    {
        mbk3.erase(it3, ++it3);
    }

    multimap<string, int, compareString>::iterator it4 = mbk4.find(br1.GetiType2());
    if (it4 != this->mbk4.end())
    {
        mbk4.erase(it4, ++it4);
    }

    multimap<string, int, compareString>::iterator it5 = mbk5.find(br1.GetBookType2());
    if (it5 != this->mbk5.end())
    {
        mbk5.erase(it5, ++it5);
    }

}

void operation::BooksQueryStr(string BookNum)
{
    multimap<string, int, compareString>::iterator it1 = mbk1.find(BookNum);
    int x = 0;
    if (it1 != this->mbk1.end())
    {
        x = (*it1).second;
        cout << vbr[x] << endl;
    }
}

void operation::BooksQueryDate(date d)
{
    multimap<date, int, comapreDate>::iterator it2 = mbk2.find(d);
    int x = 0;
    if (it2 != this->mbk2.end())
    {
        x = (*it2).second;
        cout << vbr[x] << endl;
    }
}

void operation::BooksOs()
{
    ofstream ofs;
    ofs.open("book.txt", ios::out);
    for (vector<Books>::iterator it = this->vbk.begin(); it != this->vbk.end(); it++)
    {
        ofs << (*it) << endl;
    }cout << endl;
}

void operation::BooksIs()
{
    ifstream ifs;
    ifs.open("book.txt", ios::in);
    if (!ifs.is_open())
    {
        cout << "文件打开失败" << endl;
        return;
    }
    char c;
    while ((c = ifs.get()) != EOF)
    {
        cout << c;
    }

    ifs.close();
}

void operation::ReaderOs()
{
    ofstream ofs;
    ofs.open("reader.txt", ios::out);
    for (vector<Reader>::iterator it = this->vr.begin(); it != this->vr.end(); it++)
    {
        ofs << (*it) << endl;
    }cout << endl;
}

void operation::ReaderIs()
{
    ifstream ifs;
    ifs.open("reader.txt", ios::in);
    if (!ifs.is_open())
    {
        cout << "文件打开失败" << endl;
        return;
    }
    char c;
    while ((c = ifs.get()) != EOF)
    {
        cout << c;
    }

    ifs.close();
}

void operation::BorrowingRecordOs()
{
    ofstream ofs;
    ofs.open("record.txt", ios::out);
    for (vector<BorrowingRecord>::iterator it = this->vbr.begin(); it != this->vbr.end(); it++)
    {
        ofs << (*it) << endl;
    }cout << endl;
}

void operation::BorrowingRecordIs()
{
    ifstream ifs;
    ifs.open("record.txt", ios::in);
    if (!ifs.is_open())
    {
        cout << "文件打开失败" << endl;
        return;
    }
    char c;
    while ((c = ifs.get()) != EOF)
    {
        cout << c;
    }

    ifs.close();
}

//借阅记录操作类
class BRoperation
{
    vector<BorrowingRecord> vbr;//借阅记录类
public:
    BRoperation(vector<BorrowingRecord> vbr)
    {
        this->vbr = vbr;
    };
    void BRopAdd(BorrowingRecord br1);//添加一条借阅记录
    void BRopQuery1(date d);//按照日期查询
    void BRopQuery2(string ID);//按照学号查询
    void BRopQuery3(string BookNum);//按照书号查询
    void BRdelete(BorrowingRecord br1);//删除一条记录
    void BRupdate(BorrowingRecord br1, date d, string BookNum, string ID, int iType2, int BookType2);//修改一条记录
    void BRopOs();
    void BRopIs();
};

void BRoperation::BRopAdd(BorrowingRecord br1)
{
    this->vbr.push_back(br1);
}

void BRoperation::BRopQuery1(date d)
{
    cout << "QueryDate:" << endl;
    for (vector<BorrowingRecord>::iterator it = this->vbr.begin(); it != this->vbr.end(); it++)
    {
        if ((*it).GetDate() == d)
        {
            cout << (*it) << endl;
        }
    }
}

void BRoperation::BRopQuery2(string ID)
{
    cout << "QueryID:" << endl;
    for (vector<BorrowingRecord>::iterator it = this->vbr.begin(); it != this->vbr.end(); it++)
    {
        if ((*it).GetID() == ID)
        {
            cout << (*it) << endl;
        }
    }
}

void BRoperation::BRopQuery3(string BookNum)
{
    cout << "QueryBookNum:" << endl;
    for (vector<BorrowingRecord>::iterator it = this->vbr.begin(); it != this->vbr.end(); it++)
    {
        if ((*it).GetBookNum() == BookNum)
        {
            cout << (*it) << endl;
        }
    }
}

void BRoperation::BRdelete(BorrowingRecord br1)
{
    for (vector<BorrowingRecord>::iterator it = this->vbr.begin(); it != this->vbr.end(); it++)
    {
        if ((*it) == br1)
        {
            this->vbr.erase(it);
        }
    }
}

void BRoperation::BRupdate(BorrowingRecord br1, date d, string BookNum, string ID, int iType3, int BookType3)
{
    for (vector<BorrowingRecord>::iterator it = this->vbr.begin(); it != this->vbr.end(); it++)
    {
        if ((*it) == br1)
        {
            (*it).SetDate(d);
            (*it).SetBookNum(BookNum);
            (*it).SetID(ID);
            (*it).SetiType2(iType3);
            (*it).SetBookType2(BookType3);
        }
    }
}

void BRoperation::BRopOs()
{
    ofstream ofs;
    ofs.open("record.txt", ios::out);
    for (vector<BorrowingRecord>::iterator it = this->vbr.begin(); it != this->vbr.end(); it++)
    {
        ofs << (*it) << endl;
    }cout << endl;
}

void BRoperation::BRopIs()
{
    ifstream ifs;
    ifs.open("record.txt", ios::in);
    if (!ifs.is_open())
    {
        cout << "文件打开失败" << endl;
        return;
    }
    char c;
    while ((c = ifs.get()) != EOF)
    {
        cout << c;
    }

    ifs.close();
}

int main()
{
    //第一人借计算机书记录
    date d01(2020, 11, 28);
    BorrowingRecord br01(d01, "123", "1", 1, 3);
    date d02(2021, 9, 15);
    BorrowingRecord br02(d02, "123", "1", 2, 3);
    vector<BorrowingRecord> v11;
    v11.push_back(br01);
    v11.push_back(br02);

    //第二人借计算机书记录
    date d11(2021, 10, 1);
    BorrowingRecord br11(d11, "123", "2", 1, 3);
    date d12(2022, 3, 15);
    BorrowingRecord br12(d12, "123", "2", 2, 3);
    vector<BorrowingRecord> v12;
    v12.push_back(br11);
    v12.push_back(br12);

    //计算机书总借书记录
    vector<BorrowingRecord> v01;
    v01.push_back(br01);
    v01.push_back(br02);
    v01.push_back(br11);
    v01.push_back(br12);

    //计算机书读者记录
    Reader r01("1", "张伟", "计算机科学与技术", "计算机4班", 2, v11);
    Reader r02("2", "李华", "网络工程", "网络2班", 2, v12);
    vector<Reader> vr01;
    vr01.push_back(r01);
    vr01.push_back(r02);

    //图书类记录
    date d03(2017, 6, 25);
    Books bk01("123", "C++程序设计", "林伟健", "电子工业出版社", d03, 3, 1000, 800, v01);
    vector<Books> vbk01;
    vbk01.push_back(bk01);

    //操作类
    operation op(vbk01, vr01, v01);

    date md01(2022, 4, 22);
    BorrowingRecord mbr01(md01, "456", "3", 1, 3);
    vector<BorrowingRecord> mv11;
    mv11.push_back(mbr01);
    Reader mr01("3", "赵雷", "材料化学", "材料3班", 2, mv11);
    date mb02(2015, 11, 11);
    Books mbk01("456", "无机化学与分析", "宋天佑", "高等教育出版社", mb02, 2, 550, 320, mv11);

    op.BooksAdd(mbr01, mr01, mbk01);

    cout << "Book:";
    op.BooksOs();
    op.BooksIs();

    cout << "Reader:";
    op.ReaderOs();
    op.ReaderIs();

    cout << "Record:";
    op.BorrowingRecordOs();
    op.BorrowingRecordIs();
    cout << endl;

    //借阅记录操作类
    BRoperation brop(v01);
    date d33(2022, 5, 7);
    BorrowingRecord br33(d33, "456", "4", 1, 3);
    date d34(2022, 5, 8);
    BorrowingRecord br34(d34, "789", "4", 1, 2);
    brop.BRopAdd(br34);
    cout << "BRoperation:";
    brop.BRopOs();
    brop.BRopIs();
    brop.BRdelete(br33);
    date d35(2022, 5, 9);
    brop.BRupdate(br34, d35, "888", "5", 1, 1);
    brop.BRopQuery1(d01);
    brop.BRopQuery2("2");
    brop.BRopQuery3("888");
}

猜你喜欢

转载自blog.csdn.net/weixin_59798969/article/details/124483189