ATM機模擬實現STL
#include<bits/stdc++.h>
using namespace std;
class Times
{
private:
int month;
int day;
int hour;
int minute;//組織資料成員日月時分;
public:
Times(int mo,int d,int h,int m);//定義帶參建構函式...;
Times();//無參建構函式 ;
void show();
void setMonth(int m){month=m;};
void setDay(int d){day=d;};
void setHour(int h){hour=h;};
void setMinute(int m){minute=m;};
void setAll(int mo,int d,int h,int m){month=mo;day=d;hour=h;minute=m;};
void setAllin(){cin>>month>>day>>hour>>minute;};
int getMonth(){return month;}
int getDay(){return day;}
int getHour(){return hour;}
int getMinute(){return minute;};
friend istream&operator>>(istream&in,Times &t);
friend ostream&operator<<(ostream&out,Times&t);
bool operator<(const Times &t)const{
return month!=t.month?month<t.month:day!=t.day?day<t.day:hour<t.hour;}
};
istream&operator>>(istream&in,Times &t)
{
in>>t.month>>t.day>>t.hour>>t.minute;
return in;
}
ostream&operator<<(ostream&out,Times&t)
{
out<<t.month<<" "<<t.day<<" "<<t.hour<<" "<<t.minute;
return out;
}
Times::Times(int mo,int d,int h,int m)
{
month=mo;
day=d;
hour=h;
minute=m;
}
Times::Times()
{
month=0;
day=0;
hour=0;
minute=0;
}
void Times::show()
{
cout<<month<<" "<<day<<" "<<hour<<" "<<minute<<" ";
}
class Record
{
private:
int money;
double left;
string type;
int number;
Times date;
public:
Record(int number1,Times date1,string type1,int money1,double left1);
Record();
void show()
{cout<<number<<" ";date.show();cout<<type<<" "<<money<<" "<<left;};
void setNumber(int number1){number=number1;};
void setType(string type1){type=type1;};
void setMoney(int money1){money=money1;};
void setLeft(double left1){left=left1;};
void setAll(int number1,int a,int b,int c,int d,string type1,int money1,double left1){number=number1;date.setAll(a,b,c,d);type=type1;money=money1;left=left1;}
void setAllin(){cin>>number;date.setAllin();cin>>type>>money>>left;};
int getNumber(){return number;};
string getType(){return type;};
int getMoney(){return money;};
double getLeft(){return left;};
int getMonth(){date.getMonth();}
int getDay(){date.getDay();}
int getHour(){date.getHour();}
int getMinute(){date.getMinute();};
Times getTimes(){return date;};
friend istream&operator>>(istream&in,Record&t);
friend ostream&operator<<(ostream&out,Record&t);
};
istream&operator>>(istream&in,Record&t)
{
in>>t.number>>t.date>>t.type>>t.money>>t.left;
return in;
}
ostream&operator<<(ostream&out,Record&t)
{
out<<t.number<<" "<<t.date<<" "<<t.type<<" "<<t.money<<" "<<t.left;
return out;
}
Record::Record(int number1,Times date1,string type1,int money1,double left1)
{
number=number1;
date=date1;
type=type1;
money=money1;
left=left1;
}
Record::Record()
{
number=0;
type=" ";
money=0;
left=0;
}
class User
{
private:
int number;//?
double left;////有問題測試
string code;
string name;
vector<Record>r;
vector<Record>::iterator it;
multimap<string,int>m1;
multimap<string,int>::iterator m1p;
multimap<Times,int>m2;
multimap<Times,int>::iterator m2p;
int num;//交易次數
public:
User( int number1,string name1,string code1,double left1):number(number1),name(name1),code(code1),left(left1){num=0;}
//再加一個複製建構函式!
User(){num=0;};
User(User&u);
void show();
void setLeft(double left1){left=left1;};
void setCode(string code1){code=code1;};
void setNum(int num1){num=num1;};
double getLeft(){return left;};
string getCode(){return code;};
string getName(){return name;};
int getNumber(){return number;};
Record getRecord(int i){return r[i];};
int getNum(){return num;};
void addRecord(Record r1){r[num++]=r1;};
void addRecord1(Record r1);
void showRecord(int i){r[i].show();};
void showallRecord();
void queryTime(Times t1,Times t2);
void queryTime1(Times t1,Times t2);
void queryType1(string type);
void queryType(string type);
void showAll();
friend istream&operator>>(istream&in,User&u);
};
istream&operator>>(istream&in,User&u)
{
in>>u.number>>u.name>>u.code>>u.left;
return in;
}
void User::queryTime1(Times t1,Times t2)
{
multimap<Times,int>::iterator p1,p2,p3;
p1=m2.lower_bound(t1);
p2=m2.upper_bound(t2);
for(p3=p1;p3!=p2;p3++)
{
cout<<r[p3->second]<<endl;//第幾個;
}
}
void User::queryType1(string type)
{
multimap<string,int>::iterator p1,p2,p3;
p1=m1.lower_bound(type);
p2=m1.upper_bound(type);
for(p3=p1;p3!=p2;p3++)
{
cout<<r[p3->second]<<endl;//第幾個;
}
}
void User::addRecord1(Record r1)
{
int i;
r.push_back(r1);
num++;
i=r.size();
m1.insert(make_pair(r1.getType(),i-1));
m2.insert(make_pair(r1.getTimes(),i-1));
}
//複製建構函式
User::User(User&u)
{
number=u.getNumber();
left=u.getLeft();
code=u.getCode();
name=u.getName();
num=u.num;
for(int i=0;i<u.num;i++)
{
r.push_back(u.r[i]);
int j=r.size();
m1.insert(make_pair(u.r[i].getType(),j-1));
m2.insert(make_pair(u.r[i].getTimes(),j-1));
}
}
void User::show()
{
cout<<number<<" "<<name<<" "<<code<<" "<<left;
}
void User::showAll()
{ show();
cout<<endl;//if(num>0)
showallRecord();
}
void User::showallRecord()
{
for(int i=0;i<num;i++)
{
cout<<r[i]<<endl;
}
}
void User::queryTime(Times t1,Times t2)
{
for(int i=0;i<num;i++)
{
if(r[i].getMonth()==t1.getMonth()&&(r[i].getMonth()==t2.getMonth()))
{
if(r[i].getDay()>=t1.getDay()&&r[i].getDay()<=t2.getDay())
{
r[i].show();
cout<<endl;
}
}//月份內;
else if(r[i].getMonth()==t1.getMonth()&&r[i].getMonth()!=t2.getMonth())
{
if(r[i].getDay()>=t1.getDay())
{
r[i].show();
cout<<endl;
}
}
else if(r[i].getMonth()==t2.getMonth()&&r[i].getMonth()!=t1.getMonth())
{
if(r[i].getDay()<=t2.getDay())
{
r[i].show();
cout<<endl;
}
}
else if(r[i].getMonth()>t1.getMonth()&&(r[i].getMonth()<t2.getMonth()))
{
r[i].show();
cout<<endl;
}
}//t1為月份小的一個
}
void User::queryType(string type)
{
for(int i=0;i<num;i++)
{
if(r[i].getType()==type)
{r[i].show();
cout<<endl;}
}
}
class Atm
{private:
User u;
Times t;
public:
Atm(int number1,string name1,string code1,double left1,int a,int b,int c,int d):u(number1,name1,code1,left1),t(a,b,c,d){}
Atm(User u1,Times t1):u(u1),t(t1){}
void outMoney();
void inMoney();
void queryTime();
void queryType(string type);
void showRecord();
void showInformation();
void showAll(){u.show();cout<<endl;u.showallRecord();};
};
void Atm::showInformation()
{
u.showAll();
}
void Atm::showRecord()
{
u.showallRecord();
}
void Atm::queryType(string type)
{
u.queryType(type);
}
void Atm::queryTime()
{
int a,b,c,d;
cin>>a>>b>>c>>d;
Times t1(a,b,c,d);
cin>>a>>b>>c>>d;
Times t2(a,b,c,d);
u.queryTime(t1,t2);
}
void Atm::inMoney()
{
int money;
cin>>money;
u.setLeft(u.getLeft()+money);
Record r1(u.getNumber(),t,"cq",money,u.getLeft());
u.addRecord(r1);
}
void Atm::outMoney()
{
int money;
cin>>money;
if(money<=u.getLeft())
{
u.setLeft(u.getLeft()-money);
Record r1(u.getNumber(),t,"qq",money,u.getLeft());
u.addRecord(r1);
}
else
cout<<"所取錢數超過賬號餘額"<<endl;
}
int main()
{
/*Times t1;
cin>>t1;
cout<<t1;
cout<<endl;
Times t2;//無參函式定義不加括號;
cin>>t2;
cout<<t2;
return 0;
int num,m,l;
string t;
cin>>num>>t>>m>>l;
Times t1(4,23,8,5);
Record r1(num,t1,t,m,l);
cout<<r1<<endl;
Record r2;
cin>>r2;
cout<<r2;
return 0;
int number;
string code;
string name;
double left;
cin>>number>>name>>code>>left;*/
User u1;
cin>>u1;
u1.show();
cout<<endl;
u1.setCode("778899");
u1.show();
cout<<endl;
Times t1(4,22,8,10),t2(4,28,13,20);
Record r1(u1.getNumber(),t1,"qq",200,2000),r2(u1.getNumber(),t2,"cq",400,2400);
u1.addRecord1(r1);
u1.addRecord1(r2);
u1.showRecord(1);
cout<<endl;
Times t3(4,28,0,0),t4(4,29,0,0);
u1.queryTime1(t3,t4);
u1.showallRecord();
u1.showAll();
User u2(u1);
u2.queryType1("cq");
u2.showAll();
/*int n;
cin>>n;
string name;
cin>>name;
string code;
cin>>code;
int left;
cin>>left;
int a1,b1,c1,d1;
cin>>a1>>b1>>c1>>d1;
Atm as(n,name,code,left,a1,b1,c1,d1);
as.showInformation();//第一行輸出
as.inMoney();
as.outMoney();
as.queryType("cq");
as.showInformation();//空格
User u(2 ,"wyy","321",2000);
int a3,b2,c2,d2;
cin>>a3>>b2>>c2>>d2;
Times t(a3,b2,c2,d2);
Atm a2(u,t);
a2.outMoney();
a2.outMoney();
a2.queryType("qq");
a2.inMoney();
a2.showInformation();*/
}////////////////////////////////
LIBRARY
#include<bits/stdc++.h>
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<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;
/*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<<r.id<<" ";
os<<r.id1<<" ";
os<<r.type<<" ";
os<<r.start<<" ";
os<<r.changeEnd<<" "<<endl;
return 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<Record>r;
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<b.num;++i)
{
Record rr;
in>>rr;
b.r.push_back(rr);
}
return in;
}
ostream&operator<<(ostream&os,const Book&b)
{
os<<b.name<<" "<<b.no<<" "<<b.name1<<" "<<b.press<<" "<<b.number<<" "<<b.num<<endl;
for(int i=0;i<b.num;++i)
{
os<<b.r[i];
}
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<Book>b;
multimap<int,int>b1;
multimap<int,int>::iterator b1p;
multimap<string,int>b2;
multimap<string,int>::iterator b2p;
vector<Record>r;
vector<Record>::iterator it;
multimap<int,int>m1;
multimap<int,int>::iterator m1p;
multimap<string,int>m2;
multimap<int,int>::iterator m2p;
multimap<Time,int>m3;
multimap<Time,int>::iterator m3p;
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()<t)
cout<<*it;
}
}
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()<t)
cout<<r[it-r.begin()]<<endl;
}
}
/*void User::queryId(int ids)
{
it=find_if(r.begin(),r.end(),cmp1(ids));
while(it!=r.end())
{
cout<<"found:\t"<<r[it-r.begin()]<<endl;
it=find_if(it+1,r.end(),cmp1(ids));
}
}*/
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<u.num;++i)
{
Record rr;
in>>rr;
u.r.push_back(rr);
}
return in;
}
ostream&operator<<(ostream&os,User&u)
{
os<<u.id<<" "<<u.code<<" "<<u.name<<" "<<u.major<<" "<<u.classes<<" "<<u.nowBorrows<<" "<<u.breaks<<" "<<u.num<<endl;
for(int i=0;i<u.num;++i)
{
os<<u.r[i];
}
}
/*
操作類
1.查詢當前資訊
2.查詢記錄
2.借還書
3.續借
4.新增記錄
*/
class Operate
{
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<User>u;
vector<User>::iterator it;
multimap<int,int>u1;
multimap<int,int>::iterator u1p;
multimap<string,int>u2;
multimap<string,int>::iterator u2p;
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<<endl;
}
}
void Operate::reBorrow()
{
user.reBorrow();
}*/
/*
管理員類
1.增加學生圖書資訊
2.刪除學生圖書資訊
3.修改學生圖書資訊
4.查詢學生圖書資訊
*/
class Adm
{
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<User>u;
vector<User>::iterator it;
multimap<int,int>u1;
multimap<int,int>::iterator u1p;
multimap<string,int>u2;
multimap<string,int>::iterator u2p;
//對書集合和學生集合操作
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<bits/stdc++.h>
using namespace std;
class Times
{
private:
int month;
int day;
int hour;
int minute;//組織資料成員日月時分;
public:
Times(int mo,int d,int h,int m);//定義帶參建構函式...;
Times();//無參建構函式 ;
void show();
void setMonth(int m){month=m;};
void setDay(int d){day=d;};
void setHour(int h){hour=h;};
void setMinute(int m){minute=m;};
void setAll(int mo,int d,int h,int m){month=mo;day=d;hour=h;minute=m;};
void setAllin(){cin>>month>>day>>hour>>minute;};
int getMonth(){return month;}
int getDay(){return day;}
int getHour(){return hour;}
int getMinute(){return minute;};
};
Times::Times(int mo,int d,int h,int m)
{
month=mo;
day=d;
hour=h;
minute=m;
}
Times::Times()
{
month=0;
day=0;
hour=0;
minute=0;
}
void Times::show()
{
cout<<month<<" "<<day<<" "<<hour<<" "<<minute<<" ";
}
class Record
{
private:
int money;
double left;
string type;
int number;
Times date;
public:
Record(int number1,Times date1,string type1,int money1,double left1);
Record();
void show()
{cout<<number<<" ";date.show();cout<<type<<" "<<money<<" "<<left;};
void setNumber(int number1){number=number1;};
void setType(string type1){type=type1;};
void setMoney(int money1){money=money1;};
void setLeft(double left1){left=left1;};
void setAll(int number1,int a,int b,int c,int d,string type1,int money1,double left1){number=number1;date.setAll(a,b,c,d);type=type1;money=money1;left=left1;}
void setAllin(){cin>>number;date.setAllin();cin>>type>>money>>left;};
int getNumber(){return number;};
string getType(){return type;};
int getMoney(){return money;};
double getLeft(){return left;};
int getMonth(){date.getMonth();}
int getDay(){date.getDay();}
int getHour(){date.getHour();}
int getMinute(){date.getMinute();};
};
Record::Record(int number1,Times date1,string type1,int money1,double left1)
{
number=number1;
date=date1;
type=type1;
money=money1;
left=left1;
}
Record::Record()
{
number=0;
type=" ";
money=0;
left=0;
}
class User
{
private:
int number;//?
double left;////有問題測試
string code;
string name;
vector<Record>v;
vector<Record>iterator it;
multimap<string,int>m1;
multimap<string,int>m1p;
multimap<Data,int>m2;
multimap<Data,int>m2p;
int num;//交易次數
public:
User( int number1,string name1,string code1,double left1):number(number1),name(name1),code(code1),left(left1){num=0;}
//再加一個複製建構函式!
User(User&u);
void show();
void setLeft(double left1){left=left1;};
void setCode(string code1){code=code1;};
void setNum(int num1){num=num1;};
double getLeft(){return left;};
string getCode(){return code;};
string getName(){return name;};
int getNumber(){return number;};
Record getRecord(int i){return r[i];};
int getNum(){return num;};
void addRecord(Record r1);
void showRecord(int i){r[i].show();};
void showallRecord();
void queryTime(Times t1,Times t2);
void queryType(string type);
void showAll();
void showAlll(){ show();cout<<endl;showallRecord();};
};
void User::addRecord(Record r1)
{
v.push_back(r1);
int i=v.size();
m1.insert(make_pair(r1.getType,i-1));
m2.insert(make_pair(r2.getDataS,i-1));
}
//複製建構函式
User::User(User&u)
{
number=u.getNumber();
left=u.getLeft();
code=u.getCode();
name=u.getName();
num=u.getNum();
for(it=u.v.begin();it!=u.v.end();it++)
{
v.push_back(it);
m1p.
}
}
void User::show()
{
cout<<number<<" "<<name<<" "<<code<<" "<<left;
}
void User::showAll()
{ show();
if(num>0)cout<<endl;
showallRecord();
}
void User::showallRecord()
{
for(int i=0;i<num;i++)
{
showRecord(i);
cout<<endl;
}
}
void User::queryTime(Times t1,Times t2)
{
for(int i=0;i<num;i++)
{
if(r[i].getMonth()==t1.getMonth()&&(r[i].getMonth()==t2.getMonth()))
{
if(r[i].getDay()>=t1.getDay()&&r[i].getDay()<=t2.getDay())
{
r[i].show();
cout<<endl;
}
}//月份內;
else if(r[i].getMonth()==t1.getMonth()&&r[i].getMonth()!=t2.getMonth())
{
if(r[i].getDay()>=t1.getDay())
{
r[i].show();
cout<<endl;
}
}
else if(r[i].getMonth()==t2.getMonth()&&r[i].getMonth()!=t1.getMonth())
{
if(r[i].getDay()<=t2.getDay())
{
r[i].show();
cout<<endl;
}
}
else if(r[i].getMonth()>t1.getMonth()&&(r[i].getMonth()<t2.getMonth()))
{
r[i].show();
cout<<endl;
}
}//t1為月份小的一個
}
void User::queryType(string type)
{
for(int i=0;i<num;i++)
{
if(r[i].getType()==type)
{r[i].show();
cout<<endl;}
}
}
class Atm
{private:
User u;
Times t;
public:
Atm(int number1,string name1,string code1,double left1,int a,int b,int c,int d):u(number1,name1,code1,left1),t(a,b,c,d){}
Atm(User u1,Times t1):u(u1),t(t1){}
void outMoney();
void inMoney();
void queryTime();
void queryType(string type);
void showRecord();
void showInformation();
void showAll(){u.show();cout<<endl;u.showallRecord();};
};
void Atm::showInformation()
{
u.showAll();
}
void Atm::showRecord()
{
u.showallRecord();
}
void Atm::queryType(string type)
{
u.queryType(type);
}
void Atm::queryTime()
{
int a,b,c,d;
cin>>a>>b>>c>>d;
Times t1(a,b,c,d);
cin>>a>>b>>c>>d;
Times t2(a,b,c,d);
u.queryTime(t1,t2);
}
void Atm::inMoney()
{
int money;
cin>>money;
u.setLeft(u.getLeft()+money);
Record r1(u.getNumber(),t,"cq",money,u.getLeft());
u.addRecord(r1);
}
void Atm::outMoney()
{
int money;
cin>>money;
if(money<=u.getLeft())
{
u.setLeft(u.getLeft()-money);
Record r1(u.getNumber(),t,"qq",money,u.getLeft());
u.addRecord(r1);
}
else
cout<<"所取錢數超過賬號餘額"<<endl;
}
int main()
{
/*int a,b,c,d;
cin>>a>>b>>c>>d;
Times t1(a,b,c,d);
t1.show();
cout<<endl;
Times t2;//無參函式定義不加括號;
t2.setAllin();
t2.show();
return 0;*/
Times t1(4,23,8,5);
int n,m,l;
string t;
cin>>n>>t>>m>>l;
Record r1(n,t1,t,m,l);
r1.show();
cout<<endl;
Record r2;
r2.setAllin();
r2.show();
return 0;
/* int number;
string code;
string name;
double left;
cin>>number>>name>>code>>left;
User u1(number,name,code,left);
u1.show();
cout<<endl;
u1.setCode("778899");
u1.show();
cout<<endl;
Times t1(4,22,8,10),t2(4,28,13,20);
Record r1(number,t1,"qq",200,2000),r2(number,t2,"cq",400,2400);
u1.addRecord(r1);
u1.addRecord(r2);
u1.showRecord(1);
cout<<endl;
Times t3(4,28,0,0),t4(4,29,0,0);
u1.queryTime(t3,t4);
u1.showallRecord();
u1.showAll();
User u2(u1);
u2.queryType("cq");
u2.showAll();
/*int n;
cin>>n;
string name;
cin>>name;
string code;
cin>>code;
int left;
cin>>left;
int a1,b1,c1,d1;
cin>>a1>>b1>>c1>>d1;
Atm as(n,name,code,left,a1,b1,c1,d1);
as.showInformation();//第一行輸出
as.inMoney();
as.outMoney();
as.queryType("cq");
as.showInformation();//空格
User u(2 ,"wyy","321",2000);
int a3,b2,c2,d2;
cin>>a3>>b2>>c2>>d2;
Times t(a3,b2,c2,d2);
Atm a2(u,t);
a2.outMoney();
a2.outMoney();
a2.queryType("qq");
a2.inMoney();
a2.showInformation();*/
}
#include<bits/stdc++.h>
using namespace std;
class Times
{
private:
int month;
int day;
int hour;
int minute;//組織資料成員日月時分;
public:
Times(int mo,int d,int h,int m);//定義帶參建構函式...;
Times();//無參建構函式 ;
void show();
void setMonth(int m){month=m;};
void setDay(int d){day=d;};
void setHour(int h){hour=h;};
void setMinute(int m){minute=m;};
void setAll(int mo,int d,int h,int m){month=mo;day=d;hour=h;minute=m;};
void setAllin(){cin>>month>>day>>hour>>minute;};
int getMonth(){return month;}
int getDay(){return day;}
int getHour(){return hour;}
int getMinute(){return minute;};
};
Times::Times(int mo,int d,int h,int m)
{
month=mo;
day=d;
hour=h;
minute=m;
}
Times::Times()
{
month=0;
day=0;
hour=0;
minute=0;
}
void Times::show()
{
cout<<month<<" "<<day<<" "<<hour<<" "<<minute<<" ";
}
class Record
{
private:
int money;
double left;
string type;
int number;
Times date;
public:
Record(int number1,Times date1,string type1,int money1,double left1);
Record();
void show()
{cout<<number<<" ";date.show();cout<<type<<" "<<money<<" "<<left<<endl;};
void setNumber(int number1){number=number1;};
void setType(string type1){type=type1;};
void setMoney(int money1){money=money1;};
void setLeft(double left1){left=left1;};
void setAll(int number1,int a,int b,int c,int d,string type1,int money1,double left1){number=number1;date.setAll(a,b,c,d);type=type1;money=money1;left=left1;}
void setAllin(){cin>>number;date.setAllin();cin>>type>>money>>left;};
int getNumber(){return number;};
string getType(){return type;};
int getMoney(){return money;};
double getLeft(){return left;};
int getMonth(){date.getMonth();}
int getDay(){date.getDay();}
int getHour(){date.getHour();}
int getMinute(){date.getMinute();};
};
Record::Record(int number1,Times date1,string type1,int money1,double left1)
{
number=number1;
date=date1;
type=type1;
money=money1;
left=left1;
}
Record::Record()
{
number=0;
type=" ";
money=0;
left=0;
}
class User
{
private:
int number;//?
double left;////有問題測試
string code;
string name;
Record r[100];
static int num;//交易次數
public:
User( int number1,string name1,string code1,double left1):number(number1),name(name1),code(code1),left(left1){}
//再加一個複製建構函式!
User(User&u);
void show();
void setLeft(double left1){left=left1;};
void setCode(string code1){code=code1;};
void setNum(int num1){num=num1;};
double getLeft(){return left;};
string getCode(){return code;};
string getName(){return name;};
int getNumber(){return number;};
Record getRecord(int i){return r[i];};
int getNum(){return num;};
void addRecord(Record r1){r[num++]=r1;};
void showRecord(int i){r[i].show();};
void showallRecord();
void queryTime(Times t1,Times t2);
void queryType(string type);
void showAll();
void showAlll(){ show();cout<<endl;showallRecord();};
};
//複製建構函式
User::User(User&u)
{
number=u.getNumber();
left=u.getLeft();
code=u.getCode();
name=u.getName();
num=u.getNum();
for(int i=0;i<num;i++)
{
r[i]=u.getRecord(i);
}
}
int User::num=0;
void User::show()
{
cout<<number<<" "<<name<<" "<<code<<" "<<left;
}
void User::showAll()
{ show();
showallRecord();
}
void User::showallRecord()
{
for(int i=0;i<num;i++)
{
showRecord(i);
}
}
void User::queryTime(Times t1,Times t2)
{
for(int i=0;i<num;i++)
{
if(r[i].getMonth()==t1.getMonth()&&(r[i].getMonth()==t2.getMonth()))
{
if(r[i].getDay()>=t1.getDay()&&r[i].getDay()<=t2.getDay())
r[i].show();
}//月份內;
else if(r[i].getMonth()==t1.getMonth()&&r[i].getMonth()!=t2.getMonth())
{
if(r[i].getDay()>=t1.getDay())
r[i].show();
}
else if(r[i].getMonth()==t2.getMonth()&&r[i].getMonth()!=t1.getMonth())
{
if(r[i].getDay()<=t2.getDay())
r[i].show();
}
else if(r[i].getMonth()>t1.getMonth()&&(r[i].getMonth()<t2.getMonth()))
{
r[i].show();
}
}//t1為月份小的一個
}
void User::queryType(string type)
{
for(int i=0;i<num;i++)
{
if(r[i].getType()==type)
r[i].show();
}
}
class Atm
{private:
User u;
Times t;
public:
Atm(int number1,string name1,string code1,double left1,int a,int b,int c,int d):u(number1,name1,code1,left1),t(a,b,c,d){}
Atm(User u1,Times t1):u(u1),t(t1){}
void outMoney();
void inMoney();
void queryTime();
void queryType(string type);
void showRecord();
void showInformation();
void showAll(){u.show();cout<<endl;u.showallRecord();};
};
void Atm::showInformation()
{
u.showAll();
}
void Atm::showRecord()
{
u.showallRecord();
}
void Atm::queryType(string type)
{
u.queryType(type);
}
void Atm::queryTime()
{
int a,b,c,d;
cin>>a>>b>>c>>d;
Times t1(a,b,c,d);
cin>>a>>b>>c>>d;
Times t2(a,b,c,d);
u.queryTime(t1,t2);
}
void Atm::inMoney()
{
int money;
cin>>money;
u.setLeft(u.getLeft()+money);
Record r1(u.getNumber(),t,"cq",money,u.getLeft());
u.addRecord(r1);
}
void Atm::outMoney()
{
int money;
cin>>money;
if(money<=u.getLeft())
{
u.setLeft(u.getLeft()-money);
Record r1(u.getNumber(),t,"qq",money,u.getLeft());
u.addRecord(r1);
}
else
cout<<"所取錢數超過賬號餘額"<<endl;
}
int main()
{
/*int a,b,c,d;
cin>>a>>b>>c>>d;
Times t1(a,b,c,d);
t1.show();
cout<<endl;
Times t2;//無參函式定義不加括號;
t2.setAllin();
t2.show();
return 0;*/
/*Times t1(4,23,8,5);
int n,m,l;
string t;
cin>>n>>t>>m>>l;
Record r1(n,t1,t,m,l);
r1.show();
Record r2;
r2.setAllin();
r2.show();
return 0;*/
/*int number;
string code;
string name;
double left;
cin>>number>>name>>code>>left;
User u1(number,name,code,left);
u1.show();
cout<<endl;
u1.setCode("778899");
u1.show();
cout<<endl;
Times t1(4,22,8,10),t2(4,28,13,20);
Record r1(number,t1,"qq",200,2000),r2(number,t2,"cq",400,2400);
u1.addRecord(r1);
u1.addRecord(r2);
u1.showRecord(1);
Times t3(4,28,0,0),t4(4,29,0,0);
u1.queryTime(t3,t4);
u1.showallRecord();
u1.showAlll();
User u2(u1);
u2.queryType("cq");
u2.showAlll();*/
int n;
cin>>n;
string name;
cin>>name;
string code;
cin>>code;
int left;
cin>>left;
int a1,b1,c1,d1;
cin>>a1>>b1>>c1>>d1;
Atm as(n,name,code,left,a1,b1,c1,d1);
as.showInformation();//第一行輸出
as.inMoney();
as.outMoney();
as.queryType("cq");
as.showAll();//空格
User u(2 ,"wyy","321",2000);
int a3,b2,c2,d2;
cin>>a3>>b2>>c2>>d2;
Times t(a3,b2,c2,d2);
Atm a2(u,t);
u.setNum(0);
a2.outMoney();
a2.outMoney();
a2.queryType("qq");
a2.inMoney();
a2.showAll();
}
#include<bits/stdc++.h>
using namespace std;
class Times
{
private:
int month;
int day;
int hour;
int minute;//組織資料成員日月時分;
public:
Times(int mo,int d,int h,int m);//定義帶參建構函式...;
Times();//無參建構函式 ;
void show();
void setMonth(int m){month=m;};
void setDay(int d){day=d;};
void setHour(int h){hour=h;};
void setMinute(int m){minute=m;};
void setAll(int mo,int d,int h,int m){month=mo;day=d;hour=h;minute=m;};
void setAllin(){cin>>month>>day>>hour>>minute;};
int getMonth(){return month;}
int getDay(){return day;}
int getHour(){return hour;}
int getMinute(){return minute;};
};
Times::Times(int mo,int d,int h,int m)
{
month=mo;
day=d;
hour=h;
minute=m;
}
Times::Times()
{
month=0;
day=0;
hour=0;
minute=0;
}
void Times::show()
{
cout<<month<<" "<<day<<" "<<hour<<" "<<minute<<" ";
}
class Record
{
private:
int money;
double left;
string type;
int number;
Times date;
public:
Record(int number1,Times date1,string type1,int money1,double left1);
Record();
void show()
{cout<<number<<" ";date.show();cout<<type<<" "<<money<<" "<<left;};
void setNumber(int number1){number=number1;};
void setType(string type1){type=type1;};
void setMoney(int money1){money=money1;};
void setLeft(double left1){left=left1;};
void setAll(int number1,int a,int b,int c,int d,string type1,int money1,double left1){number=number1;date.setAll(a,b,c,d);type=type1;money=money1;left=left1;}
void setAllin(){cin>>number;date.setAllin();cin>>type>>money>>left;};
int getNumber(){return number;};
string getType(){return type;};
int getMoney(){return money;};
double getLeft(){return left;};
int getMonth(){date.getMonth();}
int getDay(){date.getDay();}
int getHour(){date.getHour();}
int getMinute(){date.getMinute();};
};
Record::Record(int number1,Times date1,string type1,int money1,double left1)
{
number=number1;
date=date1;
type=type1;
money=money1;
left=left1;
}
Record::Record()
{
number=0;
type=" ";
money=0;
left=0;
}
class User
{
private:
int number;//?
double left;////有問題測試
string code;
string name;
Record r[100];
int num;//交易次數
public:
User( int number1,string name1,string code1,double left1):number(number1),name(name1),code(code1),left(left1){num=0;}
//再加一個複製建構函式!
User(User&u);
void show();
void setLeft(double left1){left=left1;};
void setCode(string code1){code=code1;};
void setNum(int num1){num=num1;};
double getLeft(){return left;};
string getCode(){return code;};
string getName(){return name;};
int getNumber(){return number;};
Record getRecord(int i){return r[i];};
int getNum(){return num;};
void addRecord(Record r1){r[num++]=r1;};
void showRecord(int i){r[i].show();};
void showallRecord();
void queryTime(Times t1,Times t2);
void queryType(string type);
void showAll();
void showAlll(){ show();cout<<endl;showallRecord();};
};
//複製建構函式