#include<bits/stdc++.h>
using namespace std;
class Time
{
int year;
int month;
int day;
int hour;
public:
Time(int y,int m,int d,int h):year(y),month(m),day(d),hour(h){}
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<d.year:month!=d.month?month<d.month:day!=d.day?day<d.day:hour<d.hour;
}
friend ostream&operator<<(ostream &os, const Time &d);
friend istream&operator>>(istream &in, Time &d);
};
ostream&operator<<(ostream &os,const Time &d)
{
os<<d.year<<" "<<d.month<<" "<<d.day<<" "<<d.hour;
return os;
}
istream&operator>>(istream &in,Time &d)
{
in>>d.year;
in>>d.month;
in>>d.day;
in>>d.hour;
return in;
}
class Record
{
string name;
int sh;
int id;
int major;
int classes;
int nowBorrows;
int breaks;
string type;
Time start;
Time end;
bool either;
Time changeEnd;
public:
Record(int s,int i,string t,Time s1,Time e):sh(s),id(i),type(t),start(s1),end(e){changeEnd=end;};
Record(){changeEnd=end;}
Time getStart(){return start;};
Time getEnd(){return changeEnd;};
Time setChange(Time t){changeEnd=t;}
int getsh(){return sh;};
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.sh;
if(r.sh==0)return in;
in>>r.id;
in>>r.type;
in>>r.start;
in>>r.end;
r.changeEnd=r.end;
return in;
}
ostream&operator<<(ostream&os,const Record&r)
{
os<<r.sh<<" "<<r.id<<" "<<r.type<<" "<<r.start<<" "<<r.changeEnd<<" "<<endl;
return os;
}
class Records
{
protected:
int num;
vector<Record>v1;
vector<Record>::iterator vit1;
multimap<int,int>m1;
multimap<int,int>::iterator mit1;
multimap<string,int>b2;
multimap<string,int>::iterator b2p;
public:
void setNum(int x){num=x;};
vector<Record>getRecord(){return v1;};
Records(){num=0;}
int getNum(){return num;};
void disAllRecord();
void addRecord(Record r){num++;v1.push_back(r);};
};
void Records::disAllRecord()
{
for(int i=0;i<v1.size();++i)
cout<<v1[i]<<endl;
}
class Book:public Records
{
string name;
string author;
int sh;
int number;//总数
int borrow;//已借数
int nowNumber;//目前可借数量
//vector<Record>r;
//int num;
public:
Book(string n,int h,string a,int nu):name(n),sh(h),author(a),number(nu){}
//Book(string n,int h,string a,int nu,int num1):name(n),sh(h),author(a),number(nu),num(num1){}
~Book(){v1.clear();}
Book(){borrow=0;num=0;}
string getName(){return name;};
Record getRecord(int i){return v1[i];};
void addBorrowsJ(int n){borrow+=n;};
void addBorrowsH(int n){borrow-=n;};
int getsh(){return sh;};
int getNum(){return num;};
void setNum(int i){num+=i;};
// void addRecord(Record rr){num++;v1.push_back(rr);};
int getNowNumber(){return (number-borrow);};//可借数量
int getNumber(){return number;};
int getBorrow(){return borrow;};
//int getLeft(){return left;};
//vector<Record>getRecord(){return r;};
friend ostream&operator<<(ostream&os,const Book&b);
friend istream&operator>>(istream&in,Book&b);
void de(){v1.clear();}
};
istream&operator>>(istream&in,Book&b)
{
in>>b.name;
if(b.name=="E")return in;
in>>b.sh>>b.author>>b.number>>b.num;
for(int i=0;i<b.num;++i)
{
Record rr;
in>>rr;
b.v1.push_back(rr);
}
return in;
}
ostream&operator<<(ostream&os,const Book&b)
{
os<<b.name<<" "<<b.sh<<" "<<b.author<<" "<<b.number<<" "<<b.num<<endl;
for(int i=0;i<b.num;++i)
{
os<<b.v1[i];
}
return os;
}
class Student:public Records
{
string name;
string major;
string classes;
int id;
//int num;
int borrows;//最大借阅数
int nowBorrows;//当前借阅数
int canReborrow;
bool breaks;
vector<Book>b;
multimap<int,int>b1;
multimap<int,int>::iterator b1p;
/*vector<Record>r;
vector<Record>::iterator it;
multimap<int,int>m1;
multimap<int,int>::iterator m1p;*/
public:
Student()
{borrows=10;breaks=0;nowBorrows=0;canReborrow=1;}
~Student(){b.clear();v1.clear();m1.clear();}
int getNowBorrows(){return nowBorrows;};
int getCanReborrow(){return canReborrow;};
int getBreaks(){return breaks;};
int getId(){return id;}
string getName(){return name;}
void addBreaks(int m){breaks+=m;};
void addNowBorrowsJ(int m){nowBorrows+=m;};
void addNowBorrowsH(int m){nowBorrows-=m;};
// void addRecord(Record r){num++;v1.push_back(r);};
void show();
void queryTime(Time t);
void changeTime(int sh,Time t);
void queryNow();
Time search1(int sh);
friend istream&operator>>(istream&in,Student &u);
friend ostream&operator<<(ostream&os,Student &u);
void operator=(Student u);
bool operator==(Student u);
//vector<Record>getRecord(){return r;};
vector<Book>getBook(){return b;};
void de1(){v1.clear();}
void de2(){b.clear();}
};
Time Student::search1(int sh)
{
for(vit1=v1.begin();vit1!=v1.end();vit1++)
{
if(vit1->getId()==sh)
return vit1->getEnd();
break;
}
}
bool Student::operator==(Student u)
{
return this->id==u.getId()?1:0;
}
void Student::operator=(Student u)
{
id=u.id;
name=u.name;
major=u.major;
classes=u.classes;
borrows=u.borrows;
breaks=u.breaks;
num=u.num;
v1=u.getRecord();
}
void Student::changeTime(int sh,Time t)
{
for(vit1=v1.begin();vit1!=v1.end();vit1++)
{
if(vit1->getsh()==sh)
{
v1[vit1-v1.begin()].setChange(t);
}
}
}
/*void Student::queryTime(Time t)
{
for(it=v1.begin();it!=v1.end();it++)
{
if(t<it->getEnd())
cout<<*it;
}
}
void Student::show()
{
for(it=v1.begin();it!=v1.end();it++)
{
cout<<*it;
}
}
void Student::queryNow()
{
cout<<"输入当前时间\n";
Time t;
cin>>t;
for(it=v1.begin();it!=v1.end();it++)
{
if(t<v1[it-v1.begin()].getEnd())
cout<<v1[it-v1.begin()];
}
}*/
istream&operator>>(istream&in,Student &u)
{
in>>u.id;
if(u.id==0)return in;
in>>u.name>>u.major>>u.classes>>u.borrows>>u.breaks>>u.num;
for(int i=0;i<u.num;++i)
{
Record rr;
in>>rr;
u.v1.push_back(rr);
}
return in;
}
ostream&operator<<(ostream&os,Student&u)
{
os<<u.id<<" "<<u.name<<" "<<u.major<<" "<<u.classes<<" "<<u.borrows<<" "<<u.breaks<<" "<<u.num<<endl;
for(int i=0;i<u.num;++i)
{
os<<u.v1[i];
}
}
class Client
{
vector<Book>b;
vector<Book>::iterator it1;
multimap<int,int>b1;
multimap<int,int>::iterator b1p;
multimap<string,int>b2;
multimap<string,int>::iterator b2p;
Student u;
public:
Client()
{
load1();
load2();
}
~Client()
{
load1p();
load2p();
u.getRecord().clear();
u.getBook().clear();
b.clear();
b1.clear();
}
void load1();
void load2();
void load1p();
void load2p();
int search1(string name);
int search2(int sh);//查书
void borrowBook();
void returnBook();
void queryNumber();//按书号查询当前是否可借
void queryNameBook();
void queryNow();//查询当前
void queryHistory();//查询历史
};
int Client::search2(int sh)
{
b1p=b1.find(sh);
if(b1p!=b1.end())
{
int i=b1p->second;
return i;
}
else return -1;
}
void Client::queryNumber()
{
cout<<"您想查询的书的序号为\n";
int sh;
cin>>sh;
if(b[search2(sh)].getNowNumber()>0)
cout<<"可以借阅\n"<<"剩余:"<<b[search2(sh)].getNowNumber()<<endl;
else
cout<<"不可借阅\n";
}
int Client::search1(string name)
{
b2p=b2.find(name);
if(b2p!=b2.end())
{
int i=b2p->second;
return i;
}
else return -1;
}
void Client::queryNameBook()
{
cout<<"你想查询的书名为\n";
string name;
cin>>name;
if(b[search1(name)].getNowNumber()>0)
{
cout<<"可以借阅\n"<<"该书书号为:"<<" "<<b[search1(name)].getsh()<<endl;
cout<<"剩余数目:"<<b[search1(name)].getNowNumber()<<endl;
}
else
cout<<"不可借阅\n";
}
void Client::borrowBook()
{
cout<<"请输入借书书号及目前时间与截止时间\n";
int sh;
Time t1,t2;
cin>>sh>>t1>>t2;
b1p=b1.find(sh);
if(u.getBreaks()>=3||u.getNowBorrows()>10||b[b1p->second].getNowNumber()<=0)
{
return;
}
Record r(sh,u.getId(),"jieshu",t1,t2);
u.addRecord(r);
b[b1p->second].addRecord(r);
u.addNowBorrowsJ(1);
b[b1p->second].addBorrowsJ(1);
cout<<"操作成功!\n";
}
void Client::returnBook()
{
cout<<"请输入还书书号及借书时间与目前时间\n";
int sh;
Time t1,t2;
cin>>sh>>t1>>t2;
b1p=b1.find(sh);
if(u.search1(sh)<t2)
{
u.addBreaks(1);
}
Record r(sh,u.getId(),"huanshu",t1,t2);
u.addRecord(r);
b[b1p->second].addRecord(r);
u.addNowBorrowsH(1);
b[b1p->second].addBorrowsH(1);
cout<<"还书成功!\n";
}
void Client::load1p()
{
ofstream outfileB("d:\\book.txt",ios::out);
if(!outfileB)
return;
for(it1=b.begin();it1!=b.end();it1++)
{
outfileB<<*it1;
}
outfileB.close();
}
void Client::load2p()
{
vector<Student>v1;
vector<Student>::iterator it;
Student u1;
ifstream infile("d:\\student.txt",ios::in);
if(!infile)
return ;
while(infile>>u1)
{
if(u1==this->u)
{
u1=this->u;
}
v1.push_back(u1);
u1.de1();
u1.de2();
}
infile.close();
ofstream outfile("d:\\student.txt",ios::out);
if(!outfile)
return;
for(it=v1.begin();it!=v1.end();it++)
outfile<<*it;
outfile.close();
}
void Client::load1()
{
int i;
Book bb;
ifstream infile("d:\\book.txt",ios::in);
if(!infile)
return;
b.clear();
b1.clear();
i=0;
while(infile>>bb)
{
b.push_back(bb);
b1.insert(make_pair(bb.getsh(),i));
b2.insert(make_pair(bb.getName(),i));
bb.de();
i++;
}
infile.close();
}
void Client::load2()
{
int id;
cin>>id;
Student uu;
int i;
ifstream infile("d:\\student.txt",ios::in);
if(!infile)
return;
while(infile>>uu)
{
if(uu.getId()==id)
{
u=uu;
break;
}
else
{
uu.de1();
uu.de2();
}
}
infile.close();
}
class Manage
{
vector<Book>b;
vector<Book>::iterator it1;
multimap<int,int>b1;
multimap<int,int>::iterator b1p;
multimap<string,int>b2;
multimap<string,int>::iterator b2p;
vector<Student>u;
vector<Student>::iterator it;
multimap<int,int>u1;
multimap<int,int>::iterator u1p;
public:
Manage()
{
load1();
load2();
}
~Manage()
{
load1p();
load2p();
}
void load1();
void load2();
void load1p();
void load2p();
void addStudent();
void addBook();
void deletesStudent();//删除一个用户
void deletesBook();
void queryIdStudent();//查询
void queryIdBook();
void queryNameBook();
};
void Manage::queryIdStudent()//STL
{
cout<<"你想查询的学生学号为\n";
int id;
cin>>id;
u1p=u1.find(id);
cout<<u[u1p->second];
}
void Manage::queryIdBook()
{
cout<<"你想查询的书号为\n";
int sh;
cin>>sh;
b1p=b1.find(sh);
cout<<b[b1p->second];
}
void Manage::queryNameBook()
{
cout<<"你想查询的书名为\n";
string name;
cin>>name;
b2p=b2.find(name);
cout<<b[b2p->second];
}
void Manage::deletesStudent()
{
cout<<"你想删除的学生学号为\n";
int id;
cin>>id;
u1p=u1.find(id);
it=u.begin()+u1p->second;
it=u.erase(it);
cout<<"删除成功\n";
}
void Manage::deletesBook()
{
cout<<"您想删除的书的编号是\n";
int sh;
cin>>sh;
b1p=b1.find(sh);
it1=b.begin()+b1p->second;
it1=b.erase(it1);
cout<<"删除成功\n";
}
void Manage::load1p()
{
ofstream outfileB("d:\\book.txt",ios::out);
if(!outfileB)
return;
for(it1=b.begin();it1!=b.end();it1++)
{
outfileB<<*it1;
}
outfileB.close();
}
void Manage::load2p()
{
ofstream outfileS("d:\\student.txt",ios::out);
if(!outfileS)
return;
for(it=u.begin();it!=u.end();it++)
{
outfileS<<*it;
}
outfileS.close();
}
void Manage::addStudent()
{
Student uu;
while(cin>>uu)
{
if(uu.getId()==0)break;
u.push_back(uu);
}
};
void Manage::addBook()
{
Book bb;
while(cin>>bb)
{
if(bb.getName()=="E") break;
b.push_back(bb);
}
}
void Manage::load1()
{
int i;
Book bb;
ifstream infile("d:\\book.txt",ios::in);
if(!infile)
return;
b.clear();
b1.clear();
i=0;
while(infile>>bb)
{
b.push_back(bb);
b1.insert(make_pair(bb.getsh(),i));
b2.insert(make_pair(bb.getName(),i));
i++;
}
infile.close();
}
void Manage::load2()
{
int i;
Student uu;
ifstream infile("d:\\student.txt",ios::in);
if(!infile)
return;
u.clear();
u1.clear();
i=0;
while(infile>>uu)
{
u.push_back(uu);
u1.insert(make_pair(uu.getId(),i));
i++;
}
infile.close();
}
class Account
{
int Id;
string passward;
bool type;
public:
Account(int a,string p,bool t):Id(a),passward(p),type(t){}
Account(){}
friend istream&operator>>(istream&in,Account&);
friend ostream&operator<<(ostream&out,Account&);
int getId(){return Id;}
string getPassward(){return passward;}
bool getType(){return type;}
void setAccount(int a,string p,bool t){Id=a,passward=p,type=t;}
};
istream&operator>>(istream&in,Account &A)
{
in>>A.Id;
if(A.Id==-1)return in;
in>>A.passward>>A.type;
return in;
}
ostream&operator<<(ostream&out,Account &A)
{
out<<A.Id<<" "<<A.passward<<" "<<A.type;
return out;
}
class People
{
vector<Account> A;
vector<Account>::iterator vi;
multimap<int,int>b3;
multimap<int,int>::iterator bit3,m,n;
public:
People()
{
load();
}
~People()
{
save();
}
void load();
void save();
void addAccount();
void deleteAccount();
void Register();
};
void People::load()
{
Account a;
int i=0;
ifstream infile("d:\\account.txt",ios::in);
if(!infile)
return;
A.clear();
b3.clear();
while(infile>>a)
{
A.push_back(a);
b3.insert(make_pair(a.getId(),i));
i++;
}
infile.close();
}
void People::save()
{
ofstream outfile("d:\\account.txt",ios::out);
if(!outfile)
return;
for(vi=A.begin(); vi!=A.end(); vi++)
{
outfile<<*vi;
//outfile<<endl;
}
outfile.close();
}
void People::addAccount()
{
cout<<"请输入要添加人的账户,密码,类型!"<<endl;
Account a;
int i;
while(cin>>a)
{
if(a.getId()==-1) break;
A.push_back(a);
}
cout<<"添加成功!";
}
void People::deleteAccount()
{
cout<<"请输入要添加人的账户,类型!"<<endl;
int Id;
while(1)
{
cin>>Id;
if(Id==-1) break;
if(b3.find(Id)!=b3.end())
{
vi=A.begin()+(bit3->second);
vi=A.erase(vi);
cout<<"删除成功!"<<endl;
}
else cout<<"无此用户!";
}
}
void People::Register()
{
int Id;
string p;
while(cin>>Id>>p)
{
if(b3.find(Id)!=b3.end())
{
m=b3.lower_bound(Id);n=b3.upper_bound(Id);
for(bit3=m; bit3!=n; bit3++)
{
if(A[bit3->second].getPassward()==p)
{
if(A[bit3->second].getType())
{
cout<<"欢迎用户登陆"<<endl;
Client c;
//c.queryNumber();
c.queryNameBook();
c.borrowBook();
//c.returnBook();
exit(0);
}
else
{
cout<<"欢迎管理员登陆"<<endl;
addAccount();
//deleAccount();
Manage m;
m.addBook();
// m.deletesBook();
m.addStudent();
exit(0);
}
}
else
cout<<"密码错误,请重新输入账号和密码"<<endl;
}
}
else
cout<<"账号错误,请重新输入账号和密码"<<endl;
}
}
int main()
{
/*Manage m;
m.addBook();
//m.deletesBook();
// m.addStudent();
Client c;
//c.queryNumber();
c.queryNameBook();
//c.borrowBook();
//c.search1(name);
//c.returnBook();
//Manage m;
//m.addBook();*/
People p;
p.Register();
return 0;
}
using namespace std;
class Time
{
int year;
int month;
int day;
int hour;
public:
Time(int y,int m,int d,int h):year(y),month(m),day(d),hour(h){}
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<d.year:month!=d.month?month<d.month:day!=d.day?day<d.day:hour<d.hour;
}
friend ostream&operator<<(ostream &os, const Time &d);
friend istream&operator>>(istream &in, Time &d);
};
ostream&operator<<(ostream &os,const Time &d)
{
os<<d.year<<" "<<d.month<<" "<<d.day<<" "<<d.hour;
return os;
}
istream&operator>>(istream &in,Time &d)
{
in>>d.year;
in>>d.month;
in>>d.day;
in>>d.hour;
return in;
}
class Record
{
string name;
int sh;
int id;
int major;
int classes;
int nowBorrows;
int breaks;
string type;
Time start;
Time end;
bool either;
Time changeEnd;
public:
Record(int s,int i,string t,Time s1,Time e):sh(s),id(i),type(t),start(s1),end(e){changeEnd=end;};
Record(){changeEnd=end;}
Time getStart(){return start;};
Time getEnd(){return changeEnd;};
Time setChange(Time t){changeEnd=t;}
int getsh(){return sh;};
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.sh;
if(r.sh==0)return in;
in>>r.id;
in>>r.type;
in>>r.start;
in>>r.end;
r.changeEnd=r.end;
return in;
}
ostream&operator<<(ostream&os,const Record&r)
{
os<<r.sh<<" "<<r.id<<" "<<r.type<<" "<<r.start<<" "<<r.changeEnd<<" "<<endl;
return os;
}
class Records
{
protected:
int num;
vector<Record>v1;
vector<Record>::iterator vit1;
multimap<int,int>m1;
multimap<int,int>::iterator mit1;
multimap<string,int>b2;
multimap<string,int>::iterator b2p;
public:
void setNum(int x){num=x;};
vector<Record>getRecord(){return v1;};
Records(){num=0;}
int getNum(){return num;};
void disAllRecord();
void addRecord(Record r){num++;v1.push_back(r);};
};
void Records::disAllRecord()
{
for(int i=0;i<v1.size();++i)
cout<<v1[i]<<endl;
}
class Book:public Records
{
string name;
string author;
int sh;
int number;//总数
int borrow;//已借数
int nowNumber;//目前可借数量
//vector<Record>r;
//int num;
public:
Book(string n,int h,string a,int nu):name(n),sh(h),author(a),number(nu){}
//Book(string n,int h,string a,int nu,int num1):name(n),sh(h),author(a),number(nu),num(num1){}
~Book(){v1.clear();}
Book(){borrow=0;num=0;}
string getName(){return name;};
Record getRecord(int i){return v1[i];};
void addBorrowsJ(int n){borrow+=n;};
void addBorrowsH(int n){borrow-=n;};
int getsh(){return sh;};
int getNum(){return num;};
void setNum(int i){num+=i;};
// void addRecord(Record rr){num++;v1.push_back(rr);};
int getNowNumber(){return (number-borrow);};//可借数量
int getNumber(){return number;};
int getBorrow(){return borrow;};
//int getLeft(){return left;};
//vector<Record>getRecord(){return r;};
friend ostream&operator<<(ostream&os,const Book&b);
friend istream&operator>>(istream&in,Book&b);
void de(){v1.clear();}
};
istream&operator>>(istream&in,Book&b)
{
in>>b.name;
if(b.name=="E")return in;
in>>b.sh>>b.author>>b.number>>b.num;
for(int i=0;i<b.num;++i)
{
Record rr;
in>>rr;
b.v1.push_back(rr);
}
return in;
}
ostream&operator<<(ostream&os,const Book&b)
{
os<<b.name<<" "<<b.sh<<" "<<b.author<<" "<<b.number<<" "<<b.num<<endl;
for(int i=0;i<b.num;++i)
{
os<<b.v1[i];
}
return os;
}
class Student:public Records
{
string name;
string major;
string classes;
int id;
//int num;
int borrows;//最大借阅数
int nowBorrows;//当前借阅数
int canReborrow;
bool breaks;
vector<Book>b;
multimap<int,int>b1;
multimap<int,int>::iterator b1p;
/*vector<Record>r;
vector<Record>::iterator it;
multimap<int,int>m1;
multimap<int,int>::iterator m1p;*/
public:
Student()
{borrows=10;breaks=0;nowBorrows=0;canReborrow=1;}
~Student(){b.clear();v1.clear();m1.clear();}
int getNowBorrows(){return nowBorrows;};
int getCanReborrow(){return canReborrow;};
int getBreaks(){return breaks;};
int getId(){return id;}
string getName(){return name;}
void addBreaks(int m){breaks+=m;};
void addNowBorrowsJ(int m){nowBorrows+=m;};
void addNowBorrowsH(int m){nowBorrows-=m;};
// void addRecord(Record r){num++;v1.push_back(r);};
void show();
void queryTime(Time t);
void changeTime(int sh,Time t);
void queryNow();
Time search1(int sh);
friend istream&operator>>(istream&in,Student &u);
friend ostream&operator<<(ostream&os,Student &u);
void operator=(Student u);
bool operator==(Student u);
//vector<Record>getRecord(){return r;};
vector<Book>getBook(){return b;};
void de1(){v1.clear();}
void de2(){b.clear();}
};
Time Student::search1(int sh)
{
for(vit1=v1.begin();vit1!=v1.end();vit1++)
{
if(vit1->getId()==sh)
return vit1->getEnd();
break;
}
}
bool Student::operator==(Student u)
{
return this->id==u.getId()?1:0;
}
void Student::operator=(Student u)
{
id=u.id;
name=u.name;
major=u.major;
classes=u.classes;
borrows=u.borrows;
breaks=u.breaks;
num=u.num;
v1=u.getRecord();
}
void Student::changeTime(int sh,Time t)
{
for(vit1=v1.begin();vit1!=v1.end();vit1++)
{
if(vit1->getsh()==sh)
{
v1[vit1-v1.begin()].setChange(t);
}
}
}
/*void Student::queryTime(Time t)
{
for(it=v1.begin();it!=v1.end();it++)
{
if(t<it->getEnd())
cout<<*it;
}
}
void Student::show()
{
for(it=v1.begin();it!=v1.end();it++)
{
cout<<*it;
}
}
void Student::queryNow()
{
cout<<"输入当前时间\n";
Time t;
cin>>t;
for(it=v1.begin();it!=v1.end();it++)
{
if(t<v1[it-v1.begin()].getEnd())
cout<<v1[it-v1.begin()];
}
}*/
istream&operator>>(istream&in,Student &u)
{
in>>u.id;
if(u.id==0)return in;
in>>u.name>>u.major>>u.classes>>u.borrows>>u.breaks>>u.num;
for(int i=0;i<u.num;++i)
{
Record rr;
in>>rr;
u.v1.push_back(rr);
}
return in;
}
ostream&operator<<(ostream&os,Student&u)
{
os<<u.id<<" "<<u.name<<" "<<u.major<<" "<<u.classes<<" "<<u.borrows<<" "<<u.breaks<<" "<<u.num<<endl;
for(int i=0;i<u.num;++i)
{
os<<u.v1[i];
}
}
class Client
{
vector<Book>b;
vector<Book>::iterator it1;
multimap<int,int>b1;
multimap<int,int>::iterator b1p;
multimap<string,int>b2;
multimap<string,int>::iterator b2p;
Student u;
public:
Client()
{
load1();
load2();
}
~Client()
{
load1p();
load2p();
u.getRecord().clear();
u.getBook().clear();
b.clear();
b1.clear();
}
void load1();
void load2();
void load1p();
void load2p();
int search1(string name);
int search2(int sh);//查书
void borrowBook();
void returnBook();
void queryNumber();//按书号查询当前是否可借
void queryNameBook();
void queryNow();//查询当前
void queryHistory();//查询历史
};
int Client::search2(int sh)
{
b1p=b1.find(sh);
if(b1p!=b1.end())
{
int i=b1p->second;
return i;
}
else return -1;
}
void Client::queryNumber()
{
cout<<"您想查询的书的序号为\n";
int sh;
cin>>sh;
if(b[search2(sh)].getNowNumber()>0)
cout<<"可以借阅\n"<<"剩余:"<<b[search2(sh)].getNowNumber()<<endl;
else
cout<<"不可借阅\n";
}
int Client::search1(string name)
{
b2p=b2.find(name);
if(b2p!=b2.end())
{
int i=b2p->second;
return i;
}
else return -1;
}
void Client::queryNameBook()
{
cout<<"你想查询的书名为\n";
string name;
cin>>name;
if(b[search1(name)].getNowNumber()>0)
{
cout<<"可以借阅\n"<<"该书书号为:"<<" "<<b[search1(name)].getsh()<<endl;
cout<<"剩余数目:"<<b[search1(name)].getNowNumber()<<endl;
}
else
cout<<"不可借阅\n";
}
void Client::borrowBook()
{
cout<<"请输入借书书号及目前时间与截止时间\n";
int sh;
Time t1,t2;
cin>>sh>>t1>>t2;
b1p=b1.find(sh);
if(u.getBreaks()>=3||u.getNowBorrows()>10||b[b1p->second].getNowNumber()<=0)
{
return;
}
Record r(sh,u.getId(),"jieshu",t1,t2);
u.addRecord(r);
b[b1p->second].addRecord(r);
u.addNowBorrowsJ(1);
b[b1p->second].addBorrowsJ(1);
cout<<"操作成功!\n";
}
void Client::returnBook()
{
cout<<"请输入还书书号及借书时间与目前时间\n";
int sh;
Time t1,t2;
cin>>sh>>t1>>t2;
b1p=b1.find(sh);
if(u.search1(sh)<t2)
{
u.addBreaks(1);
}
Record r(sh,u.getId(),"huanshu",t1,t2);
u.addRecord(r);
b[b1p->second].addRecord(r);
u.addNowBorrowsH(1);
b[b1p->second].addBorrowsH(1);
cout<<"还书成功!\n";
}
void Client::load1p()
{
ofstream outfileB("d:\\book.txt",ios::out);
if(!outfileB)
return;
for(it1=b.begin();it1!=b.end();it1++)
{
outfileB<<*it1;
}
outfileB.close();
}
void Client::load2p()
{
vector<Student>v1;
vector<Student>::iterator it;
Student u1;
ifstream infile("d:\\student.txt",ios::in);
if(!infile)
return ;
while(infile>>u1)
{
if(u1==this->u)
{
u1=this->u;
}
v1.push_back(u1);
u1.de1();
u1.de2();
}
infile.close();
ofstream outfile("d:\\student.txt",ios::out);
if(!outfile)
return;
for(it=v1.begin();it!=v1.end();it++)
outfile<<*it;
outfile.close();
}
void Client::load1()
{
int i;
Book bb;
ifstream infile("d:\\book.txt",ios::in);
if(!infile)
return;
b.clear();
b1.clear();
i=0;
while(infile>>bb)
{
b.push_back(bb);
b1.insert(make_pair(bb.getsh(),i));
b2.insert(make_pair(bb.getName(),i));
bb.de();
i++;
}
infile.close();
}
void Client::load2()
{
int id;
cin>>id;
Student uu;
int i;
ifstream infile("d:\\student.txt",ios::in);
if(!infile)
return;
while(infile>>uu)
{
if(uu.getId()==id)
{
u=uu;
break;
}
else
{
uu.de1();
uu.de2();
}
}
infile.close();
}
class Manage
{
vector<Book>b;
vector<Book>::iterator it1;
multimap<int,int>b1;
multimap<int,int>::iterator b1p;
multimap<string,int>b2;
multimap<string,int>::iterator b2p;
vector<Student>u;
vector<Student>::iterator it;
multimap<int,int>u1;
multimap<int,int>::iterator u1p;
public:
Manage()
{
load1();
load2();
}
~Manage()
{
load1p();
load2p();
}
void load1();
void load2();
void load1p();
void load2p();
void addStudent();
void addBook();
void deletesStudent();//删除一个用户
void deletesBook();
void queryIdStudent();//查询
void queryIdBook();
void queryNameBook();
};
void Manage::queryIdStudent()//STL
{
cout<<"你想查询的学生学号为\n";
int id;
cin>>id;
u1p=u1.find(id);
cout<<u[u1p->second];
}
void Manage::queryIdBook()
{
cout<<"你想查询的书号为\n";
int sh;
cin>>sh;
b1p=b1.find(sh);
cout<<b[b1p->second];
}
void Manage::queryNameBook()
{
cout<<"你想查询的书名为\n";
string name;
cin>>name;
b2p=b2.find(name);
cout<<b[b2p->second];
}
void Manage::deletesStudent()
{
cout<<"你想删除的学生学号为\n";
int id;
cin>>id;
u1p=u1.find(id);
it=u.begin()+u1p->second;
it=u.erase(it);
cout<<"删除成功\n";
}
void Manage::deletesBook()
{
cout<<"您想删除的书的编号是\n";
int sh;
cin>>sh;
b1p=b1.find(sh);
it1=b.begin()+b1p->second;
it1=b.erase(it1);
cout<<"删除成功\n";
}
void Manage::load1p()
{
ofstream outfileB("d:\\book.txt",ios::out);
if(!outfileB)
return;
for(it1=b.begin();it1!=b.end();it1++)
{
outfileB<<*it1;
}
outfileB.close();
}
void Manage::load2p()
{
ofstream outfileS("d:\\student.txt",ios::out);
if(!outfileS)
return;
for(it=u.begin();it!=u.end();it++)
{
outfileS<<*it;
}
outfileS.close();
}
void Manage::addStudent()
{
Student uu;
while(cin>>uu)
{
if(uu.getId()==0)break;
u.push_back(uu);
}
};
void Manage::addBook()
{
Book bb;
while(cin>>bb)
{
if(bb.getName()=="E") break;
b.push_back(bb);
}
}
void Manage::load1()
{
int i;
Book bb;
ifstream infile("d:\\book.txt",ios::in);
if(!infile)
return;
b.clear();
b1.clear();
i=0;
while(infile>>bb)
{
b.push_back(bb);
b1.insert(make_pair(bb.getsh(),i));
b2.insert(make_pair(bb.getName(),i));
i++;
}
infile.close();
}
void Manage::load2()
{
int i;
Student uu;
ifstream infile("d:\\student.txt",ios::in);
if(!infile)
return;
u.clear();
u1.clear();
i=0;
while(infile>>uu)
{
u.push_back(uu);
u1.insert(make_pair(uu.getId(),i));
i++;
}
infile.close();
}
class Account
{
int Id;
string passward;
bool type;
public:
Account(int a,string p,bool t):Id(a),passward(p),type(t){}
Account(){}
friend istream&operator>>(istream&in,Account&);
friend ostream&operator<<(ostream&out,Account&);
int getId(){return Id;}
string getPassward(){return passward;}
bool getType(){return type;}
void setAccount(int a,string p,bool t){Id=a,passward=p,type=t;}
};
istream&operator>>(istream&in,Account &A)
{
in>>A.Id;
if(A.Id==-1)return in;
in>>A.passward>>A.type;
return in;
}
ostream&operator<<(ostream&out,Account &A)
{
out<<A.Id<<" "<<A.passward<<" "<<A.type;
return out;
}
class People
{
vector<Account> A;
vector<Account>::iterator vi;
multimap<int,int>b3;
multimap<int,int>::iterator bit3,m,n;
public:
People()
{
load();
}
~People()
{
save();
}
void load();
void save();
void addAccount();
void deleteAccount();
void Register();
};
void People::load()
{
Account a;
int i=0;
ifstream infile("d:\\account.txt",ios::in);
if(!infile)
return;
A.clear();
b3.clear();
while(infile>>a)
{
A.push_back(a);
b3.insert(make_pair(a.getId(),i));
i++;
}
infile.close();
}
void People::save()
{
ofstream outfile("d:\\account.txt",ios::out);
if(!outfile)
return;
for(vi=A.begin(); vi!=A.end(); vi++)
{
outfile<<*vi;
//outfile<<endl;
}
outfile.close();
}
void People::addAccount()
{
cout<<"请输入要添加人的账户,密码,类型!"<<endl;
Account a;
int i;
while(cin>>a)
{
if(a.getId()==-1) break;
A.push_back(a);
}
cout<<"添加成功!";
}
void People::deleteAccount()
{
cout<<"请输入要添加人的账户,类型!"<<endl;
int Id;
while(1)
{
cin>>Id;
if(Id==-1) break;
if(b3.find(Id)!=b3.end())
{
vi=A.begin()+(bit3->second);
vi=A.erase(vi);
cout<<"删除成功!"<<endl;
}
else cout<<"无此用户!";
}
}
void People::Register()
{
int Id;
string p;
while(cin>>Id>>p)
{
if(b3.find(Id)!=b3.end())
{
m=b3.lower_bound(Id);n=b3.upper_bound(Id);
for(bit3=m; bit3!=n; bit3++)
{
if(A[bit3->second].getPassward()==p)
{
if(A[bit3->second].getType())
{
cout<<"欢迎用户登陆"<<endl;
Client c;
//c.queryNumber();
c.queryNameBook();
c.borrowBook();
//c.returnBook();
exit(0);
}
else
{
cout<<"欢迎管理员登陆"<<endl;
addAccount();
//deleAccount();
Manage m;
m.addBook();
// m.deletesBook();
m.addStudent();
exit(0);
}
}
else
cout<<"密码错误,请重新输入账号和密码"<<endl;
}
}
else
cout<<"账号错误,请重新输入账号和密码"<<endl;
}
}
int main()
{
/*Manage m;
m.addBook();
//m.deletesBook();
// m.addStudent();
Client c;
//c.queryNumber();
c.queryNameBook();
//c.borrowBook();
//c.search1(name);
//c.returnBook();
//Manage m;
//m.addBook();*/
People p;
p.Register();
return 0;
}