请大一做此份作业的同学不要借鉴太多。加油。
#include
using namespace std;
class Time
{
int year;
int month;
int day;
int hour;
public:
Time(int x,int y,int z,int v):year(x),month(y),day(z),hour(v){}
Time(){}
int getYear(){return year;};
int getMonth(){return month;};
int getDay(){return day;};
int getHour(){return hour;};
bool operator<(const Time&d)const
{
return year!=d.year?year
friend ostream&operator<<(ostream &os, const Time &d);
friend istream&operator>>(istream &in, Time &d);
};
ostream&operator<<(ostream &os,const Time &d)
{
os<
}
istream&operator>>(istream &in,Time &d)
{
in>>d.year;
in>>d.month;
in>>d.day;
in>>d.hour;
/*while(1)
{
in>>d.year;
if(d.year>1900&&d.year<2019)
break;
else cout<<"请重输\n";
}
while(1)
{
in>>d.month;
if(d.month>0&&d.month<13)
break;
else cout<<"请重输\n";
}
while(1)
{
in>>d.day;
if(d.day>0&&d.day<32)
break;
else cout<<"请重输\n";
}
while(1)
{
in>>d.hour;
if(d.hour>0&&d.hour<24)
break;
else cout<<"请重输\n";
}
*/
return in;
}
/*
记录类
1.包含借阅人一部分信息
2.借阅图书序号及少部分信息
3.简易为下面服务的函数及运算符重载;
*/
class Record
{
string name;
int id;
int id1;
int code;
int major;
int classes;
int nowBorrows;
int breaks;
string type;
Time start;
Time end;
bool either;
Time changeEnd;
public:
Record(Time t1,Time t2);
Record(){changeEnd=end;}
Time getStart(){return start;};
Time getEnd(){return end;};
Time setChange(Time t){changeEnd=t;}
int getNo(){return id;};
int getId(){return id1;};
string getType(){return type;};
string getName(){return name;};
friend ostream&operator<<(ostream&os,const Record&r);
friend istream&operator>>(istream&in,Record&r);
};
istream&operator>>(istream&in,Record&r)
{
in>>r.id;
if(r.id==0)return in;
in>>r.id1;
in>>r.type;
in>>r.start;
in>>r.end;
r.changeEnd=r.end;
return in;
}
ostream&operator<<(ostream&os,const Record&r)
{
os<
}
Record::Record(Time t1,Time t2)
{
start=t1;
end=t2;
changeEnd=end;
}
/*
书数据类
1.提供书的信息
2.提供这本书一些人借阅记录查阅
3.可借数量,判断函数为下面操作类服务
*/
class Book//书籍类
{
string name;
string name1;
string press;
int no;
int number;//每类书的总数
int borrow;//借出数量
int left;
vector
int num;
public:
Book(string name1,int no1,string press1,int number1,int num1):name(name1),no(no1),press(press1),number(number1),num(num1){}
Book(){number=0;borrow=0;num=0;}
string getName(){return name;};
string getPress(){return press;};
Record getRecord(int i){return r[i];};
void addBorrowsJ(int n){borrow+=n;}
void addBorrowsH(int n){borrow-=n;};
int getNo(){return no;};
int getNum(){return num;};
void setNum(int i){num+=i;};
void addRecord(Record rr){num++;r.push_back(rr);};
int getNowNumber(){return (number-borrow);}//可借数量
int getNumber(){return number;};
int getBorrows(){return borrow;};
int getLeft(){return left;};
friend ostream&operator<<(ostream&os,const Book&b);
friend istream&operator>>(istream&in,Book&b);
};
istream&operator>>(istream&in,Book&b)
{
in>>b.name;
if(b.name=="E")return in;
in>>b.no>>b.name1>>b.press>>b.number>>b.num;
for(int i=0;i
Record rr;
in>>rr;
b.r.push_back(rr);
}
return in;
}
ostream&operator<<(ostream&os,const Book&b)
{
os<
os<
return os;
}
/*
用户数据类
1.提供大多数数据
2.包含一部分小函数
3.查询函数,显示函数,修改函数,为操作类服务;
4.一部分注释,修改版
*/
class User
{
string name;
string major;
string classes;
int id;
int num;//记录条数
int code;
int borrows;
int nowBorrows;
int canReborrow;
bool breaks;
vector
multimap
multimap
multimap
multimap
vector
vector
multimap
multimap
multimap
multimap
multimap
}
}
}
void User::queryTime(Time t)
{
for(it=r.begin();it!=r.end();it++)
{
if(it->getEnd()
}
}
void User::show()
{
for(it=r.begin();it!=r.end();it++)
{
cout<<*it;
}
}
/*void User::load()
{
int i;
Book bb;
ifstream infile("d:\\User.txt",ios::in);
if(!infile)
return;
b.clear();
b1.clear();
b2.clear();
i=0;
while(infile>>bb)
{
b.push_back(bb);
b1.insert(make_pair(bb.getNo(),i));
b2.insert(make_pair(bb.getName(),i));
i++;
}
infile.close();
}
void User::reBorrow()
{
bool e;
if(!can())
{
cout<<"您已达借阅上限\n";
}
else
{
cout<<"您想续借书的序号以及借到的时间\n";
int s;
cin>>s;
Time t;
cin>>t;
for(it=r.begin();it!=r.end();it++)
{
if(r[it-r.begin()].getId()==s)
r[it-r.begin()].setChange(t);
}
}
}*/
void User::queryNow()
{
cout<<"输入当前时间\n";
Time t;
cin>>t;
for(it=r.begin();it!=r.end();it++)
{
if(r[it-r.begin()].getEnd()
}
/*void User::queryId(int ids)
{
it=find_if(r.begin(),r.end(),cmp1(ids));
while(it!=r.end())
{
cout<<"found:\t"<
}
}*/
istream&operator>>(istream&in,User &u)
{
in>>u.id;
if(u.id==0)return in;
in>>u.code>>u.name>>u.major>>u.classes>>u.nowBorrows>>u.breaks>>u.num;
for(int i=0;i
Record rr;
in>>rr;
u.r.push_back(rr);
}
return in;
}
ostream&operator<<(ostream&os,User&u)
{
os<
os<
}
/*
操作类
1.查询当前信息
2.查询记录
2.借还书
3.续借
4.添加记录
*/
class Operate
{
vector
vector
multimap
multimap
multimap
multimap
vector
vector
multimap
multimap
multimap
multimap
User user;
public:
public:
Operate()
{
load1();
load2();
}
~Operate()
{
load1p();
load2p();
}
void load1();//把文件中的数据读到vector里
void load2();
void load1p();//析构函数
void load2p();
void addOne();
void addSome();//增加记录;
void reBorrow();//修改时间
void queryNow();
void queryHistory();
};
void Operate::reBorrow()
{
cout<<"您的学号为\n";
int id;
cin>>id;
cout<<"您想续借的书的序号为\n";
int no;
cin>>no;
cout<<"您想更改的日期为\n";
Time t;
cin>>t;
for(it=u.begin();it!=u.end();it++)
{
if(it->getId()==id)//找到这一个人
{
if(it->getNowReborrow()>1)
{
cout<<"续借失败\n";
return;
}
it->addReborrow(1);
it->changeTime(no,t);
cout<<"修改成功\n";
}
}
}
void Operate::queryNow()
{
cout<<"您的学号为\n";
int id;
cin>>id;
cout<<"请输入当今时间\n";
Time t;
cin>>t;
for(it=u.begin();it!=u.end();it++)
{
if(it->getId()==id)
it->queryTime(t);
}
}
void Operate::queryHistory()
{
cout<<"您的学号为\n";
int id;
cin>>id;
cout<<"您的记录为\n";
for(it=u.begin();it!=u.end();it++)
{
if(it->getId()==id)
{
cout<<*it;
}
}
}
void Operate::addOne()
{
cout<<"您想借阅书的编号您的学号等信息\n";
Record rr;
Book bb;
bool e=1;//判断
cin>>rr;
int no=rr.getNo();
int id=rr.getId();
if(rr.getType()=="J")//借书类型
{
for(it=u.begin();it!=u.end();it++)
{
if(it->getId()==id)
{
if(it->getNowBorrows()>10)
{
e=0;
break;
}
cout<<"添加成功\n";
u[it-u.begin()].addRecord(rr);
u[it-u.begin()].addNowBorrowsJ(1);//该学生可借数量减1
}
}
if(e==1)
{
for(it1=b.begin();it1!=b.end();it1++)
{
if(it1->getNo()==no)
{
if(it1->getNowNumber()>0)
{
cout<<"添加成功\n";
b[it1-b.begin()].addRecord(rr);
b[it1-b.begin()].addBorrowsJ(1);//书的数量变化
}
}
}
}
}
if(rr.getType()=="H")//还书类型
{
for(it=u.begin();it!=u.end();it++)
{
if(it->getId()==id)
{
cout<<"添加成功\n";
u[it-u.begin()].addRecord(rr);
u[it-u.begin()].addNowBorrowsH(1);//该学生可借数量减1
}
}
for(it1=b.begin();it1!=b.end();it1++)
{
if(it1->getNo()==no)
{
cout<<"添加成功\n";
b[it1-b.begin()].addRecord(rr);
b[it1-b.begin()].addBorrowsH(1);//书的数量变化
}
}
}
}
void Operate::addSome()
{
while(1)
{
cout<<"您想借阅书的编号您的学号等信息,输入书号为0结束\n";
Record rr;
Book bb;
bool e=1;//判断
cin>>rr;
if(rr.getNo()==0)break;
int no=rr.getNo();
int id=rr.getId();
if(rr.getType()=="J")//借书类型
{
for(it=u.begin();it!=u.end();it++)
{
if(it->getId()==id)
{
if(it->getNowBorrows()>10)
{
e=0;
break;
}
cout<<"添加成功\n";
u[it-u.begin()].addRecord(rr);
u[it-u.begin()].addNowBorrowsJ(1);//该学生可借数量减1
}
}
if(e==1)
{
for(it1=b.begin();it1!=b.end();it1++)
{
if(it1->getNo()==no)
{
if(it1->getNowNumber()>0)
{
cout<<"添加成功\n";
b[it1-b.begin()].addRecord(rr);
b[it1-b.begin()].addBorrowsJ(1);//书的数量变化
}
}
}
}
}
if(rr.getType()=="H")//还书类型
{
for(it=u.begin();it!=u.end();it++)
{
if(it->getId()==id)
{
cout<<"添加成功\n";
u[it-u.begin()].addRecord(rr);
u[it-u.begin()].addNowBorrowsH(1);//该学生可借数量减1
}
}
for(it1=b.begin();it1!=b.end();it1++)
{
if(it1->getNo()==no)
{
cout<<"添加成功\n";
b[it1-b.begin()].addRecord(rr);
b[it1-b.begin()].addBorrowsH(1);//书的数量变化
}
}
}
}
}
void Operate::load1p()
{
ofstream outfileB("e:\\20171789book.txt",ios::out);
if(!outfileB)
return;
for(it1=b.begin();it1!=b.end();it1++)
{
outfileB<<*it1;
}
outfileB.close();
}
void Operate::load2p()
{
ofstream outfileS("e:\\20171789stu.txt",ios::out);
if(!outfileS)
return;
for(it=u.begin();it!=u.end();it++)
{
outfileS<<*it;
}
outfileS.close();
}
void Operate::load1()
{
int i;
Book bb;
ifstream infile("e:\\20171789book.txt",ios::in);
if(!infile)
return;
b.clear();
b1.clear();
b2.clear();
i=0;
while(infile>>bb)
{
b.push_back(bb);
b1.insert(make_pair(bb.getNo(),i));
b2.insert(make_pair(bb.getName(),i));
i++;
}
infile.close();
}
void Operate::load2()
{
int i;
User uu;
ifstream infile("e:\\20171789stu.txt",ios::in);
if(!infile)
return;
u.clear();
u1.clear();
u2.clear();
i=0;
while(infile>>uu)
{
u.push_back(uu);
u1.insert(make_pair(uu.getId(),i));
u2.insert(make_pair(uu.getName(),i));
i++;
}
infile.close();
}
/*void Operate::query()
{
cout<<"学生学号为\n";
int id;
cin>>id;
for(it=u.begin();it!=u.end();it++)
{
if(u[it-u.begin()].getId()==id)
cout<<*it<
}
void Operate::reBorrow()
{
user.reBorrow();
}*/
/*
管理员类
1.增加学生图书信息
2.删除学生图书信息
3.修改学生图书信息
4.查询学生图书信息
*/
class Adm//更新为STL
{
vector
vector
multimap
multimap
multimap
multimap
vector
vector
multimap
multimap
multimap
multimap
//对书集合和学生集合操作
public:
Adm()
{
load1();
load2();
}
~Adm()
{
load1p();
load2p();
}
void load1();//把文件中的数据读到vector里
void load2();
void load1p();//析构函数
void load2p();
void addUser();//增加一个用户
void addBook();
void deletesU();//删除一个用户
void deletesB();
void searchS();
void searchB();
void queryIdS();//查询
void queryIdB();
void changeU();//修改
void changeB();
};
void Adm::load1p()
{
ofstream outfileB("e:\\20171789book.txt",ios::out);
if(!outfileB)
return;
for(it1=b.begin();it1!=b.end();it1++)
{
outfileB<<*it1;
}
outfileB.close();
}
void Adm::load2p()
{
ofstream outfileS("e:\\20171789stu.txt",ios::out);
if(!outfileS)
return;
for(it=u.begin();it!=u.end();it++)
{
outfileS<<*it;
}
outfileS.close();
}
void Adm::queryIdS()//STL
{
cout<<"你想查询的学生学号为\n";
User uu;
int id;
cin>>id;
u1p=u1.find(id);
cout<second];
}
void Adm::queryIdB()
{
cout<<"你想查询的书号为\n";
Book bb;
int id;
cin>>id;
b1p=b1.find(id);
cout<second];
}
void Adm::changeU()//STL
{
cout<<"您想修改信息的学生的学号为\n";
User uu;
int id;
cin>>id;
u1p=u1.find(id);//it??
it=u.begin()+u1p->second;
u.erase(it);
u1.erase(id);//删除map内指定元素;
cout<<"请重输\n";
cin>>uu;
u.insert(it,uu);
u1.insert(u1p,uu);
cout<<"修改信息成功\n";
}
void Adm::changeB()//STL
{
cout<<"您想修改信息的书的编号为\n";
Book bb;
int id;
cin>>id;
b1p=b1.find(id);
it1=b.begin()+b1p->second;
b.erase(it1);
b1.erase(id);
cout<<"请重输\n";
cin>>bb;
b.insert(it1,bb);
cout<<"修改信息成功\n";
}
void Adm::deletesU()
{
cout<<"你想删除的学生学号为\n";
int id;
User uu;
cin>>id;
u1p=u1.find(id);//it??
it=u.begin()+u1p->second;
it=u.erase(it);
cout<<"删除成功\n";
}
void Adm::deletesB()
{
cout<<"您想删除的书的编号是\n";
int id;
Book bb;
cin>>id;
b1p=b1.find(id);
it1=b.begin()+b1p->second;
it1=b.erase(it1);
cout<<"删除成功\n";
}
void Adm::addUser()
{
cout<<"您想增加的用户信息为,学号输入为0结束\n";
User uu;
while(cin>>uu)
{
if(uu.getId()==0)break;
u.push_back(uu);
cout<<"增加用户信息成功\n";
}
};
void Adm::addBook()
{
cout<<"您想增加的图书信息为:书名输入为E结束\n";
Book bb;
while(cin>>bb)
{
if(bb.getName()=="E")break;
b.push_back(bb);
cout<<"增加图书信息成功\n";
}
}
void Adm::load1()
{
int i;
Book bb;
ifstream infile("e:\\20171789book.txt",ios::in);
if(!infile)
return;
b.clear();
b1.clear();
b2.clear();
i=0;
while(infile>>bb)
{
b.push_back(bb);
b1.insert(make_pair(bb.getNo(),i));
b2.insert(make_pair(bb.getName(),i));
i++;
}
infile.close();
}
void Adm::load2()
{
int i;
User uu;
ifstream infile("e:\\20171789stu.txt",ios::in);
if(!infile)
return;
u.clear();
u1.clear();
u2.clear();
i=0;
while(infile>>uu)
{
u.push_back(uu);
u1.insert(make_pair(uu.getId(),i));
u2.insert(make_pair(uu.getName(),i));
i++;
}
infile.close();
}
int main()
{
//Operate o;
//o.addOne();
//o.queryHistory();
//o.queryNow();
Adm a;
a.deletesB();
//a.queryIdB();
//a.queryIdS();
//a.deletesU();
//a.addUser();
//a.addBook();
//a.deletesB();
}
//最终版
2017 666 FFF JJJ 2 1 1 0
2018 666 FFF JJJ 2 4 0 1
113 2018 J 2018 7 7 7 2019 9 9 9
2019 666 YYY III 2 1 0 0
FFF 111 HHH UUU 1 0
RRR 112 HHH UUU 1 0
YYY 113 UUU III 1 1
113 2018 J 2018 7 7 7 2019 9 9 9
#include
using namespace std;
class Time
{
int year;
int month;
int day;
int hour;
public:
Time(int x,int y,int z,int v):year(x),month(y),day(z),hour(v){}
Time(){}
int getYear(){return year;};
int getMonth(){return month;};
int getDay(){return day;};
int getHour(){return hour;};
bool operator<(const Time&d)const
{
return year!=d.year?year
friend ostream&operator<<(ostream &os, const Time &d);
friend istream&operator>>(istream &in, Time &d);
};
ostream&operator<<(ostream &os,const Time &d)
{
os<
}
istream&operator>>(istream &in,Time &d)
{
in>>d.year;
in>>d.month;
in>>d.day;
in>>d.hour;
/*while(1)
{
in>>d.year;
if(d.year>1900&&d.year<2019)
break;
else cout<<"请重输\n";
}
while(1)
{
in>>d.month;
if(d.month>0&&d.month<13)
break;
else cout<<"请重输\n";
}
while(1)
{
in>>d.day;
if(d.day>0&&d.day<32)
break;
else cout<<"请重输\n";
}
while(1)
{
in>>d.hour;
if(d.hour>0&&d.hour<24)
break;
else cout<<"请重输\n";
}
*/
return in;
}
/*
记录类
1.包含借阅人一部分信息
2.借阅图书序号及少部分信息
3.简易为下面服务的函数及运算符重载;
*/
class Record
{
string name;
int id;
int id1;
int code;
int major;
int classes;
int nowBorrows;
int breaks;
string type;
Time start;
Time end;
bool either;
Time changeEnd;
public:
Record(Time t1,Time t2);
Record(){changeEnd=end;}
Time getStart(){return start;};
Time getEnd(){return end;};
Time setChange(Time t){changeEnd=t;}
int getNo(){return id;};
int getId(){return id1;};
string getType(){return type;};
string getName(){return name;};
friend ostream&operator<<(ostream&os,const Record&r);
friend istream&operator>>(istream&in,Record&r);
};
istream&operator>>(istream&in,Record&r)
{
in>>r.id;
if(r.id==0)return in;
in>>r.id1;
in>>r.type;
in>>r.start;
in>>r.end;
r.changeEnd=r.end;
return in;
}
ostream&operator<<(ostream&os,const Record&r)
{
os<
}
Record::Record(Time t1,Time t2)
{
start=t1;
end=t2;
changeEnd=end;
}
/*
书数据类
1.提供书的信息
2.提供这本书一些人借阅记录查阅
3.可借数量,判断函数为下面操作类服务
*/
class Book//书籍类
{
string name;
string name1;
string press;
int no;
int number;//每类书的总数
int borrow;//借出数量
int left;
vector
int num;
public:
Book(string name1,int no1,string press1,int number1,int num1):name(name1),no(no1),press(press1),number(number1),num(num1){}
Book(){number=0;borrow=0;num=0;}
string getName(){return name;};
string getPress(){return press;};
Record getRecord(int i){return r[i];};
void addBorrowsJ(int n){borrow+=n;}
void addBorrowsH(int n){borrow-=n;};
int getNo(){return no;};
int getNum(){return num;};
void setNum(int i){num+=i;};
void addRecord(Record rr){num++;r.push_back(rr);};
int getNowNumber(){return (number-borrow);}//可借数量
int getNumber(){return number;};
int getBorrows(){return borrow;};
int getLeft(){return left;};
friend ostream&operator<<(ostream&os,const Book&b);
friend istream&operator>>(istream&in,Book&b);
};
istream&operator>>(istream&in,Book&b)
{
in>>b.name;
if(b.name=="E")return in;
in>>b.no>>b.name1>>b.press>>b.number>>b.num;
for(int i=0;i
Record rr;
in>>rr;
b.r.push_back(rr);
}
return in;
}
ostream&operator<<(ostream&os,const Book&b)
{
os<
os<
return os;
}
/*
用户数据类
1.提供大多数数据
2.包含一部分小函数
3.查询函数,显示函数,修改函数,为操作类服务;
4.一部分注释,修改版
*/
class User
{
string name;
string major;
string classes;
int id;
int num;//记录条数
int code;
int borrows;
int nowBorrows;
int canReborrow;
bool breaks;
vector
multimap
multimap
multimap
multimap
vector
vector
multimap
multimap
multimap
multimap
multimap
multimap
public:
User()
{borrows=10;breaks=0;nowBorrows=0;canReborrow=1;}
void addOne();
void addSome();
int getNowBorrows(){return nowBorrows;};
int getNowReborrow(){return canReborrow;};
int getBreaks(){return breaks;};
int getId(){return id;}
string getName(){return name;}
void addReborrow(int i){canReborrow-=i;};
void addBreaks(int m){breaks+=m;};
void addNowBorrowsJ(int m){nowBorrows+=m;};
void addNowBorrowsH(int m){nowBorrows-=m;};
void addRecord(Record rr){num++;r.push_back(rr);}
void show();
void queryTime(Time t);
void changeTime(int no,Time t);
void queryNow();
//void reBorrow();
friend istream&operator>>(istream&in,User &u);
friend ostream&operator<<(ostream&os,User &u);
};
void User::changeTime(int no,Time t)//具体哪一位学生
{
for(it=r.begin();it!=r.end();it++)
{
if(it->getNo()==no)
{
r[it-r.begin()].setChange(t);
}
}
}
void User::queryTime(Time t)
{
for(it=r.begin();it!=r.end();it++)
{
if(it->getEnd()
}
}
void User::show()
{
for(it=r.begin();it!=r.end();it++)
{
cout<<*it;
}
}
/*void User::load()
{
int i;
Book bb;
ifstream infile("d:\\User.txt",ios::in);
if(!infile)
return;
b.clear();
b1.clear();
b2.clear();
i=0;
while(infile>>bb)
{
b.push_back(bb);
b1.insert(make_pair(bb.getNo(),i));
b2.insert(make_pair(bb.getName(),i));
i++;
}
infile.close();
}
void User::reBorrow()
{
bool e;
if(!can())
{
cout<<"您已达借阅上限\n";
}
else
{
cout<<"您想续借书的序号以及借到的时间\n";
int s;
cin>>s;
Time t;
cin>>t;
for(it=r.begin();it!=r.end();it++)
{
if(r[it-r.begin()].getId()==s)
r[it-r.begin()].setChange(t);
}
}
}*/
void User::queryNow()
{
cout<<"输入当前时间\n";
Time t;
cin>>t;
for(it=r.begin();it!=r.end();it++)
{
if(r[it-r.begin()].getEnd()
}
/*void User::queryId(int ids)
{
it=find_if(r.begin(),r.end(),cmp1(ids));
while(it!=r.end())
{
cout<<"found:\t"<
}
}*/
istream&operator>>(istream&in,User &u)
{
in>>u.id;
if(u.id==0)return in;
in>>u.code>>u.name>>u.major>>u.classes>>u.nowBorrows>>u.breaks>>u.num;
for(int i=0;i
Record rr;
in>>rr;
u.r.push_back(rr);
}
return in;
}
ostream&operator<<(ostream&os,User&u)
{
os<
os<
}
/*
操作类
1.查询当前信息
2.查询记录
2.借还书
3.续借
4.添加记录
*/
class Operate
{
vector
vector
multimap
multimap
multimap
multimap
vector
vector
multimap
multimap
multimap
multimap
User user;
public:
public:
Operate()
{
load1();
load2();
}
~Operate()
{
load1p();
load2p();
}
void load1();//把文件中的数据读到vector里
void load2();
void load1p();//析构函数
void load2p();
void addOne();
void addSome();//增加记录;
void reBorrow();//修改时间
void queryNow();
void queryHistory();
};
void Operate::reBorrow()
{
cout<<"您的学号为\n";
int id;
cin>>id;
cout<<"您想续借的书的序号为\n";
int no;
cin>>no;
cout<<"您想更改的日期为\n";
Time t;
cin>>t;
for(it=u.begin();it!=u.end();it++)
{
if(it->getId()==id)//找到这一个人
{
if(it->getNowReborrow()>1)
{
cout<<"续借失败\n";
return;
}
it->addReborrow(1);
it->changeTime(no,t);
cout<<"修改成功\n";
}
}
}
void Operate::queryNow()
{
cout<<"您的学号为\n";
int id;
cin>>id;
cout<<"请输入当今时间\n";
Time t;
cin>>t;
for(it=u.begin();it!=u.end();it++)
{
if(it->getId()==id)
it->queryTime(t);
}
}
void Operate::queryHistory()
{
cout<<"您的学号为\n";
int id;
cin>>id;
cout<<"您的记录为\n";
for(it=u.begin();it!=u.end();it++)
{
if(it->getId()==id)
{
cout<<*it;
}
}
}
void Operate::addOne()
{
cout<<"您想借阅书的编号您的学号等信息\n";
Record rr;
Book bb;
bool e=0;//判断
cin>>rr;
int no=rr.getNo();
int id=rr.getId();
if(rr.getType()=="J")//借书类型
{
for(it=u.begin();it!=u.end();it++)
{
if(it->getId()==id)
{
if(it->getNowBorrows()>10)
{
e=1;
break;
}
cout<<"添加成功\n";
u[it-u.begin()].addRecord(rr);
u[it-u.begin()].addNowBorrowsJ(1);//该学生可借数量减1
}
}
if(e==1)
{
for(it1=b.begin();it1!=b.end();it1++)
{
if(it1->getNo()==no)
{
if(it1->getNowNumber()>0)
{
cout<<"添加成功\n";
b[it1-b.begin()].addRecord(rr);
b[it1-b.begin()].addBorrowsJ(1);//书的数量变化
}
}
}
}
}
if(rr.getType()=="H")//还书类型
{
for(it=u.begin();it!=u.end();it++)
{
if(it->getId()==id)
{
cout<<"添加成功\n";
u[it-u.begin()].addRecord(rr);
u[it-u.begin()].addNowBorrowsH(1);//该学生可借数量减1
}
}
for(it1=b.begin();it1!=b.end();it1++)
{
if(it1->getNo()==no)
{
cout<<"添加成功\n";
b[it1-b.begin()].addRecord(rr);
b[it1-b.begin()].addBorrowsH(1);//书的数量变化
}
}
}
}
void Operate::addSome()
{
while(1)
{
cout<<"您想借阅书的编号您的学号等信息,输入书号为0结束\n";
Record rr;
Book bb;
bool e=0;//判断
cin>>rr;
if(rr.getNo()==0)break;
int no=rr.getNo();
int id=rr.getId();
if(rr.getType()=="J")//借书类型
{
for(it=u.begin();it!=u.end();it++)
{
if(it->getId()==id)
{
if(it->getNowBorrows()>10)
{
e=1;
break;
}
cout<<"添加成功\n";
u[it-u.begin()].addRecord(rr);
u[it-u.begin()].addNowBorrowsJ(1);//该学生可借数量减1
}
}
if(e==1)
{
for(it1=b.begin();it1!=b.end();it1++)
{
if(it1->getNo()==no)
{
if(it1->getNowNumber()>0)
{
cout<<"添加成功\n";
b[it1-b.begin()].addRecord(rr);
b[it1-b.begin()].addBorrowsJ(1);//书的数量变化
}
}
}
}
}
if(rr.getType()=="H")//还书类型
{
for(it=u.begin();it!=u.end();it++)
{
if(it->getId()==id)
{
cout<<"添加成功\n";
u[it-u.begin()].addRecord(rr);
u[it-u.begin()].addNowBorrowsH(1);//该学生可借数量减1
}
}
for(it1=b.begin();it1!=b.end();it1++)
{
if(it1->getNo()==no)
{
cout<<"添加成功\n";
b[it1-b.begin()].addRecord(rr);
b[it1-b.begin()].addBorrowsH(1);//书的数量变化
}
}
}
}
}
void Operate::load1p()
{
ofstream outfileB("e:\\book.txt",ios::out);
if(!outfileB)
return;
for(it1=b.begin();it1!=b.end();it1++)
{
outfileB<<*it1;
}
outfileB.close();
}
void Operate::load2p()
{
ofstream outfileS("e:\\student.txt",ios::out);
if(!outfileS)
return;
for(it=u.begin();it!=u.end();it++)
{
outfileS<<*it;
}
outfileS.close();
}
void Operate::load1()
{
int i;
Book bb;
ifstream infile("e:\\book.txt",ios::in);
if(!infile)
return;
b.clear();
b1.clear();
b2.clear();
i=0;
while(infile>>bb)
{
b.push_back(bb);
b1.insert(make_pair(bb.getNo(),i));
b2.insert(make_pair(bb.getName(),i));
i++;
}
infile.close();
}
void Operate::load2()
{
cout<<"hello worldope!\n";
int i;
User uu;
ifstream infile("e:\\student.txt",ios::in);
if(!infile)
return;
u.clear();
u1.clear();
u2.clear();
i=0;
while(infile>>uu)
{
u.push_back(uu);
u1.insert(make_pair(uu.getId(),i));
u2.insert(make_pair(uu.getName(),i));
i++;
}
infile.close();
}
/*void Operate::query()
{
cout<<"学生学号为\n";
int id;
cin>>id;
for(it=u.begin();it!=u.end();it++)
{
if(u[it-u.begin()].getId()==id)
cout<<*it<
}
void Operate::reBorrow()
{
user.reBorrow();
}*/
/*
管理员类
1.增加学生图书信息
2.删除学生图书信息
3.修改学生图书信息
4.查询学生图书信息
*/
class Adm
{
vector
vector
multimap
multimap
multimap
multimap
vector
vector
multimap
multimap
multimap
multimap
//对书集合和学生集合操作
public:
Adm()
{
load1();
load2();
}
~Adm()
{
load1p();
load2p();
}
void load1();//把文件中的数据读到vector里
void load2();
void load1p();//析构函数
void load2p();
void addUser();//增加一个用户
void addBook();
void deletesU();//删除一个用户
void deletesB();
void queryIdS();//查询
void queryIdB();
void changeU();//修改
void changeB();
};
void Adm::load1p()
{
ofstream outfileB("e:\\book.txt",ios::out);
if(!outfileB)
return;
for(it1=b.begin();it1!=b.end();it1++)
{
outfileB<<*it1;
}
outfileB.close();
}
void Adm::load2p()
{
ofstream outfileS("e:\\student.txt",ios::out);
if(!outfileS)
return;
for(it=u.begin();it!=u.end();it++)
{
outfileS<<*it;
}
outfileS.close();
}
void Adm::queryIdS()
{
cout<<"你想查询的学生学号为\n";
User uu;
int id;
cin>>id;
for(it=u.begin();it!=u.end();it++)
{
if(u[it-u.begin()].getId()==id)
{
cout<<*it;
uu=*it;
}
}
}
void Adm::queryIdB()
{
cout<<"你想查询的书号为\n";
Book bb;
int id;
cin>>id;
for(it1=b.begin();it1!=b.end();it1++)
{
if(b[it1-b.begin()].getNo()==id)
{
cout<<*it1;
bb=*it1;
}
}
}
void Adm::changeU()
{
cout<<"您想修改信息的学生的学号为\n";
User uu;
int id;
cin>>id;
for(it=u.begin();it!=u.end();it++)
{
if(u[it-u.begin()].getId()==id)
{
u.erase(it);
u1.erase(id);//删除map内指定元素;
cout<<"请重输\n";
cin>>uu;
u.insert(it,uu);
cout<<"修改信息成功\n";
}
}
}
void Adm::changeB()
{
cout<<"您想修改信息的书的编号为\n";
Book bb;
int id;
cin>>id;
for(it1=b.begin();it1!=b.end();it1++)
{
if(b[it1-b.begin()].getNo()==id)
{
b.erase(it1);
b1.erase(id);
cout<<"请重输\n";
cin>>bb;
b.insert(it1,bb);
cout<<"修改信息成功\n";
}
}
}
void Adm::deletesU()
{
cout<<"你想删除的学生学号为\n";
int id;
User uu;
cin>>id;
for(it=u.begin();it!=u.end();)
{
if(u[it-u.begin()].getId()==id)
{
it=u.erase(it);
cout<<"删除成功\n";
}
else
{
it++;
}
}
}
void Adm::deletesB()
{
cout<<"您想删除的书的编号是\n";
int id;
Book bb;
cin>>id;
for(it1=b.begin();it1!=b.end();)
{
if(b[it1-b.begin()].getNo()==id)
{
it1=b.erase(it1);
cout<<"删除成功\n";
}
/*
删除部分
普通办法会越界
网上搜集资料
*/
else
{
it1++;
}
}
}
void Adm::addUser()
{
cout<<"您想增加的用户信息为,学号输入为0结束\n";
User uu;
while(cin>>uu)
{
if(uu.getId()==0)break;
u.push_back(uu);
cout<<"增加用户信息成功\n";
}
};
void Adm::addBook()
{
cout<<"您想增加的图书信息为:书名输入为E结束\n";
Book bb;
while(cin>>bb)
{
if(bb.getName()=="E")break;
b.push_back(bb);
cout<<"增加图书信息成功\n";
}
}
void Adm::load1()
{
int i;
Book bb;
ifstream infile("e:\\book.txt",ios::in);
if(!infile)
return;
b.clear();
b1.clear();
b2.clear();
i=0;
while(infile>>bb)
{
b.push_back(bb);
b1.insert(make_pair(bb.getNo(),i));
b2.insert(make_pair(bb.getName(),i));
i++;
}
infile.close();
}
void Adm::load2()
{
int i;
User uu;
ifstream infile("e:\\student.txt",ios::in);
if(!infile)
return;
u.clear();
u1.clear();
u2.clear();
i=0;
while(infile>>uu)
{
u.push_back(uu);
u1.insert(make_pair(uu.getId(),i));
u2.insert(make_pair(uu.getName(),i));
i++;
}
infile.close();
}
int main()
{
Operate o;
//o.addSome();
//o.queryHistory();
o.queryNow();
//Adm a;
//a.queryIdB();
//a.queryIdS();
//a.deletesU();
//a.addUser();
//a.addBook();
//a.deletesB();
}
//陆续更新#include
using namespace std;
class Time//时间类,包含年月日时
{
int year;
int month;
int day;
int hour;
public:
Time(int x,int y,int z,int v):year(x),month(y),day(z),hour(v){}
Time(){}
int getYear(){return year;};
int getMonth(){return month;};
int getDay(){return day;};
int getHour(){return hour;};
bool operator<(const Time&d)const
{
return year!=d.year?year
friend ostream&operator<<(ostream &os, const Time &d);
friend istream&operator>>(istream &in, Time &d);
};
ostream&operator<<(ostream &os,const Time &d)
{
os<
}
istream&operator>>(istream &in,Time &d)
{
in>>d.year;
while(1)
{
if(d.year>1000&&d.year<3000)
break;
else if(d.year==0)return in;
else
{
cout<<"请输入正确时间"<
}
}
in>>d.month;
while(1)
{
if(d.month>0&&d.month<13)
break;
else
{
cout<<"请输入正确时间"<
}
}
in>>d.day;
while(1)
{
if(d.day>0&&d.day<32)
break;
else
{
cout<<"请输入正确时间"<
}
}
in>>d.hour;
while(1)
{
if(d.hour>-1&&d.hour<25)
break;
else
{
cout<<"请输入正确时间"<
}
}
return in;
}
class Book//书籍类
{
string name;
string name1;
string press;
int no;
int number;//每类书的总数
int borrow;
int left;
public:
Book(string name1,int no1,string press1,int number1):name(name1),no(no1),press(press1),number(number1){}
Book(){number=0;borrow=0;}
string getName(){return name;};
string getPress(){return press;};
void setNumber(int n){number-=n;}
int getNo(){return no;};
int getNumber(){return number;};
int getLeft(){return left;};
friend ostream&operator<<(ostream&os,const Book&b);
friend istream&operator>>(istream&in,Book&b);
};
istream&operator>>(istream&in,Book&b)
{
in>>b.name>>b.no>>b.name1>>b.press>>b.number;
return in;
}
ostream&operator<<(ostream&os,const Book&b)
{
os<
}
class Record//一条记录对应一个人一本书,判断借出去的数目;
{
string name;
int id;
int code;
int major;
int classes;
int nowBorrows;
int breaks;
string type;
Time start;
Time end;
Book b;
bool either;
Time changeEnd;
public:
Record(Time t1,Time t2,Book B1);
Record(){changeEnd=end;}
Book getBook(){return b;};
Time getStart(){return start;};
Time getEnd(){return end;};
Time setChange(Time t){changeEnd=t;}
int getId(){return id;};
string getType(){return type;};
string getName(){return name;};
friend ostream&operator<<(ostream&os,const Record&r);
friend istream&operator>>(istream&in,Record&r);
};
istream&operator>>(istream&in,Record&r)
{
in>>r.id>>r.name>>r.major>>r.classes>>r.nowBorrows>>r.breaks;
in>>r.type;
in>>r.start;
if(r.start.getYear()==0)return in;
in>>r.end>>r.b;
r.changeEnd=r.end;
return in;
}
ostream&operator<<(ostream&os,const Record&r)
{
os<<"个人信息\n"<
}
Record::Record(Time t1,Time t2,Book b1)
{
start=t1;
end=t2;
b=b1;
changeEnd=end;
}
struct cmp1//?
{
int m;
cmp1(int mm){m=mm;}
bool operator()(Record &a)
{
return (a.getId()==m);
}
};
class User
{
string name;
string major;
string classes;
int id;
int code;
int borrows;
int nowBorrows;
bool breaks;
vector
multimap
multimap
multimap
multimap
vector
vector
multimap
multimap
multimap
multimap
multimap
multimap
public:
User()
{borrows=10;breaks=0;nowBorrows=0;}
void addOne();
void addSome();
int getNowBorrows(){return borrows;};
int getBreaks(){return breaks;};
int getId(){return id;}
string getName(){return name;}
void addBreaks(int m){breaks+=m;};
void addNowBorrows(int m){nowBorrows+=m;}
//void queryId(int ids);
void queryTime();
void queryNow();
void reBorrow();
//void load();
friend istream&operator>>(istream&in,User &u);
friend ostream&operator<<(ostream&os,User &u);
void show();
bool can(){return (nowBorrows<=borrows);}
};
/*void User::load()
{
int i;
Book bb;
ifstream infile("d:\\User.txt",ios::in);
if(!infile)
return;
b.clear();
b1.clear();
b2.clear();
i=0;
while(infile>>bb)
{
b.push_back(bb);
b1.insert(make_pair(bb.getNo(),i));
b2.insert(make_pair(bb.getName(),i));
i++;
}
infile.close();
}*/
void User::reBorrow()
{
bool e;
if(!can())
{
cout<<"您已达借阅上限\n";
}
else
{
cout<<"您想续借书的序号以及借到的时间\n";
int s;
cin>>s;
Time t;
cin>>t;
for(it=r.begin();it!=r.end();it++)
{
if(r[it-r.begin()].getBook().getNo()==s)
r[it-r.begin()].setChange(t);
}
}
}
void User::queryNow()
{
cout<<"输入当前时间\n";
Time t;
cin>>t;
for(it=r.begin();it!=r.end();it++)
{
if(r[it-r.begin()].getEnd()
}
void User::queryTime()
{
cout<<"您想查询的时间段是\n";
Time t1,t2;
cin>>t1>>t2;
multimap
l1=m3.lower_bound(t1);
l2=m3.upper_bound(t2);
for(l3=l1;l3!=l2;l3++)
{
cout<
}
/*void User::queryId(int ids)
{
it=find_if(r.begin(),r.end(),cmp1(ids));
while(it!=r.end())
{
cout<<"found:\t"<
}
}*/
void User::addSome()
{
if(!can())
{
cout<<"您已达借阅上限\n";
}
else
{
Record r1;
cout<<"输入年为0时停止输入"<
{
cin>>r1;
if(r1.getStart().getYear()==0)break;
addNowBorrows(1);
r.push_back(r1);
int i=r.size();
m1.insert(make_pair(r1.getId(),i-1));
m2.insert(make_pair(r1.getName(),i-1));
}
}
}
void User::addOne()
{
if(!can())
{
cout<<"您已达借阅上限\n";
}
else
{
Record r1;
cin>>r1;
addNowBorrows(1);
r.push_back(r1);
int i=r.size();
m1.insert(make_pair(r1.getId(),i-1));
m2.insert(make_pair(r1.getName(),i-1));
}
}
void User::show()
{
for(it=r.begin();it!=r.end();it++)
{
cout<<*it<
}
istream&operator>>(istream&in,User &u)
{
in>>u.id;
if(u.id==0)return in;
in>>u.code>>u.name>>u.major>>u.classes>>u.nowBorrows>>u.breaks;
return in;
}
ostream&operator<<(ostream&os,User&u)
{
os<<"学号"<<"\t"<<"姓名"<<"\t"<<"专业"<<"\t"<<"班级"<<"\t"<<"当前借阅数"<<"\t"<<"违规数"<
class Operate
{
vector
vector
multimap
multimap
multimap
multimap
vector
vector
multimap
multimap
multimap
multimap
User user;
public:
void addOne();
void addSome();//增加记录;
void queryNow();
void reBorrow();
void queryTime();
};
void Operate::addOne()
{
user.addOne();
}
void Operate::addSome()
{
user.addSome();
}
void Operate::queryNow()
{
user.queryNow();
}
void Operate::reBorrow()
{
user.reBorrow();
}
void Operate::queryTime()
{
user.queryTime();
}
class Adm
{
vector
vector
multimap
multimap
multimap
multimap
vector
vector
multimap
multimap
multimap
multimap
//对书集合和学生集合操作
public:
Adm()
{
load1();
load2();
}
~Adm()
{
load1p();
load2p();
}
void load1();//把文件中的数据读到vector里
void load2();
void load1p();//析构函数
void load2p();
void addUser();//增加一个用户
void deletes();//删除一个用户
void queryId();//查询
void change();//修改
};
void Adm::load1p()
{
ofstream outfile("e:\\book.txt",ios::out);
if(!outfile)
return;
for(it1=b.begin();it1!=b.end();it1++)
{
outfile<<*it1;
}
outfile.close();
}
void Adm::load2p()
{
ofstream outfile("e:\\student.txt",ios::out);
if(!outfile)
return;
for(it=u.begin();it!=u.end();it++)
{
outfile<<*it;
}
outfile.close();
}
void Adm::change()
{
cout<<"您想修改信息的学生的学号为\n";
User u1;
int id;
cin>>id;
for(it=u.begin();it!=u.end();it++)
{
if(u[it-u.begin()].getId()==id)
{
u.erase(it);
cout<<"请重输\n";
cin>>u1;
u.insert(it,u1);
cout<<"修改信息成功\n";
}
}
}
void Adm::deletes()
{
cout<<"你想删除的学生学号为\n";
int id;
User uu;
cin>>id;
for(it=u.begin();it!=u.end();it++)
{
if(u[it-u.begin()].getId()==id)
{
u.erase(it);
cout<<"删除成功\n";
}
}
}
void Adm::addUser()
{
cout<<"您想增加的用户信息为,学号输入为0结束\n";
User uu;
while(cin>>uu)
{
if(uu.getId()==0)break;
u.push_back(uu);
cout<<"增加用户信息成功\n";
}
};
void Adm::queryId()
{
cout<<"你想查询的学生学号为\n";
User uu;
int id;
cin>>id;
for(it=u.begin();it!=u.end();it++)
{
if(u[it-u.begin()].getId()==id)
{
cout<<*it<
}
}
uu.show();//输出记录;
}
void Adm::load1()
{
int i;
Book bb;
ifstream infile("e:\\book.txt",ios::in);
if(!infile)
return;
b.clear();
b1.clear();
b2.clear();
i=0;
while(infile>>bb)
{
b.push_back(bb);
b1.insert(make_pair(bb.getNo(),i));
b2.insert(make_pair(bb.getName(),i));
i++;
}
infile.close();
}
void Adm::load2()
{
int i;
User uu;
ifstream infile("e:\\student.txt",ios::in);
if(!infile)
return;
u.clear();
u1.clear();
u2.clear();
i=0;
while(infile>>uu)
{
u.push_back(uu);
u1.insert(make_pair(uu.getId(),i));
u2.insert(make_pair(uu.getName(),i));
i++;
}
infile.close();
}
int main()
{
/*Time t;
cin>>t;
cout<
cin>>b;
cout< Record r;
cin>>r;
cout<
cin>>u;
u.addSome();
cout< u.show();
freopen("book1.txt","r",stdin);
Book b;
cin>>b;
cout< */
Adm a;
a.queryId();
}
using namespace std;
class Time//时间类,包含年月日时
{
int year;
int month;
int day;
int hour;
public:
Time(int x,int y,int z,int v):year(x),month(y),day(z),hour(v){}
Time(){}
int getYear(){return year;};
int getMonth(){return month;};
int getDay(){return day;};
int getHour(){return hour;};
bool operator<(const Time&d)const
{
return year!=d.year?year
friend ostream&operator<<(ostream &os, const Time &d);
friend istream&operator>>(istream &in, Time &d);
};
ostream&operator<<(ostream &os,const Time &d)
{
os<
}
istream&operator>>(istream &in,Time &d)
{
in>>d.year;
while(1)
{
if(d.year>1000&&d.year<3000)
break;
else if(d.year==0)return in;
else
{
cout<<"请输入正确时间"<
}
}
in>>d.month;
while(1)
{
if(d.month>0&&d.month<13)
break;
else
{
cout<<"请输入正确时间"<
}
}
in>>d.day;
while(1)
{
if(d.day>0&&d.day<32)
break;
else
{
cout<<"请输入正确时间"<
}
}
in>>d.hour;
while(1)
{
if(d.hour>-1&&d.hour<25)
break;
else
{
cout<<"请输入正确时间"<
}
}
return in;
}
class Book//书籍类
{
string name;
string name1;
string press;
int no;
int number;//每类书的总数
int borrow;
int left;
public:
Book(string name1,int no1,string press1,int number1):name(name1),no(no1),press(press1),number(number1){}
Book(){number=0;borrow=0;}
string getName(){return name;};
string getPress(){return press;};
void setNumber(int n){number-=n;}
int getNo(){return no;};
int getNumber(){return number;};
int getLeft(){return left;};
friend ostream&operator<<(ostream&os,const Book&b);
friend istream&operator>>(istream&in,Book&b);
};
istream&operator>>(istream&in,Book&b)
{
in>>b.name>>b.no>>b.name1>>b.press>>b.number;
return in;
}
ostream&operator<<(ostream&os,const Book&b)
{
os<
}
class Record//一条记录对应一个人一本书,判断借出去的数目;
{
string name;
int id;
int code;
int major;
int classes;
int nowBorrows;
int breaks;
string type;
Time start;
Time end;
Book b;
bool either;
Time changeEnd;
public:
Record(Time t1,Time t2,Book B1);
Record(){changeEnd=end;}
Book getBook(){return b;};
Time getStart(){return start;};
Time getEnd(){return end;};
Time setChange(Time t){changeEnd=t;}
int getId(){return id;};
string getType(){return type;};
string getName(){return name;};
friend ostream&operator<<(ostream&os,const Record&r);
friend istream&operator>>(istream&in,Record&r);
};
istream&operator>>(istream&in,Record&r)
{
in>>r.id>>r.name>>r.major>>r.classes>>r.nowBorrows>>r.breaks;
in>>r.type;
in>>r.start;
if(r.start.getYear()==0)return in;
in>>r.end>>r.b;
r.changeEnd=r.end;
return in;
}
ostream&operator<<(ostream&os,const Record&r)
{
os<<"个人信息\n"<
}
Record::Record(Time t1,Time t2,Book b1)
{
start=t1;
end=t2;
b=b1;
changeEnd=end;
}
struct cmp1//?
{
int m;
cmp1(int mm){m=mm;}
bool operator()(Record &a)
{
return (a.getId()==m);
}
};
class User
{
string name;
string major;
string classes;
int id;
int code;
int borrows;
int nowBorrows;
bool breaks;
vector
multimap
multimap
multimap
multimap
vector
vector
multimap
multimap
multimap
multimap
multimap
multimap
public:
User()
{borrows=10;breaks=0;nowBorrows=0;}
void addOne();
void addSome();
int getNowBorrows(){return borrows;};
int getBreaks(){return breaks;};
int getId(){return id;}
string getName(){return name;}
void addBreaks(int m){breaks+=m;};
//void queryId(int ids);
void queryTime();
void queryNow();
void reborrow();
//void load();
friend istream&operator>>(istream&in,User &u);
friend ostream&operator<<(ostream&os,User &u);
void show();
};
/*void User::load()
{
int i;
Book bb;
ifstream infile("d:\\User.txt",ios::in);
if(!infile)
return;
b.clear();
b1.clear();
b2.clear();
i=0;
while(infile>>bb)
{
b.push_back(bb);
b1.insert(make_pair(bb.getNo(),i));
b2.insert(make_pair(bb.getName(),i));
i++;
}
infile.close();
}*/
void User::reborrow()
{
bool e;
cout<<"您想续借书的序号以及借到的时间\n";
int s;
cin>>s;
Time t;
cin>>t;
for(it=r.begin();it!=r.end();it++)
{
if(r[it-r.begin()].getBook().getNo()==s)
r[it-r.begin()].setChange(t);
}
}
void User::queryNow()
{
cout<<"输入当前时间\n";
Time t;
cin>>t;
for(it=r.begin();it!=r.end();it++)
{
if(r[it-r.begin()].getEnd()
}
void User::queryTime()
{
cout<<"您想查询的时间段是\n";
Time t1,t2;
cin>>t1>>t2;
multimap
l1=m3.lower_bound(t1);
l2=m3.upper_bound(t2);
for(l3=l1;l3!=l2;l3++)
{
cout<
}
/*void User::queryId(int ids)
{
it=find_if(r.begin(),r.end(),cmp1(ids));
while(it!=r.end())
{
cout<<"found:\t"<
}
}*/
void User::addSome()
{
Record r1;
cout<<"输入0停止输入"<
{
cin>>r1;
if(r1.getStart().getYear()==0)break;
r.push_back(r1);
int i=r.size();
m1.insert(make_pair(r1.getId(),i-1));
m2.insert(make_pair(r1.getName(),i-1));
}
}
void User::addOne()
{
Record r1;
cin>>r1;
r.push_back(r1);
int i=r.size();
m1.insert(make_pair(r1.getId(),i-1));
m2.insert(make_pair(r1.getName(),i-1));
}
void User::show()
{
for(it=r.begin();it!=r.end();it++)
{
cout<<*it<
}
istream&operator>>(istream&in,User &u)
{
in>>u.id>>u.code>>u.name>>u.major>>u.classes>>u.nowBorrows>>u.breaks;
return in;
}
ostream&operator<<(ostream&os,User &u)
{
os<<"学号"<<"\t"<<"姓名"<<"\t"<<"专业"<<"\t"<<"班级"<<"\t"<<"当前借阅数"<<"\t"<<"违规数"<
class Operate
{
};
class Adm
{
vector
vector
multimap
multimap
multimap
multimap
vector
vector
multimap
multimap
multimap
multimap
//对书集合和学生集合操作
public:
Adm()
{
load1();
load2();
}
~Adm()
{
load1p();
load2p();
}
void load1();//把文件中的数据读到vector里
void load2();
void load1p();//析构函数
void load2p();
void addUser();//增加一个用户
void deletes();//删除一个用户
void queryId();//查询
void change();//修改
};
void Adm::change()
{
cout<<"您想修改信息的学生的学号为\n";
User u1;
int id;
cin>>id;
for(it=u.begin();it!=u.end();it++)
{
if(u[it-u.begin()].getId()==id)
{
u.erase(it);
cout<<"请重输\n";
cin>>u1;
u.insert(it,u1);
cout<<"修改信息成功\n";
}
}
}
void Adm::deletes()
{
cout<<"你想删除的学生学号为\n";
int id;
User uu;
cin>>id;
for(it=u.begin();it!=u.end();it++)
{
if(u[it-u.begin()].getId()==id)
{
u.erase(it);
cout<<"删除成功\n";
}
}
}
void Adm::addUser()
{
cout<<"您想增加的用户信息为\n";
User uu;
cin>>uu;
u.push_back(uu);
cout<<"增加用户信息成功\n";
};
void Adm::queryId()
{
cout<<"你想查询的学生学号为\n";
User uu;
int id;
cin>>id;
for(it=u.begin();it!=u.end();it++)
{
if(u[it-u.begin()].getId()==id)
{
cout<<*it<
}
}
uu.show();//输出记录;
}
void Adm::load1()
{
int i;
Book bb;
ifstream infile("d:\\book.txt",ios::in);
if(!infile)
return;
b.clear();
b1.clear();
b2.clear();
i=0;
while(infile>>bb)
{
b.push_back(bb);
b1.insert(make_pair(bb.getNo(),i));
b2.insert(make_pair(bb.getName(),i));
i++;
}
infile.close();
}
void Adm::load2()
{
int i;
User uu;
ifstream infile("d:\\student.txt",ios::in);
if(!infile)
return;
u.clear();
u1.clear();
u2.clear();
i=0;
while(infile>>uu)
{
u.push_back(uu);
u1.insert(make_pair(uu.getId(),i));
u2.insert(make_pair(uu.getName(),i));
i++;
}
infile.close();
}
int main()
{
/*Time t;
cin>>t;
cout<
cin>>b;
cout< Record r;
cin>>r;
cout<
cin>>u;
u.addSome();
cout< u.show();
freopen("book1.txt","r",stdin);
Book b;
cin>>b;
cout< */
}
#include
using namespace std;
class Time//时间类,包含年月日时
{
int year;
int month;
int day;
int hour;
public:
Time(int x,int y,int z,int v):year(x),month(y),day(z),hour(v){}
Time(){}
int getYear(){return year;};
int getMonth(){return month;};
int getDay(){return day;};
int getHour(){return hour;};
bool operator<(const Time&d)const
{
return year!=d.year?year
friend ostream&operator<<(ostream &os, const Time &d);
friend istream&operator>>(istream &in, Time &d);
};
ostream&operator<<(ostream &os,const Time &d)
{
os<
}
istream&operator>>(istream &in,Time &d)
{
in>>d.year;
while(1)
{
if(d.year>1000&&d.year<3000)
break;
else if(d.year==0)return in;
else
{
cout<<"请输入正确时间"<
}
}
in>>d.month;
while(1)
{
if(d.month>0&&d.month<13)
break;
else
{
cout<<"请输入正确时间"<
}
}
in>>d.day;
while(1)
{
if(d.day>0&&d.day<32)
break;
else
{
cout<<"请输入正确时间"<
}
}
in>>d.hour;
while(1)
{
if(d.hour>-1&&d.hour<25)
break;
else
{
cout<<"请输入正确时间"<
}
}
return in;
}
class Book//书籍类
{
string name;
string name1;
string press;
int no;
int number;//每类书的总数
int borrow;
int left;
public:
Book(string name1,int no1,string press1,int number1):name(name1),no(no1),press(press1),number(number1){}
Book(){number=0;borrow=0;}
string getName(){return name;};
string getPress(){return press;};
void setNumber(int n){number-=n;}
int getNo(){return no;};
int getNumber(){return number;};
int getLeft(){return left;};
friend ostream&operator<<(ostream&os,const Book&b);
friend istream&operator>>(istream&in,Book&b);
};
istream&operator>>(istream&in,Book&b)
{
in>>b.name>>b.no>>b.name1>>b.press>>b.number;
return in;
}
ostream&operator<<(ostream&os,const Book&b)
{
os<
}
class Record//一条记录对应一个人一本书,判断借出去的数目;
{
string name;
int id;
int code;
int major;
int classes;
int nowBorrows;
int breaks;
string type;
Time start;
Time end;
Book b;
bool either;
Time changeEnd;
public:
Record(Time t1,Time t2,Book B1);
Record(){changeEnd=end;}
Book getBook(){return b;};
Time getStart(){return start;};
Time getEnd(){return end;};
Time setChange(Time t){changeEnd=t;}
int getId(){return id;};
string getType(){return type;};
string getName(){return name;};
friend ostream&operator<<(ostream&os,const Record&r);
friend istream&operator>>(istream&in,Record&r);
};
istream&operator>>(istream&in,Record&r)
{
in>>r.id>>r.name>>r.major>>r.classes>>r.nowBorrows>>r.breaks;
in>>r.type;
in>>r.start;
if(r.start.getYear()==0)return in;
in>>r.end>>r.b;
r.changeEnd=r.end;
return in;
}
ostream&operator<<(ostream&os,const Record&r)
{
os<<"个人信息\n"<
}
Record::Record(Time t1,Time t2,Book b1)
{
start=t1;
end=t2;
b=b1;
changeEnd=end;
}
struct cmp1//?
{
int m;
cmp1(int mm){m=mm;}
bool operator()(Record &a)
{
return (a.getId()==m);
}
};
class User
{
string name;
string major;
string classes;
int id;
int code;
int borrows;
int nowBorrows;
bool breaks;
vector
multimap
multimap
multimap
multimap
vector
vector
multimap
multimap
multimap
multimap
multimap
multimap
public:
User()
{borrows=10;breaks=0;nowBorrows=0;}
void addOne();
void addSome();
int getNowBorrows(){return borrows;};
int getBreaks(){return breaks;};
int getId(){return id;}
string getName(){return name;}
void addBreaks(int m){breaks+=m;};
//void queryId(int ids);
void queryTime();
void queryNow();
void reborrow();
//void load();
friend istream&operator>>(istream&in,User &u);
friend ostream&operator<<(ostream&os,User &u);
void show();
};
/*void User::load()
{
int i;
Book bb;
ifstream infile("d:\\User.txt",ios::in);
if(!infile)
return;
b.clear();
b1.clear();
b2.clear();
i=0;
while(infile>>bb)
{
b.push_back(bb);
b1.insert(make_pair(bb.getNo(),i));
b2.insert(make_pair(bb.getName(),i));
i++;
}
infile.close();
}*/
void User::reborrow()
{
bool e;
cout<<"您想续借书的序号以及借到的时间\n";
int s;
cin>>s;
Time t;
cin>>t;
for(it=r.begin();it!=r.end();it++)
{
if(r[it-r.begin()].getBook().getNo()==s)
r[it-r.begin()].setChange(t);
}
}
void User::queryNow()
{
cout<<"输入当前时间\n";
Time t;
cin>>t;
for(it=r.begin();it!=r.end();it++)
{
if(r[it-r.begin()].getEnd()
}
void User::queryTime()
{
cout<<"您想查询的时间段是\n";
Time t1,t2;
cin>>t1>>t2;
multimap
l1=m3.lower_bound(t1);
l2=m3.upper_bound(t2);
for(l3=l1;l3!=l2;l3++)
{
cout<
}
/*void User::queryId(int ids)
{
it=find_if(r.begin(),r.end(),cmp1(ids));
while(it!=r.end())
{
cout<<"found:\t"<
}
}*/
void User::addSome()
{
Record r1;
cout<<"输入0停止输入"<
{
cin>>r1;
if(r1.getStart().getYear()==0)break;
r.push_back(r1);
int i=r.size();
m1.insert(make_pair(r1.getId(),i-1));
m2.insert(make_pair(r1.getName(),i-1));
}
}
void User::addOne()
{
Record r1;
cin>>r1;
r.push_back(r1);
int i=r.size();
m1.insert(make_pair(r1.getId(),i-1));
m2.insert(make_pair(r1.getName(),i-1));
}
void User::show()
{
for(it=r.begin();it!=r.end();it++)
{
cout<<*it<
}
istream&operator>>(istream&in,User &u)
{
in>>u.id>>u.code>>u.name>>u.major>>u.classes>>u.nowBorrows>>u.breaks;
return in;
}
ostream&operator<<(ostream&os,User &u)
{
os<<"学号"<<"\t"<<"姓名"<<"\t"<<"专业"<<"\t"<<"班级"<<"\t"<<"当前借阅数"<<"\t"<<"违规数"<
class Operate
{
};
class Adm
{
vector
vector
multimap
multimap
multimap
multimap
vector
vector
multimap
multimap
multimap
multimap
//对书集合和学生集合操作
public:
Adm()
{
load1();
load2();
}
void load1();//把文件中的数据读到vector里
void load2();
void addUser();//增加一个用户
void deletes();//删除一个用户
void queryId();//查询
void change();//修改
};
void Adm::queryId()
{
cout<<"你想查询的学生学号为\n";
User uu;
int id;
cin>>id;
for(it=u.begin();it!=u.end();it++)
{
if(u[it-u.begin()].getId()==id)
{
cout<<*it<
}
}
uu.show();//输出记录;
}
void Adm::load1()
{
int i;
Book bb;
ifstream infile("d:\\book.txt",ios::in);
if(!infile)
return;
b.clear();
b1.clear();
b2.clear();
i=0;
while(infile>>bb)
{
b.push_back(bb);
b1.insert(make_pair(bb.getNo(),i));
b2.insert(make_pair(bb.getName(),i));
i++;
}
infile.close();
}
void Adm::load2()
{
int i;
User uu;
ifstream infile("d:\\student.txt",ios::in);
if(!infile)
return;
u.clear();
u1.clear();
u2.clear();
i=0;
while(infile>>uu)
{
u.push_back(uu);
u1.insert(make_pair(uu.getId(),i));
u2.insert(make_pair(uu.getName(),i));
i++;
}
infile.close();
}
int main()
{
/*Time t;
cin>>t;
cout<
cin>>b;
cout< Record r;
cin>>r;
cout<
cin>>u;
u.addSome();
cout< u.show();
freopen("book1.txt","r",stdin);
Book b;
cin>>b;
cout< */
}
#include
using namespace std;
class Time//时间类,包含年月日时
{
int year;
int month;
int day;
int hour;
public:
Time(int x,int y,int z,int v):year(x),month(y),day(z),hour(v){}
Time(){}
int getYear(){return year;};
int getMonth(){return month;};
int getDay(){return day;};
int getHour(){return hour;};
bool operator<(const Time&d)const
{
return year!=d.year?year
friend ostream&operator<<(ostream &os, const Time &d);
friend istream&operator>>(istream &in, Time &d);
};
ostream&operator<<(ostream &os,const Time &d)
{
os<
}
istream&operator>>(istream &in,Time &d)
{
in>>d.year;
while(1)
{
if(d.year>1000&&d.year<3000)
break;
else if(d.year==0)return in;
else
{
cout<<"请输入正确时间"<
}
}
in>>d.month;
while(1)
{
if(d.month>0&&d.month<13)
break;
else
{
cout<<"请输入正确时间"<
}
}
in>>d.day;
while(1)
{
if(d.day>0&&d.day<32)
break;
else
{
cout<<"请输入正确时间"<
}
}
in>>d.hour;
while(1)
{
if(d.hour>-1&&d.hour<25)
break;
else
{
cout<<"请输入正确时间"<
}
}
return in;
}
class Book//书籍类
{
string name;
string name1;
string press;
int no;
int number;//每类书的总数
int borrow;
int left;
public:
Book(string name1,int no1,string press1,int number1):name(name1),no(no1),press(press1),number(number1){}
Book(){number=0;borrow=0;}
string getName(){return name;};
string getPress(){return press;};
void setNumber(int n){number-=n;}
int getNo(){return no;};
int getNumber(){return number;};
int getLeft(){return left;};
friend ostream&operator<<(ostream&os,const Book&b);
friend istream&operator>>(istream&in,Book&b);
};
istream&operator>>(istream&in,Book&b)
{
in>>b.name>>b.no>>b.name1>>b.press>>b.number;
return in;
}
ostream&operator<<(ostream&os,const Book&b)
{
os<
}
class Record//一条记录对应一个人一本书,判断借出去的数目;
{
string name;
int id;
int code;
int major;
int classes;
int nowBorrows;
int breaks;
Time start;
Time end;
Book b;
bool either;
Time changeEnd;
public:
Record(Time t1,Time t2,Book B1);
Record(){changeEnd=end;}
Book getBook(){return b;};
Time getStart(){return start;};
Time getEnd(){return end;};
Time setChange(Time t){changeEnd=t;}
int getId(){return id;};
string getName(){return name;};
friend ostream&operator<<(ostream&os,const Record&r);
friend istream&operator>>(istream&in,Record&r);
};
istream&operator>>(istream&in,Record&r)
{
in>>r.id>>r.name>>r.major>>r.classes>>r.nowBorrows>>r.breaks;
in>>r.start;
if(r.start.getYear()==0)return in;
in>>r.end>>r.b;
r.changeEnd=r.end;
return in;
}
ostream&operator<<(ostream&os,const Record&r)
{
os<<"个人信息\n"<
}
Record::Record(Time t1,Time t2,Book b1)
{
start=t1;
end=t2;
b=b1;
changeEnd=end;
}
struct cmp1//?
{
int m;
cmp1(int mm){m=mm;}
bool operator()(Record &a)
{
return (a.getId()==m);
}
};
class User
{
string name;
string major;
string classes;
int id;
int code;
int borrows;
int nowBorrows;
bool breaks;
vector
multimap
multimap
multimap
multimap
vector
vector
multimap
multimap
multimap
multimap
multimap
multimap
public:
User()
{borrows=10;breaks=0;nowBorrows=0;}
void addOne();
void addSome();
int getNowBorrows(){return borrows;};
int getBreaks(){return breaks;};
int getId(){return id;}
string getName(){return name;}
void addBreaks(int m){breaks+=m;};
//void queryId(int ids);
void queryTime();
void queryNow();
void reborrow();
//void load();
friend istream&operator>>(istream&in,User &u);
friend ostream&operator<<(ostream&os,User &u);
void show();
};
/*void User::load()
{
int i;
Book bb;
ifstream infile("d:\\User.txt",ios::in);
if(!infile)
return;
b.clear();
b1.clear();
b2.clear();
i=0;
while(infile>>bb)
{
b.push_back(bb);
b1.insert(make_pair(bb.getNo(),i));
b2.insert(make_pair(bb.getName(),i));
i++;
}
infile.close();
}*/
void User::reborrow()
{
bool e;
cout<<"您想续借书的序号以及借到的时间\n";
int s;
cin>>s;
Time t;
cin>>t;
for(it=r.begin();it!=r.end();it++)
{
if(r[it-r.begin()].getBook().getNo()==s)
r[it-r.begin()].setChange(t);
}
}
void User::queryNow()
{
cout<<"输入当前时间\n";
Time t;
cin>>t;
for(it=r.begin();it!=r.end();it++)
{
if(r[it-r.begin()].getEnd()
}
void User::queryTime()
{
cout<<"您想查询的时间段是\n";
Time t1,t2;
cin>>t1>>t2;
multimap
l1=m3.lower_bound(t1);
l2=m3.upper_bound(t2);
for(l3=l1;l3!=l2;l3++)
{
cout<
}
/*void User::queryId(int ids)
{
it=find_if(r.begin(),r.end(),cmp1(ids));
while(it!=r.end())
{
cout<<"found:\t"<
}
}*/
void User::addSome()
{
Record r1;
cout<<"输入0停止输入"<
{
cin>>r1;
if(r1.getStart().getYear()==0)break;
r.push_back(r1);
int i=r.size();
m1.insert(make_pair(r1.getId(),i-1));
m2.insert(make_pair(r1.getName(),i-1));
}
}
void User::addOne()
{
Record r1;
cin>>r1;
r.push_back(r1);
int i=r.size();
m1.insert(make_pair(r1.getId(),i-1));
m2.insert(make_pair(r1.getName(),i-1));
}
void User::show()
{
for(it=r.begin();it!=r.end();it++)
{
cout<<*it<
}
istream&operator>>(istream&in,User &u)
{
in>>u.id>>u.code>>u.name>>u.major>>u.classes>>u.nowBorrows>>u.breaks;
return in;
}
ostream&operator<<(ostream&os,User &u)
{
os<<"学号"<<"\t"<<"姓名"<<"\t"<<"专业"<<"\t"<<"班级"<<"\t"<<"当前借阅数"<<"\t"<<"违规数"<
class Operate
{
};
class Adm
{
vector
multimap
multimap
multimap
multimap
vector
multimap
multimap
multimap
multimap
//对书集合和学生集合操作
public:
Adm()
{
load1();
load2();
}
void load1();//把文件中的数据读到vector里
void load2();
};
void Adm::load1()
{
int i;
Book bb;
ifstream infile("d:\\Adm.txt",ios::in);
if(!infile)
return;
b.clear();
b1.clear();
b2.clear();
i=0;
while(infile>>bb)
{
b.push_back(bb);
b1.insert(make_pair(bb.getNo(),i));
b2.insert(make_pair(bb.getName(),i));
i++;
}
infile.close();
}
void Adm::load2()
{
int i;
User uu;
ifstream infile("d:\\Adm.txt",ios::in);
if(!infile)
return;
u.clear();
u1.clear();
u2.clear();
i=0;
while(infile>>uu)
{
u.push_back(uu);
u1.insert(make_pair(uu.getId(),i));
u2.insert(make_pair(uu.getName(),i));
i++;
}
infile.close();
}
int main()
{
/*Time t;
cin>>t;
cout<
cin>>b;
cout< Record r;
cin>>r;
cout<
cin>>u;
u.addSome();
cout< u.show();
*/
freopen("book1.txt","r",stdin);
Book b;
cin>>b;
cout<
}
#include
using namespace std;
class Time//时间类,包含年月日时
{
int year;
int month;
int day;
int hour;
public:
Time(int x,int y,int z,int v):year(x),month(y),day(z),hour(v){}
Time(){}
int getYear(){return year;};
int getMonth(){return month;};
int getDay(){return day;};
int getHour(){return hour;};
bool operator<(const Time&d)const
{
return year!=d.year?year
friend ostream&operator<<(ostream &os, const Time &d);
friend istream&operator>>(istream &in, Time &d);
};
ostream&operator<<(ostream &os,const Time &d)
{
os<
}
istream&operator>>(istream &in,Time &d)
{
in>>d.year;
while(1)
{
if(d.year>1000&&d.year<3000)
break;
else
{
cout<<"请输入正确时间"<
}
}
in>>d.month;
while(1)
{
if(d.month>0&&d.month<13)
break;
else
{
cout<<"请输入正确时间"<
}
}
in>>d.day;
while(1)
{
if(d.day>0&&d.day<32)
break;
else
{
cout<<"请输入正确时间"<
}
}
in>>d.hour;
while(1)
{
if(d.hour>-1&&d.hour<25)
break;
else
{
cout<<"请输入正确时间"<
}
}
return in;
}
class Book//书籍类
{
string name;
string press;
int no;
int number;
int borrow;
int left;
public:
Book(string name1,int no1,string press1,int number1):name(name1),no(no1),press(press1),number(number1){}
Book(){number=0;borrow=0;}
string getName(){return name;};
string getPress(){return press;};
int getNo(){return no;};
int getNumber(){return number;};
int getLeft(){return left;};
friend ostream&operator<<(ostream&os,const Book&b);
friend istream&operator>>(istream&in,Book&b);
};
istream&operator>>(istream&in,Book&b)
{
in>>b.name>>b.no>>b.press>>b.number;
return in;
}
ostream&operator<<(ostream&os,const Book&b)
{
os<
}
class Record//一条记录对应一个人一本书
{
string name;
int id;
Time start;
Time end;
Book b;
bool either;
Time changeEnd;
public:
Record(Time t1,Time t2,Book B1,bool e);
Record(){}
Time getStart(){return start;};
Time getEnd(){return end;};
int getId(){return id;};
string getName(){return name;};
friend ostream&operator<<(ostream&os,const Record&r);
friend istream&operator>>(istream&in,Record&r);
};
istream&operator>>(istream&in,Record&r)
{
in>>r.start>>r.end>>r.b;
in>>r.either;
if(r.either==1)
{
cin>>r.changeEnd;
in>>r.changeEnd;
}
return in;
}
ostream&operator<<(ostream&os,const Record&r)
{
os<<"图书信息"<
}
Record::Record(Time t1,Time t2,Book b1,bool e)
{
start=t1;
end=t2;
b=b1;
either=e;
changeEnd=end;
}
class User
{
string name;
string major;
string classes;
int id;
int borrows;
int nowBorrows;
bool breaks;
vector
vector
multimap
multimap
multimap
multimap
public:
User(){borrows=10;breaks=0;nowBorrows=0;}
void addOne();
void addSome();
int getNowBorrows(){return borrows;};
int getBreaks(){return breaks;};
void addBreaks(int m){breaks+=m;};
friend istream&operator>>(istream&in,User &u);
friend ostream&operator<<(ostream&os,User &u);
void show();
};
void User::addOne()
{
Record r1;
cin>>r1;
r.push_back(r1);
int i=r.size();
m2.insert(make_pair(r1.getName(),i-1));
}
void User::show()
{
for(it=r.begin();it!=r.end();it++)
{
cout<<*it<
}
istream&operator>>(istream&in,User &u)
{
in>>u.id>>u.name>>u.major>>u.classes>>u.nowBorrows>>u.breaks;
return in;
}
ostream&operator<<(ostream&os,User &u)
{
os<<"学号"<<" "<<"姓名"<<"专业"<<" "<<"班级"<<" "<<"当前借阅数"<<" "<<"违规数"<
int main()
{
/*Time t;
cin>>t;
cout<
cin>>b;
cout< Record r;
cin>>r;
cout<
}