程序:
#include<bits/stdc++.h>
using namespace std;
class Date
{
private:
int year;
int month;
int day;
public:
Date(int x,int y,int z):year(x),month(y),day(z){}
Date(){}
int getYear(){return year;}
int getMonth(){return month;}
int getDay(){return day;}
void setYear(int x){year=x;}
void setMonth(int x){month=x;}
void setDay(int x){day=x;}
friend ostream & operator <<(ostream & output,Date & obj)
{
output<<obj.year<<" "<<obj.month<<" "<<obj.day;
return output;
}
friend istream & operator >>(istream & input,Date & obj)
{
input>>obj.year>>obj.month>>obj.day;
return input;
}
bool operator <(const Date & obj)const
{
return obj.year!=year?year<obj.year:obj.month!=month?month<obj.month:day<obj.day;
}
};
class Record
{
private:
string bookName;
int bookIndex;
string stuName;
string type;//操作类型
int stuID;
Date opTime;
Date endTime;
bool ifback;//是否归还
public:
Record(){ifback=0;}
Record(string book,int b,string s1,int s2,string ty,Date o,Date end,bool f)
{
bookName=book;
bookIndex=b;
stuName=s1;
stuID=s2;
type=ty;
opTime=o;
endTime=end;
ifback=f;
}
string getName(){return bookName;}
int getIndex(){return bookIndex;}
string getstuName(){return stuName;}
int getID(){return stuID;}
Date getopTime(){return opTime;}
Date getendTime(){return endTime;}
bool getifback(){return ifback;}
string getType(){return type;}
void setType(string x){type=x;}
void setName(string x){bookName=x;}
void setIndex(int x){bookIndex=x;}
void setstuName(string x){stuName=x;}
void setID(int x){stuID=x;}
void setopTime(Date t){opTime=t;}
void setendTime(Date x){endTime=x;}//修改还书时间
void setifback(bool f){ifback=f;}
friend ostream & operator <<(ostream & out,Record & obj);
friend istream & operator >>(istream & in,Record & obj);
};
ostream & operator <<(ostream & out,Record & obj)
{
out<<obj.bookIndex<<" ";
out<<obj.bookName<<" ";
out<<obj.stuName<<" ";
out<<obj.stuID<<" ";
out<<obj.type<<" ";
out<<obj.opTime<<" ";
out<<obj.endTime<<" ";
out<<obj.ifback;
return out;
}
istream & operator >>(istream & in,Record & obj)
{
in>>obj.bookIndex>>obj.bookName>>obj.stuName>>obj.stuID>>obj.type>>
obj.opTime>>obj.endTime>>obj.ifback;
return in;
}
class Records
{
protected:
int RecordNum;
vector <Record> v1;
vector <Record> ::iterator vit1;
multimap<bool,int>m2;
multimap<bool,int>::iterator mit2;//是否归还bool
public:
Records(){RecordNum=0;}
int getRecordNum(){return RecordNum;}
vector <Record> & getRecord(){return v1;}
multimap<bool,int> & getM2(){return m2;}
void setRecordNum(int x){RecordNum=x;}
//无删除记录与增加记录Op,book类中和student类中这两个函数不同
void disAllRecord();//所有记录
void disNobackRecord();//显示未还书记录
};
void Records::disAllRecord()
{
for(int i=0;i<v1.size();++i)cout<<v1[i]<<endl;
}
void Records::disNobackRecord()
{
if(m2.find(0)!=m2.end())
for(mit2=m2.lower_bound(0);mit2!=m2.upper_bound(0);++mit2)
cout<<v1[mit2->second]<<endl;
else cout<<"no records!"<<endl;
}
class Book:public Records
{
private:
string name;
int index;
int tot;//总数
int shengyu;//剩余数量
char ch;//辅助格式
multimap<int,int>m1;