能力有限,并不完整的图书管理系统
#include
using namespace std;
class Time
{
int year,month,day;
public:
Time(){year=month=day=0;}
Time(int y,int m,int d){year=y;month=m;day=d;}
void setYear(int y){year=y;}
void setMonth(int m){month=m;}
void setDay(int d){day=d;}
int getYear(){return year;}
int getMonth(){return month;}
int getDay(){return day;}
void setTime(int y,int m,int d){year=y;month=m;day=d;}
bool operator<(const Time&t1)const
{
return year!=t1.year?year>(istream&is,Time&t);
friend ostream&operator<<(ostream&os,Time&t);
};
ostream&operator<<(ostream&os,Time&t)
{
os<>(istream&is,Time&t)
{
is>>t.year>>t.month>>t.day;
return is;
}
class record
{
int shuhao;
int xuehao;
Time jqi;
Time hqi;
int xjie;
int state;
public:
record(){}
record(int sh,int xh,Time jq):shuhao(sh),xuehao(xh),jqi(jq)
{
if(jq.getMonth()+2>12)
{
Time hq(jq.getYear()+1,jq.getMonth()-10,jq.getDay());
hqi=hq;
}
else
{
Time hq(jq.getYear(),jq.getMonth()+2,jq.getDay());
hqi=hq;
}
xjie=0;
state=0;
}
int getsh(){return shuhao;}
void setsh(int sh){shuhao=sh;}
int getxh(){return xuehao;}
void setxh(int xh){xuehao=xh;}
Time getjq(){return jqi;}
Time gethq(){return hqi;}
void sethq();
void setxj(){xjie=1;}
int getxj(){return xjie;}
void setstate(int n){state=n;}
int getstate(){return state;}
void setrecord(int sh,int xh,Time jq,Time hq){shuhao=sh;xuehao=xh;jqi=jq;hqi=hq;}
void display();
friend ostream&operator<<(ostream&os,record&r);
friend istream&operator>>(istream&is,record&r);
};
void record::sethq()
{Time hq;
if(hqi.getMonth()+1>12)
hq=Time(hqi.getYear()+1,hqi.getMonth()+1,hqi.getDay());
else
hq=Time(hqi.getYear()+1,hqi.getMonth(),hqi.getDay());
hqi=hq;
}
void record::display()
{
cout<<"书号:"<>(istream&is,record&r)
{
if(r.xuehao==0)
return is;
is>>r.xuehao;
is>>r.jqi;
is>>r.shuhao;
is>>r.hqi;
is>>r.xjie;
is>>r.state;
return is;
}
ostream&operator<<(ostream&os,record&r)
{
os<v1;
vector::iterator it1;
multimapm1;
multimap::iterator mit1;
book(){}
book(int sh,string sm,string zz,string cbs,double p,int zc,int jc)
{shuhao=sh;
shumi=sm;
cbans=cbs;
zongce=zc;
jiechu=jc;
shengyu=zongce-jiechu;
}
vectorgetrecord(){return v1;}
int getshuhao(){return shuhao;}
string getshumi(){return shumi;}
string getcbans(){return cbans;}
string getzuozhe(){return zuozhe;}
double getprice(){return price;}
void setzongce(int zc){zongce=zc;}
int getzongce(){return zongce;}
void setjiechu(int jc){jiechu=jc;}
int getjiechu(){return jiechu;}
void add(record r1);
void display();
};
void book::display()
{
cout<>(istream&is,book&b)
{
is>>b.shuhao;
if(b.shuhao==-1)
return is;
is>>b.shumi;
is>>b.zuozhe;
is>>b.cbans;
is>>b.price;
is>>b.zongce;
is>>b.jiechu;
}
ostream &operator<<(ostream&os,const book&b)
{
os<v2;
vector::iterator it2;
multimapm2;
multimap::iterator mit2;
public:
user(int xh,string na,int kj):xuehao(xh),name(na),kejie(kj){}
user(){cq=0;}
int getxh(){return xuehao;}
void setxh(int xh){xuehao=xh;}
string getna(){return name;}
void setna(string na){name=na;}
int getkj(){return kejie;}
void setkj(int kj){kejie=kj;}
void setcq(int kj){cq=kj;}
int getcq(){return cq;}
vectorgetrecord(){return v2;}
void addr2(record r2);
friend istream&operator>>(istream&is,user&u);
friend ostream&operator<<(ostream&os,user&u);
void operator=(user&u)
{
xuehao=u.getxh();
name=u.getna();
kejie=u.getkj();
v2=u.getrecord();
}
bool operator==(user u)
{
return this->xuehao==u.getxh()?1:0;
}
};
istream&operator>>(istream&is,user&u)
{
is>>u.xuehao;
if(u.xuehao==-1)
return is;
is>>u.name;
is>>u.kejie;
//is>>u.cq;
return is;
}
ostream&operator<<(ostream&os,user&u)
{
os<v3;
vector::iterator it3;
multimapm3;
multimap::iterator mit3;
vectorv4;
vector::iterator it4;
multimapm4;
multimap::iterator mit4;
public:
manage(){}
~manage()
{
save1();
save2();
}
void addbook();
void adduser();
void load1();
void load2();
void save1();
void save2();
};
void manage::load1()//读取
{
book b;
int i;
ifstream infile("d:\\20171748book.txt",ios::in);
if(!infile)
return;
v3.clear();
m3.clear();
i=0;
while(infile>>b)
{v3.push_back(b);
m3.insert(make_pair(b.getshuhao(),i-1));
i++;
}
infile.close();
}
void manage::save1()
{
ofstream outfile("d:\\20171748book.txt",ios::out);
if(!outfile)
return ;
for(it3=v3.begin();it3!=v3.end();it3++)
{
outfile<<*it3;
}
outfile.close();
}
void manage::load2()
{
user u;
int i;
ifstream infile("d:\\20171748stu.txt",ios::in);
if(!infile)
return;
v4.clear();
m4.clear();
i=0;
//infile>>u;
while(infile>>u)
{
v4.push_back(u);
m4.insert(make_pair(u.getxh(),i));
i++;
}
infile.close();
}
void manage::save2()//写入
{
ofstream outfile("d:\\20171748stu.txt",ios::out);
if(!outfile)
return ;
for(it4=v4.begin();it4!=v4.end();it4++)
{
outfile<<*it4;
}
outfile.close();
}
void manage::addbook()
{
int i;
while(1)
{
book b;
if(b.getshuhao()==-1)
break;
v3.push_back(b);
i=v3.size();
m3.insert(make_pair(b.getshuhao(),i-1));
ofstream outfile("d:\\20171748book.txt",ios::app);
if(!outfile)
return ;
outfile<>sh>>xh>>year>>month>>day;
jq.setTime(year,month,day);
record x(sh,xh,jq);
x.display();
}
}*/
class client
{
vectorv5;
vector::iterator it5;
multimapm5;
multimap::iterator mit5;
user u;
public:
client(){load3();load4();}
~client(){save3();save4();}
void load3();
void save3();
void load4();
void save4();
int search5(int sh);
void querybook();
void jie();
void huan();
};
void client::save3()
{
ofstream outfile("d:\\20171748book.txt",ios::out);
if(!outfile) return;
for(it5=v5.begin();it5!=v5.end();it5++)
outfile<<*it5;
outfile.close();
}
void client::load3()
{
book b;
ifstream infile("d:\\20171748book.txt",ios::in);
if(!infile) return;
v5.clear();
m5.clear();
while(infile>>b)
{
v5.push_back(b);
int i=v5.size();
m5.insert(make_pair(b.getshuhao(),i-1));
}
infile.close();
}
void client::load4()
{
int xh;
cin>>xh;
user u;
int i;
ifstream infile("d:\\20171748stu.txt",ios::in);
if(!infile) return;
while(infile>>u)
{
if(u.getxh()==xh)
this->u=u;
}
infile.close();
}
void client::save4()
{
vectorv;
vector::iterator it;
user u1;
ifstream infile("d:\\20171748stu.txt",ios::in);
if(!infile) return;
while(infile>>u1)
{
if(u1==this->u)
u1=this->u;
v.push_back(u1);
}
infile.close();
ofstream outfile("d:\\20171748stu.txt",ios::out);
if(!outfile) return;
for(it=v.begin();it!=v.end();it++)
outfile<<*it;
outfile.close();
}
void client::jie()
{
int sh,shumi;
Time t;
cin>>sh>>t;
record r(sh,u.getxh(),t);
user u;
u.addr2(r);
ofstream outfile("d:\\20171748book.txt",ios::app);
outfile<>sh>>h;
}
int main()
{
manage m;
m.addbook();
m.adduser();
client c;
c.jie();
c.huan();
}