大一下学期写过一个模拟图书管理系统的代码。虽然水平有点菜,但是很浅显易懂啊有没有!
这个模拟的图书管理系统主要包括两部分——用户操作和管理员操作。
因为用户和管理员均可以进行书籍的查找工作,所以就写了一个继承,可以节省空间,使代码更加简洁。
//用继承的方式写 完整的图书管理系统
#include<bits/stdc++.h>
using namespace std;
struct Test{
int testY();
int testM();
int testD(int m);
};//用于检验时间准确性的结构体
int Test::testY()
{
int y;
while(1)
{
cin>>y;
int yy=y,m=0;
for(int i=1;yy>0;i++)
{
yy/=10;
m++;
}
if(m==4) break;
else cout<<"年份输入错误,请重新输入:";
}
return y;
}
int Test::testM()
{
int m;
while(1)
{
cin>>m;
if(m<1||m>12) cout<<"月份输入错误,请重新输入";
else break;
}
return m;
}
int Test::testD(int m)
{
int d;
while(1)
{
cin>>d;
if(m==1||m==3||m==5||m==7||m==8||m==10||m==12)
{
if(d<1||d>31)
cout<<"天数输入错误,请重新输入";
else
break;
}
else if(m==2)
{
if(d<1||d>28)
cout<<"天数输入错误,请重新输入";
else break;
}
else
{
if(d<1||d>30)
cout<<"天数输入错误,请重新输入";
else break;
}
}
return d;
}
/*每写完一个结构体/类/函数就用主函数检查一下,有问题及时改,不要攒到一起
int main()
{
Test t;
int yy,mm,dd;
yy=t.testY();
mm=t.testM();
dd=t.testD(mm);
cout<<yy<<" "<<mm<<" "<<dd;
return 0;
}
*/
//时间:年 月 日 数据类
class Time{
int year;
int month;
int day;
public:
Test t;
Time():year(0),month(0),day(0){}
Time(int y,int m,int d):year(y),month(m),day(d){}
int getYear(){year=t.testY(); return year;}
int getMonth(){month=t.testM(); return month;}
int getDate(){day=t.testD(month); return day;}
void setDate_renew();//假设续借时间为1个月
void setDate_deadline();//假设借书时间为2个月
friend ostream&operator<<(ostream&os,const Time&d);
friend istream&operator>>(istream&is,Time&d);
bool operator<(const Time&t)const{
return year!=t.year?year<t.year:month!=t.month?month<t.month:day<t.day;
}
};
//运算符重载
ostream&operator<<(ostream&os,const Time&d)
{
os<<d.year<<" ";
os<<d.month<<" ";
os<<d.day<<" ";
return os;
}
istream&operator>>(istream&is,Time&d)
{
is>>d.year>>d.month>>d.day;
return is;
}
/*
31天: 1 3 5 7 8 10 12 月
28天: 2 月
30天: 4 6 9 11 月
*/
void Time::setDate_renew()//假设续借时间为1个月(月份+1粗糙计算)
{
if(month==12) //12->1 31->31
{
month=1;
year++;
}
else if(month==1) //1->2
{
month++;
if(day>=29) day=28;
}
else if(month==3||month==5||month==7||month==8||month==10) //31->30
{
month++;
if(day==31) day=30;
}
else month++;
}
/*
int main()
{
Time t1;
int y,m,d;
y=t1.getYear();
m=t1.getMonth();
d=t1.getDate();
cout<<t1<<endl;
t1.setDate_renew();
cout<<t1<<endl;
Time t2;
cout<<t2<<endl;
return 0;
}
31天: 1 3 5 7 8 10 12 月
28天: 2 月
30天: 4 6 9 11 月
*/
void Time::setDate_deadline()
{
if(month==12)//12->2 31->28
{
month=2;
year++;
if(day>=29) day=28;
}
else if(month==11)//11->1 30->31
{
month=1;
year++;
}
else if(month==7||month==9)//7->9 31->30
{
month+=2;
if(day==31) day=30;
}
else month+=2;//1->3,3->5,5->7,8->10,10->12(31->31) 2->4(28->30) 4->6,9->11(30->30),6->8(30->31)
}
/*
int main()
{
Time t1;
int y,m,d;
y=t1.getYear();
m=t1.getMonth();
d=t1.getDate();
cout<<t1<<endl;
t1.setDate_deadline();
cout<<t1<<endl;
Time t2;
cout<<t2<<endl;
return 0;
}
*/
class Record{
string rName;
string rNumber;
string department;
string borrowB;
Time borrowT;
Time currentT;
string status_return;
string status_renew;
string status_pay;
Time returnT;//两部分,若已归还,continue;否则,是否续借,且续借次数是否用完
Time deadline;//放在time里面,借书日期加两个月if(getreturnT^^^)else getdeadline
int maxB;//可借书总数
int unReturn;//未归还数量
public:
Record(){}
Record(string rm,string xh,string zybj,string b,Time bT,Time cT,string s1,string s2,string s3,Time rT,Time dL,
int ma,int unR):rName(rm),rNumber(xh),department(zybj),borrowB(b),
borrowT(bT),currentT(cT),status_return(s1),status_renew(s2),status_pay(s3),returnT(rT),deadline(dL),maxB(ma),unReturn(unR)
{}
string getRNa(){return rName;}
Time getBorrowT(int y,int m,int d);
Time getBorrowTT(){return borrowT;}
Time getCurrentT(int y,int m,int d);
string getStatus_return(){return status_return;}
void setStatus_return(){status_return="已归还"; returnT=currentT;}
string getStatus_renew(){return status_renew;}
void setStatus_renew(){
status_renew="已续借";
Time returnT(0,0,0);//未归还
Time deadline=borrowT;
deadline.setDate_deadline();
deadline.setDate_renew();//截止日期延后1个月
if(deadline<currentT) status_pay="超时应缴费";
else status_pay="正常借阅";
}
string getStatus_pay(){return status_pay;}
Time getReturnT(int y,int m,int d);
string getBorrowB(){return borrowB;}
int getMax(){return maxB;}
void setMax_r(){maxB++;}//还书时
//void setMax_b(){maxB--;}
int getHand(){return unReturn;}
void setHand_r(){unReturn--;}//还书时
//void setHand-b(){unReturn++;}
friend ostream&operator<<(ostream&os,const Record&r);
friend istream&operator>>(istream&is,Record&r);
};
Time Record::getReturnT(int y,int m,int d)
{
y=returnT.getYear();
m=returnT.getMonth();
d=returnT.getDate();
return returnT;
}
Time Record::getBorrowT(int y,int m,int d)
{
y=borrowT.getYear();
m=borrowT.getMonth();
d=borrowT.getDate();
return borrowT;
}
Time Record::getCurrentT(int y,int m,int d)
{
y=currentT.getYear();
m=currentT.getMonth();
d=currentT.getDate();
return currentT;
}
ostream&operator<<(ostream&os,const Record&r)
{
os<<r.rName<<" ";
os<<r.rNumber<<" ";
os<<r.department<<" ";
os<<r.borrowB<<" ";
os<<r.borrowT<<" ";
os<<r.currentT<<"";
os<<r.status_return<<" ";
os<<r.status_renew<<" ";
os<<r.status_pay<<" ";
os<<r.returnT<<" ";
os<<r.deadline<<" ";
os<<r.maxB<<" ";
os<<r.unReturn<<" ";
return os;
}
istream&operator>>(istream&is,Record&r)
{
is>>r.rName>>r.rNumber>>r.department>>r.borrowB>>r.borrowT>>r.currentT>>r.status_return>>r.status_renew>>r.status_pay>>r.returnT>>r.deadline>>r.maxB>>r.unReturn;
return is;
}
/*
int main()
{
string rNa,rNu,de,bB,s1,s2,s3;
int maxBook,unR,y,m,d,yy,mm,dd,yyy,mmm,ddd;
cin>>rNa>>rNu>>de>>bB>>s1>>s2>>maxBook>>unR;
Record r0;
Time t0;
Time borr=r0.getBorrowT(y,m,d);//输入借书日期
Time curr=r0.getCurrentT(yyy,mmm,ddd);//输入对当前日期
if(s1=="已归还")
{
Time retu=r0.getReturnT(yy,mm,dd);//输入归还日期
Time deadl=borr;
deadl.setDate_deadline();
if(retu<deadl) s3="正常借阅";
else s3="超时应缴费";
Record r1(rNa,rNu,de,bB,borr,curr,s1,s2,s3,retu,deadl,maxBook,unR);
cout<<r1<<endl;
}
if(s1=="未归还")
{
//若未归还,未续借,returnT不作处理,自动0000 0 0
if(s2=="未续借")//deadline正常
{
Time retu(0,0,0);//未归还
Time deadl=borr;
deadl.setDate_deadline();//截止日期不变
if(deadl<curr) s3="超时应缴费";
else s3="正常借阅";
Record r1(rNa,rNu,de,bB,borr,curr,s1,s2,s3,retu,deadl,maxBook,unR);
cout<<r1<<endl;
}
if(s2=="已续借")
{
Time retu(0,0,0);//未归还
Time deadl=borr;
deadl.setDate_deadline();
deadl.setDate_renew();//截止日期延后1个月
if(deadl<curr) s3="超时应缴费";
else s3="正常借阅";
Record r1(rNa,rNu,de,bB,borr,curr,s1,s2,s3,retu,deadl,maxBook,unR);
cout<<r1<<endl;
}
}
Record r2;
cout<<r2<<endl;
return 0;
}
*/
//图书:书号书名作者 出版社 出版时间(时间类型自己定义) 在馆册数
class Book{
string bName;
string bNumber;
string author;
string pHouse;
Time pDate;
int aAmount;//在馆数量
public:
Book():bName(""),bNumber(""),author(""),pHouse(""),aAmount(0){}
Book(string bNa,string bNu,string a,string pH,Time s,int n):bName(bNa),bNumber(bNu),author(a),pHouse(pH),pDate(s),aAmount(n){}
string getBNa(){return bName;}
string getBNu(){return bNumber;}
string getA(){return author;}
string getPH(){return pHouse;}
Time getDa(int y,int m,int d);
Time getPD(){return pDate;}
int getAa(){return aAmount;}
void getAa_return(){aAmount++;}
void getAa_borrow(){aAmount--;}
string setBNa(){string name;cin>>name;bName=name;}
friend ostream &operator<<(ostream &os,Book &b);
friend istream&operator>>(istream&is,Book&b);
};
ostream &operator<<(ostream &os,Book &b)
{
int n;
vector<Record>::iterator i;
os<<b.bName<<" ";
os<<b.bNumber<<" ";
os<<b.author<<" ";
os<<b.pHouse<<" ";
os<<b.pDate<<" ";
os<<b.aAmount<<" ";
return os;
}
istream&operator>>(istream&is,Book&b)
{
is>>b.bName>>b.bNumber>>b.author>>b.pHouse>>b.pDate>>b.aAmount;
}
Time Book::getDa(int y,int m,int d)//出版日期
{
y=pDate.getYear();
m=pDate.getMonth();
d=pDate.getDate();
return pDate;
}
/*
int main()
{
string sh,sm,zz,cbs;
int y,m,d,ava;
cin>>sm>>sh>>zz>>cbs>>ava;
Book b0;
Time rqq=b0.getDa(y,m,d);
Book b1(sm,sh,zz,cbs,rqq,ava);
Book b2;
cout<<b1<<endl;
cout<<b2<<endl;
return 0;
}
*/
//读者:姓名 学号 专业班级 可借阅数目 未还数目;
class Reader{
string account;
//string key;
string rName;
string rNumber;
string department;
Time registerT;//注册日期
//int flag;//flag=0 未注销 ; flag=1 已注销(学生已被取消借书资格)
public:
Reader(){}
Reader(string a,string rm,string xh,string zybj,Time r):account(a),rName(rm),rNumber(xh),department(zybj),registerT(r){}
string getAccount(){return account;}
//string getKey(){return key;}
string getRNa(){return rName;}
string getRNu(){return rNumber;}
string getSC(){return department;}
Time getRegister(int y,int m,int d);
Time getRT(){return registerT;}
//int getFlag(){return flag;}
friend ostream&operator<<(ostream &os,Reader &r);
friend istream&operator>>(istream &is,Reader &r);
void setRNa(string newName){rName=newName;}
/*void setKey(string newKey){
string k;
while(1)
{
cin>>k;
if(k==key) key=newKey;
else cout<<"密码错误,请重新输入:";
}
}*/
};
ostream&operator<<(ostream &os,Reader &r)
{
os<<r.account<<" ";
//os<<r.key<<" ";
os<<r.rName<<" ";
os<<r.rNumber<<" ";
os<<r.department<<" ";
os<<r.registerT<<" ";
//os<<r.flag<<" ";
return os;
}
istream&operator>>(istream &is,Reader &r)
{
is>>r.account>>r.rName>>r.rNumber>>r.department>>r.registerT;
return is;
}
Time Reader::getRegister(int y,int m,int d)
{
y=registerT.getYear();
m=registerT.getMonth();
d=registerT.getDate();
return registerT;
}
/*
int main()
{
string a,rm,xh,zybj;
int y,m,d;
cin>>a>>rm>>xh>>zybj;
Reader r0;
Time t=r0.getRegister(y,m,d);
Reader r1(a,rm,xh,zybj,t);
Reader r2;
cout<<r1<<endl;
cout<<r1.getAccount()<<" "<<endl;
cout<<r2<<endl;
return 0;
}
*/
class Srch{
vector<Book> book;
multimap<string,int>bb_na;//书名
multimap<string,int>bb_nu;//书号
multimap<string,int>bb_au;//作者
multimap<string,int>bb_ph;//出版社
multimap<Time,int>bb_pt;//出版时间
public:
Srch(){load();}
void load();
void srch_BNa();
void srch_BNu();
void srch_BAu();
void srch_ph();
void srch_pt();
};
void Srch::load()
{
Book shu;
ifstream in("2018212515-Book.txt",ios::in);
if(in.is_open())
{
// cout<<"book:"<<endl;
book.clear();
if(!in) return;
while(in>>shu)
{
book.push_back(shu);
bb_na.insert(make_pair(shu.getBNa(),book.size()-1));
bb_nu.insert(make_pair(shu.getBNu(),book.size()-1));
bb_au.insert(make_pair(shu.getA(),book.size()-1));
bb_ph.insert(make_pair(shu.getPH(),book.size()-1));
bb_pt.insert(make_pair(shu.getPD(),book.size()-1));
//cout<<shu<<endl;
}
}
in.close();
}
void Srch::srch_BNa()
{
multimap<string,int>::iterator i;
string bName;
while(1)
{
cin>>bName;
if(bName=="0") break;
else
{
i=bb_na.find(bName);
if(i==bb_na.end()) cout<<"未找到此图书";
else{
cout<<book[i->second];
}
}
}
}
void Srch::srch_BNu()
{
multimap<string,int>::iterator i;
string bNumber;
while(1)
{
cin>>bNumber;
if(bNumber=="0") break;
else
{
i=bb_nu.find(bNumber);
if(i==bb_nu.end()) cout<<"未找到此图书";
else{
cout<<book[i->second];
}
}
}
}
void Srch::srch_BAu()
{
multimap<string,int>::iterator i,ii,iii;
string bAuthor;
while(1)
{
cin>>bAuthor;
if(bAuthor=="0") break;
else
{
ii=bb_au.lower_bound(bAuthor);
iii=bb_au.upper_bound(bAuthor);
if(ii==iii) cout<<"未找到此图书";
else
{
for(i=ii;i!=iii;i++)
{
cout<<book[i->second]<<endl;
}
}
}
}
}
void Srch::srch_ph()
{
multimap<string,int>::iterator i,ii,iii;
string bPH;
while(1)
{
cin>>bPH;
if(bPH=="0") break;
else
{
ii=bb_ph.lower_bound(bPH);
iii=bb_ph.upper_bound(bPH);
if(ii==iii) cout<<"未找到此图书";
else{
for(i=ii;i!=iii;i++)
cout<<book[i->second];
}
}
}
}
void Srch::srch_pt()
{
multimap<Time,int>::iterator i,ii,iii;
Time t1;
Time t2;
int y,m,d;
int yy,mm,dd;
while(1)
{
y=t1.getYear();
m=t1.getMonth();
d=t1.getDate();
Time t3(y,m,d);
yy=t2.getYear();
mm=t2.getMonth();
dd=t2.getDate();
Time t4(yy,mm,dd);
if(y==0) break;
else
{
ii=bb_pt.upper_bound(t3);
iii=bb_pt.lower_bound(t4);
if(ii==iii) cout<<"未找到此图书";
else{
for(i=ii;i!=iii;i++)
cout<<book[i->second]<<endl;
}
}
}
}
/*
int main()
{
Srch s;
//s.srch_BNa();
//s.srch_BNu();
//s.srch_BAu();
//s.srch_ph();
//s.srch_pt();
return 0;
}
*/
class UserOp:public Srch{
string account;
string key;
vector<Record> jilu;
vector<Reader>::iterator jj;
vector<Book> book;
vector<Book>::iterator b1;
multimap<string,int>bb;//书名
multimap<string,int>aa;//按照账号查找
multimap<string,int>au;//按作者查找
multimap<Time,int>tt;//按出版日期查找
multimap<Time,int>::iterator t1;
public:
UserOp(string k):account("2018212515"),key("123456"){
while(1)
{
cin>>k;
if(k==key)
{
loadB();
loadU();
break;
}
else cout<<"密码错误,请重新输入:"<<endl;
}
}
~UserOp(){
saveB();
saveU();
}
void loadB();
void saveB();
void loadU();
void saveU();
void addU();//借书记录更新(借书)
void modify_return(string Rn);//还书
void modify_renew(string Rn);//续借
void search_Rname(string Rn);
void search_Bname();
void search_BNumber();
void search_BAuthor();
void search_BPH();
void search_time();
};
void UserOp::loadB()
{
Book b;
book.clear();
ifstream in("2018212515-Book.txt",ios::in);
if(in.is_open())
{
//cout<<"Book_opened_load"<<endl;
if(!in) return;
while(in>>b)
{
book.push_back(b);
bb.insert(make_pair(b.getBNa(),book.size()-1));
tt.insert(make_pair(b.getPD(),book.size()-1));
cout<<b<<endl;
}
in.close();
}
}
void UserOp::saveB()
{
ofstream out("2018212515-Book.txt",ios::out);
vector<Book>::iterator jj;
if(out.is_open())
{
//cout<<"Book_opened_save"<<endl;
if(!out) return;
for(jj=book.begin();jj!=book.end();jj++)
{
out<<*jj<<endl;
//cout<<*jj<<endl;
}
}
out.close();
}
/*
int main()
{
string k;
UserOp u(k);
return 0;
}
*/
void UserOp::loadU()
{
Record r;
jilu.clear();
ifstream in("2018212515-Record.txt",ios::in);
if(in.is_open())
{
if(!in) return;
//cout<<"Record_opened_load"<<endl;
while(in>>r)
{
jilu.push_back(r);
aa.insert(make_pair(r.getRNa(),jilu.size()-1));
bb.insert(make_pair(r.getBorrowB(),jilu.size()-1));
//cout<<r<<endl;
}
in.close();
}
}
void UserOp::saveU()
{
ofstream out("2018212515-Record.txt",ios::out);
vector<Record>::iterator jj;
if(out.is_open())
{
//cout<<"Record_opened_save"<<endl;
if(!out) return;
for(jj=jilu.begin();jj!=jilu.end();jj++)
{
out<<*jj<<endl;
//cout<<*jj<<endl;
}
}
out.close();
}
void UserOp::addU()//借书
{
string bo;
cin>>bo;
multimap<string,int>::iterator bbb;
bbb=bb.find(bo);
if(bbb==bb.end()) cout<<"馆内无此书!"<<endl;
else
{
int amount=book[bbb->second].getAa();
if(amount==0) cout<<"此书已全部借完!"<<endl;
else
{
Record rr;
string Rn;
cin>>Rn;
multimap<string,int>::iterator r1,r2,r3;
r1=aa.find(Rn);
r2=aa.lower_bound(Rn);
r3=aa.upper_bound(Rn);
if(r2==r3) cout<<"未找到此用户"<<endl;
else
{
bool choose;
int maxB=0;
for(r1=r2;r1!=r3;r1++)
{
cout<<jilu[r1->second]<<endl;
cin>>choose;
if(choose==0) continue;
else
{
maxB=jilu[r1->second].getMax();
cout<<maxB<<endl;
}
}
if(maxB==0) cout<<"可借书目达最大量,不可借书!"<<endl;
else
{
cin>>rr;//写入本次要借阅的书的记录 总共借书数量-1,手中书数量+1
jilu.push_back(rr);
aa.insert(make_pair(rr.getRNa(),jilu.size()-1));
bb.insert(make_pair(rr.getBorrowB(),jilu.size()-1));
book[bbb->second].getAa_borrow();
cout<<"借阅成功!"<<endl;
}
}
}
}
}
/*
int main()
{
string k;
UserOp u(k);
u.addU();
return 0;
}
*/
void UserOp::modify_return(string Rn)
{
bool chose;//找到借这本书的记录
multimap<string,int>::iterator rr1,rr2,rr3;
rr1=aa.find(Rn);
rr2=aa.lower_bound(Rn);
rr3=aa.upper_bound(Rn);
for(rr1=rr2;rr1!=rr3;rr1++)
{
cout<<jilu[rr1->second]<<endl;
cin>>chose;
if(chose==0) continue;
else
{
jilu[rr1->second].setStatus_return();
jilu[rr1->second].setMax_r();
jilu[rr1->second].setHand_r();
cout<<jilu[rr1->second]<<endl;
}
}
multimap<string,int>::iterator bbb;
string bo=jilu[rr1->second].getBorrowB();
bbb=bb.find(bo);
book[bbb->second].getAa_return();
if(rr2==rr3) cout<<"未找到此用户记录"<<endl;
}
/*
int main()
{
string k;
UserOp u(k);
string a;
cin>>a;
u.modify_return(a);
return 0;
}
*/
void UserOp::modify_renew(string Rn)
{
bool choose;
multimap<string,int>::iterator rr1,rr2,rr3;
rr1=aa.find(Rn);
rr2=aa.lower_bound(Rn);
rr3=aa.upper_bound(Rn);
for(rr1=rr2;rr1!=rr3;rr1++)
{
cout<<jilu[rr1->second]<<endl;
cin>>choose;
if(choose==0) continue;
else
{
jilu[rr1->second].setStatus_renew();
cout<<jilu[rr1->second]<<endl;
}
}
if(rr2==rr3) cout<<"未找到此用户记录"<<endl;
}
/*
int main()
{
UserOp u;
string a;
cin>>a;
u.modify_renew(a);
return 0;
}
*/
void UserOp::search_Rname(string Rn)
{
multimap<string,int>::iterator r1,r2,r3;
r1=aa.find(Rn);
r2=aa.lower_bound(Rn);
r3=aa.upper_bound(Rn);
//cout<<r1->second<<endl;
for(r1=r2;r1!=r3;r1++) cout<<jilu[r1->second]<<endl;
if(r2==r3) cout<<"未找到此用户记录"<<endl;
}
void UserOp::search_Bname()
{
srch_BNa();
}
void UserOp::search_BNumber()
{
srch_BNu();
}
void UserOp::search_BAuthor()
{
srch_BAu();
}
void UserOp::search_BPH()
{
srch_ph();
}
void UserOp::search_time()
{
srch_pt();
}
/*
int main()
{
string k;
cin>>k;
UserOp u(k);
//u.search_Rname(a);
//u.search_Bname();
//u.search_BNumber();
//u.search_BAuthor();
//u.search_BPH();
//u.search_time();
return 0;
}*/
class Librarian:public Srch{
vector<Reader> xinxiR;
vector<Book> xinxiB;
vector<Reader>::iterator ir;
vector<Book>::iterator ib;
multimap<string,int>r1;//查找账户
multimap<string,int>b1;//查找图书
public:
Librarian(){loadR();loadB();cout<<endl;}
~Librarian(){saveR();saveB();cout<<endl;}
void loadR();
void loadB();
void saveR();
void saveB();
void addB();
void addR();
void delB();
void delR();
void search_Bname();
void search_BNumber();
void search_BAuthor();
void search_BPH();
void search_time();
void search_rName();
//用户本人借书记录:借书记录 未还图书(+是否有超期未还图书) 找到人 输出Record
//已借图书数量+是否已满a
void modifyB();
void modifyR();
void pay();//超期缴费
};
//书 出版日期 人 借阅日期
void Librarian::loadR()
{
Reader r;
ifstream in("2018212515-Reader.txt",ios::in);
if(in.is_open())
{
if(!in) return;
//cout<<"reader ok 1"<<endl;
while(in>>r)
{
xinxiR.push_back(r);
r1.insert(make_pair(r.getRNa(),xinxiR.size()-1));//按姓名查找
}
in.close();
}
}
void Librarian::loadB()
{
Book b;
ifstream in("2018212515-Book.txt",ios::in);
if(in.is_open())
{
if(!in) return;
//cout<<"book ok 2"<<endl;
while(in>>b)
{
xinxiB.push_back(b);
// b1.insert(make_pair(b.getBNa(),xinxiB.size()-1));//按书名查找
}
in.close();
}
}
void Librarian::saveR()
{
ofstream out("2018212515-Reader.txt",ios::out);
if(out.is_open())
{
//cout<<"out_reader ok 1"<<endl;
if(!out) return;
for(ir=xinxiR.begin();ir!=xinxiR.end();ir++)
{
out<<*ir<<endl;
// cout<<*ir<<endl;
}
}
out.close();
}
void Librarian::saveB()
{
ofstream out("2018212515-Book.txt",ios::out);
if(out.is_open())
{
//cout<<"book ok 2";
if(!out) return;
for(ib=xinxiB.begin();ib!=xinxiB.end();ib++)
{
out<<*ib<<endl;
//cout<<*ib<<endl;
}
}
out.close();
}
/*
main()
{
Librarian L;
return 0;
}
*/
void Librarian::addB()
{
Book b;
cin>>b;
xinxiB.push_back(b);
//b1.insert(make_pair(b.getBNa(),b1.size()-1));
}
void Librarian::addR()
{
Reader r;
cin>>r;
xinxiR.push_back(r);
r1.insert(make_pair(r.getRNa(),r1.size()-1));
}
/*
int main()
{
Librarian L;
L.addB();
L.addR();
return 0;
}
*/
void Librarian::search_Bname()
{
srch_BNa();
}
void Librarian::search_BNumber()
{
srch_BNu();
}
void Librarian::search_BAuthor()
{
srch_BAu();
}
void Librarian::search_BPH()
{
srch_ph();
}
void Librarian::search_time()
{
srch_pt();
}
void Librarian::search_rName()
{
multimap<string,int>::iterator i;
string rName;
while(1)
{
cin>>rName;
if(rName=="0") break;
else
{
i=r1.find(rName);
if(i==r1.end()) cout<<"此用户不存在";
else{
cout<<xinxiR[i->second];
}
}
}
}
/*
int main()
{
Librarian L;
//L.search_rName();
//L.search_Bname();
//L.search_BNumber();
//L.search_BAuthor();
//L.search_BPH();
//L.search_time();
return 0;
}
*/
void Librarian::delB()
{
multimap<string,int>::iterator i;
string b_name;
while(1)
{
cin>>b_name;
if(b_name=="0") break;
else{
i=b1.find(b_name);
if(i==b1.end()) cout<<"此书不存在";
else
{
int a=i->second;
xinxiB.erase(xinxiB.begin()+a);
b1.erase(b_name);
}
}
}
}
void Librarian::delR()
{
multimap<string,int>::iterator i;
string r_name;
while(1)
{
cin>>r_name;
if(r_name=="0") break;
else{
i=r1.find(r_name);
if(i!=r1.end())
{
int a=i->second;
xinxiR.erase(xinxiR.begin()+a);
r1.erase(r_name);
}
else cout<<"此用户不存在"<<endl;
}
}
}
/*
int main()
{
Librarian L;
L.delB();
L.delR();
return 0;
}
*/
void Librarian::modifyB()
{
multimap<string,int>::iterator i;
string name;
cin>>name;
i=b1.find(name);
if(i==b1.end()) cout<<"此图书不存在";
else xinxiB[i->second].setBNa();
}
void Librarian::modifyR()
{
multimap<string,int>::iterator i;
string name;
cin>>name;
i=r1.find(name);
if(i==r1.end()) cout<<"此用户不存在";
else
{
string newN;
cin>>newN;
xinxiR[i->second].setRNa(newN);
}
}
/*
int main()
{
Librarian L;
L.modifyB();
L.modifyR();
return 0;
}
*/