using namespace std;
class Time
{
int hour;
int minute;
public:
Time(int v,int m ):hour(v),minute(m) {}
Time()
{
hour=0;
minute=0;
}
int getHour()
{
return hour;
};
int getMinute()
{
return minute;
};
bool operator<(const Time&d)const
{
return hour!=d.hour?hour<d.hour:minute<d.minute;
}
friend ostream&operator<<(ostream &os, const Time &d);
friend istream&operator>>(istream &in, Time &d);
};
ostream&operator<<(ostream &os,const Time &d)
{
os<<d.hour<<" "<<d.minute;
return os;
}
istream&operator>>(istream &in,Time &d)
{
in>>d.hour;
in>>d.minute;
return in;
}
class Train_information
{
string Train_number;
string Station;
Time from;
Time to;
public:
Train_information(string Train_number,string Station,Time from,Time to)
{
this->Train_number=Train_number;
this->Station=Station;
this->from=from;
this->to=to;
}
Train_information()
{
}
friend ostream&operator<<(ostream &os,Train_information &T);
friend istream&operator>>(istream &in,Train_information &T);
string getTrain_number();
Time getTimeB();
Time getTimeE();
string getStation();
void changeTime(Time t1,Time t2);
};
string Train_information::getStation()
{
return Station;
};
Time Train_information::getTimeE()
{
return to;
}
Time Train_information::getTimeB()
{
return from;
};
string Train_information::getTrain_number()
{
return Train_number;
};
void Train_information::changeTime(Time t1,Time t2)
{
from=t1;
to=t2;
}
istream&operator>>(istream &in,Train_information &T)
{
in>>T.Train_number;
in>>T.Station;
in>>T.from;
in>>T.to;
return in;
}
ostream&operator<<(ostream &os,Train_information &T)
{
os<<T.Train_number<<" ";
os<<T.Station<<" ";
os<<T.from<<" ";
os<<T.to<<" ";
return os;
}
class Station
{
string name;
int num;
vector<Train_information>T;
multimap<string,int>k;
multimap<string,int>::iterator k1;
public:
Station(string name,int num)
{
this->name=name;
this->num=num;
k.clear();
T.clear();
}
Station()
{
num=0;
k.clear();
T.clear();
}
vector<Train_information>& getTrain_information()
{
return T;
};
multimap<string,int>& getMap()
{
return k;
};
friend ostream&operator<<(ostream &os,Station &s);
friend istream&operator>>(istream &in,Station &s);
int searchIf(string number);
int searchNumber(string number);
int getNum();
string getName();
string search(int i);
Train_information getT(int i);
void changeTime();
void deleteInformation(string number);
void deleteInformation();
void addTrain_information(Train_information t);
};
void Station::deleteInformation(string number)
{
k1=k.find(number);
int i=k1->second;
T.erase(i+T.begin());
num--;
}
string Station::getName()
{
return name;
};
Train_information Station::getT(int i)
{
return T[i];
};
void Station::deleteInformation()
{
T.clear();
};
int Station::getNum()
{
return num;
};
void Station::addTrain_information(Train_information t)
{
num++;
T.push_back(t);
};
int Station::searchIf(string number)
{
return searchNumber(number)+1>0?searchNumber(number)+1:0;
}
int Station::searchNumber(string number)
{
k1=k.find(number);
if(k1!=k.end())
{
int H=k1->second;
return H;
}
return -1;
}
void Station::changeTime()
{
cout<<"请输入车号\n";
string number;
cin>>number;
int i=searchNumber(number);
cout<<"请输入时间\n";
Time t1,t2;
cin>>t1>>t2;
cout<<"修改成功\n";
cout<<T[i].getTimeB();
}
string Station::search(int i)
{
return T[i].getTrain_number();//找站点里第几个位置的车次序号
}
istream&operator>>(istream &in,Station &s)
{
s.getMap().clear();
in>>s.name;
if(s.name=="E")return in;
in>>s.num;//这个站点被哪些车次经过
int j=-1;
for(int i=0; i<s.num; i++)
{
++j;
Train_information TT;
in>>TT;
s.T.push_back(TT);
s.getMap().insert(make_pair(TT.getTrain_number(),j));
}
return in;
}
ostream&operator<<(ostream &os,Station &s)
{
os<<s.name<<" ";
os<<s.num;
os<<endl;
for(int i=0; i<s.num; i++)
{
os<<s.T[i];
os<<endl;
}
return os;
}
class Train_number//车次
{
string number;
string from;
string to;
int num;
vector<Train_information>T;
multimap<string,int>m;
multimap<string,int>::iterator m1;
public:
Train_number(string number,string from,string to,int num)
{
this->number=number;
this->from=from;
this->to=to;
this->num=num;
}
Train_number()
{
num=0;
}
friend ostream&operator<<(ostream &os,Train_number &t);
friend istream&operator>>(istream &in,Train_number &t);
void deleteInformation()
{
T.clear();
m.clear();
};
void deleteInformation(string name)
{
m1=m.find(name);
int i=m1->second;
T.erase(i+T.begin());
num--;
}
string search(int i)
{
return T[i].getStation();
}
int getNum()
{
return num;
};
void setNum(int i)
{
num=i;
};
string getNumber()
{
return number;
};
Time getTimeB()
{
return T[0].getTimeB();
};
Time getTimeE()
{
return T[T.size()].getTimeE();
}
void addTrain_information(Train_information t)
{
++num;
T.push_back(t);
};
multimap<string,int>& getMap()
{
return m;
}
vector<Train_information>& getTrain_information()
{
return T;
};
int searchName(string name);
};
int Train_number::searchName(string name)
{
m1=m.find(name);
int i;
if(m1!=m.end())
{
i=m1->second;
return i;
}
return -1;
}
istream&operator>>(istream &in,Train_number &t)
{
t.getMap().clear();
in>>t.number;
if(t.number=="E")return in;
in>>t.from;
in>>t.to;
in>>t.num;
int j=-1;
for(int i=0; i<t.num; i++)
{
++j;
Train_information TT;
in>>TT;
t.T.push_back(TT);
t.getMap().insert(make_pair(TT.getStation(),j));
}
return in;
}
ostream&operator<<(ostream &os,Train_number &t)
{
os<<t.number<<" ";
os<<t.from<<" ";
os<<t.to<<" ";
os<<t.num;
os<<endl;
for(int i=0; i<t.num; i++)
{
os<<t.T[i];
os<<endl;
}
return os;
}
class AdminOp
{
vector<Station>s;
vector<Station>::iterator it1;
multimap<string,int>m1;
multimap<string,int>::iterator m1p;
multimap<Time,int>m3;
multimap<Time,int>::iterator m3p;
vector<Train_number>t;
vector<Train_number>::iterator it2 ;
multimap<string,int>m2;
multimap<string,int>::iterator m2p;
public:
AdminOp()
{
load1();
load2();
}
~AdminOp()
{
save1();
save2();
}
void load1();
void load2();
void save1();
void save2();
void addTrain();
void deleteTrain();
void addStation();
void deleteStation();
void displayTrain();
void displayStation();
void searchStation();
void searchTrain_number();
int searchS(string where);
int searchT(string number);
void changeStationTime();
//时间调度
void arrangeStationTime();
void arrangeTrainTime();
};
void AdminOp::load1()
{
int i;
Train_number tt;
ifstream infile("e:\\train.txt",ios::in);
if(!infile)
return;
t.clear();
i=0;
while(infile>>tt)
{
t.push_back(tt);
m2.insert(make_pair(tt.getNumber(),i));
i++;
tt.deleteInformation();
}
infile.close();
}
void AdminOp::load2()
{
int i;
Station ss;
ifstream infile("e:\\station.txt",ios::in);
if(!infile)
return;
s.clear();
i=0;
while(infile>>ss)
{
s.push_back(ss);
m1.insert(make_pair(ss.getName(),i));
i++;
ss.deleteInformation();
}
infile.close();
}
void AdminOp::save1()
{
ofstream outfile("e:\\train.txt",ios::out);
if(!outfile)
return;
for(it2=t.begin(); it2!=t.end(); it2++)
{
outfile<<*it2;
}
outfile.close();
}
void AdminOp::save2()
{
ofstream outfile("e:\\station.txt",ios::out);
if(!outfile)
return;
for(it1=s.begin(); it1!=s.end(); it1++)
{
outfile<<*it1;
}
outfile.close();
}
void AdminOp::searchStation()
{
cout<<"您想查询的站点为\n";
string where;
cin>>where;
if(searchT(where)==-1)
cout<<"没找到\n";
else
{
cout<<s[searchS(where)];
}
}
void AdminOp::searchTrain_number()
{
cout<<"您想查询的车次为\n";
string number;
cin>>number;
if(searchS(number)==-1)
cout<<"没找到\n";
else
{
cout<<t[searchS(number)];
}
}
int AdminOp::searchS(string where)
{
m1p=m1.find(where);
if(m1p!=m1.end())
{
int i=m1p->second;
return i;
}
else return -1;
}
int AdminOp::searchT(string number)
{
m2p=m2.find(number);
if(m2p!=m2.end())
{
int i=m2p->second;
return i;
}
else return -1;
}
void AdminOp::changeStationTime()//同时修改站点,车次时间
{
cout<<"您想修改哪个站点,输入E结束\n";
string name;
while(cin>>name)
{
if(name=="E")break;
int i=searchS(name);//找到s[i],某个站点,站点下有各个车次经过的时间,对其修改.
if(i<0)cout<<"没找到\n";
cout<<"输入修改的车次\n";
cout<<"第几个站点: "<<i<<endl;
string number;
cin>>number;
int j=searchT(number);
if(j<0)cout<<"没找到\n";
cout<<"第几班车:"<<j<<endl;
//找到t[j];
// cout<<s[i];
int k;
k=s[i].searchNumber(number);
int l;
l=t[j].searchName(name);?
cout<<"该站点的第几个车: "<<k<<endl;
cout<<"该车次对的第几个站点: "<<l<<endl;;//L
if(k==-1||l==-1)
{
cout<<"没找到\n";
}
else
{
cout<<"请输入时间\n";
Time t1,t2;
cin>>t1>>t2;
s[i].getTrain_information()[k].changeTime( t1, t2);
t[j].getTrain_information()[l].changeTime( t1, t2);
cout<<"成功\n";
}
}
}
void AdminOp::addStation()
{
cout<<"你想增加的站点信息为,输入车站名称E结束\n";
while(1)
{
Station ss;
cin>>ss;
if(ss.getName()=="E")
{
break;
}
s.push_back(ss);
cout<<"添加成功\n";
}
}
void AdminOp::deleteStation()//删除站点的时候删除对应车次
{
cout<<"你想删除的站点信息为,输入车站名称E结束\n";
string name;
while(1)
{
cin>>name;
if(name=="E")break;
int i=searchS(name);//找到这个车站
it1=s.begin()+i;
cout<<"输入1修改对应车次\n";
int n;
cin>>n;
if(n==1)
{
for(int h=0; h<s[i].getNum(); h++)
{
string ll=s[i].search(h);
//依次找到各个车次的序号
int mm=searchT(ll);
//找到这个车次位置
//int nn=t[mm].searchName(name);
// t[mm].erase(nn);
t[mm].deleteInformation(name);
}
}
s.erase(it1);
cout<<"删除成功\n";
}
}
void AdminOp::addTrain()//增加车次的时候增加对应站点的车次
{
cout<<"你想增加的车次信息为,输入车次序号E结束\n";
while(1)
{
string number;
cout<<"输入车号: ";
cin>>number;
if(number=="E")break;
cout<<"输入起止站点: \n";
string from;
string to;
cin>>from>>to;
Train_number tt(number,from,to,0);
int num;
t.push_back(tt);
}
}
void AdminOp::deleteTrain()
{
cout<<"你想删除的车次为,输入车次序号E结束\n";
string number;
while(1)
{
cin>>number;
if(number=="E")break;
int i=searchT(number);
it2=t.begin()+i;
//找到对应的站点进行删除
cout<<"删除对应站点里的信息\n";
for(int h=0; h<t[i].getNum(); h++)
{
string ll=t[i].search(h);//返回对应站点名称
int n=searchS(ll);//找到站点位置
s[n].deleteInformation(number);
}
t.erase(it2);
cout<<"删除成功\n";//t[i]被删除
}
}
void AdminOp::displayTrain()
{
cout<<"This is all information about train\n";
for(it2=t.begin(); it2!=t.end(); it2++)
{
cout<<*it2;
}
}
void AdminOp::displayStation()
{
cout<<"This is all information about station\n";
for(it1=s.begin(); it1!=s.end(); it1++)
{
cout<<*it1;
}
}
void AdminOp::arrangeTrainTime()
{
cout<<"你想安排的车次名称为,输入E终止\n";
string number;
while(cin>>number)
{
if(number=="E")break;
int j=searchT(number);
if(j<0)cout<<"没找到\n";
cout<<"第几班车:"<<j<<endl;
cout<<"输入该车次信息数\n";
int num;
cin>>num;
for(int i=0; i<num; i++)
{
Time t1,t2;
string name;
cin>>t1>>t2;
cin>>name;
Train_information r(number,name,t1,t2);
t[j].addTrain_information(r);
int k=searchS(r.getStation());
if(k==-1)
{
cout<<"此站点不存在,请添加\n";
}
else
{
//再判断这个车次是否已经存在于这个站点;
if(s[k].searchIf(r.getTrain_number())==0)
{
s[k].addTrain_information(r);
}
}
}
cout<<"成功安排\n";
}
}
void AdminOp::arrangeStationTime()
{
cout<<"你想安排的站点名称为,输入E终止\n";
string name;
while(cin>>name)
{
if(name=="E")break;
int i=searchS(name);//找到s[i],某个站点,站点下有各个车次经过的时间,对其修改.
if(i<0)cout<<"没找到\n";
cout<<"基本信息条数及信息为\n";
string number;
Time t1;
Time t2;
int num;
cin>>num;
for(int K=0; K<num; K++)
{
cin>>t1>>t2;
cin>>number;
Train_information r(number,name,t1,t2);
s[i].addTrain_information(r);
}
//int j=s[i].searchNumber(number);//站点里面找车次
//s[i].getTrain_information()[j].changeTime( t1, t2);
cout<<"成功安排\n";
}
}
class ClientOp
{
vector<Station>s;
vector<Station>::iterator it1;
multimap<string,int>m1;
multimap<string,int>::iterator m1p;
multimap<Time,int>m3;
multimap<Time,int>::iterator m3p,m4p,m5p;
vector<Train_number>t;
vector<Train_number>::iterator it2 ;
multimap<string,int>m2;
multimap<string,int>::iterator m2p;
public:
ClientOp()
{
load1();
load2();
}
~ClientOp()
{
s.clear();
t.clear();
m1.clear();
m2.clear();
}
void load1();
void load2();
void save1();
void save2();
void changeTrain();
void searchBase();
void searchTimeBaseBegin();
void searchTimeBaseEnd();
void searchStation();
void searchTrain_number();
int searchS(string where);
int searchT(string number);
void displayTrain();
void displayStation();
};
void ClientOp::changeTrain()
{
cout<<"换乘\n";
cout<<"请输入起始站点\n";
string from;
string to;
bool f=0;
cin>>from>>to;
int i=searchS(from);
int j=searchS(to);//找到两个站点s[i],s[j];
for(int k=0; k<s[j].getNum(); k++)
{
string l=s[j].search(k);
//依次找到各个车次的序号
int m=searchT(l);
//找到这个车次位置
int n=t[m].searchName(from);
//看这个车次里是否有这个站点;
if(n!=-1)
{
f=1;
cout<<t[m]<<endl;
};//n!=-1说明已经找到
}
if(f==0)
{
cout<<"没找到,请输入1换乘,其它终止\n";
int n;
cin>>n;
if(n==1)
{
/*以天津南到苏州为例,天津南不可直接到达
但是可以到达济南西,从济南西可以直接到达苏州
所以可以换乘;先找这个站点所属车次继续找这个from的下一个站点,找这个站点所经过的车次,看这个车次是否经过from*/
for(int k=0; k<s[i].getNum(); k++)
{
string l=s[i].search(k);
//依次找到各个车次的序号
int m=searchT(l);
//找到这个车次位置
int n=t[m].searchName(from);
//看这个车次里是否有这个站点;
//返回该站点在车次的第几个位置
for(int q=n+1; q<t[m].getNum()-1; q++)
{
string o=t[m].getTrain_information()[q].getStation();//返回站点
int oo=searchS(o);//s[oo]中间站点位置
for(int h=0; h<s[oo].getNum(); h++)
{
string ll=s[oo].search(h);
//依次找到各个车次的序号
int mm=searchT(ll);
//找到这个车次位置
int nn=t[mm].searchName(to);
if(nn!=-1)
{
cout<<"首发车次: \n";
cout<<t[m]<<endl;
cout<<"中间站点: "<<s[oo].getName()<<endl;
cout<<"换乘车次: \n";
cout<<t[mm]<<"换乘成功!"<<endl;
}
}
}
}
/*找到到达的站点;
在这个站点里寻找车次,在所有车次里寻找开始的站点;
优于二重循环;*/
}
}
}
void ClientOp::displayStation()
{
cout<<"This is all information about station\n";
for(it1=s.begin(); it1!=s.end(); it1++)
{
cout<<*it1;
}
}
void ClientOp::searchTimeBaseEnd()
{
cout<<"请输入出发到达站点\n";
string from;
string to;
cin>>from>>to;
int i=searchS(from);
int j=searchS(to);//找到两个站点s[i],s[j];
bool f=0;
cout<<"到达时间限定查询\n";//此时间后发出的车,相对于初始站
Time tt;
cin>>tt;
for(int k=0; k<s[j].getNum(); k++)
{
string l=s[j].search(k);
//依次找到各个车次的序号
int m=searchT(l);
//找到这个车次位置
int n=t[m].searchName(from);
//看这个车次里是否有这个站点;
if(n!=-1)
{
f=1;
if(t[m].getTrain_information()[n].getTimeB()<tt)
{
cout<<t[m]<<endl;
}
};//n!=-1说明已经找到
}
}
void ClientOp::searchTimeBaseBegin()
{
cout<<"请输入出发到达站点\n";
string from;
string to;
cin>>from>>to;
int i=searchS(from);
int j=searchS(to);//找到两个站点s[i],s[j];
bool f=0;
cout<<"发车时间限定查询\n";//此时间后发出的车,相对于初始站
Time tt;
cin>>tt;
for(int k=0; k<s[j].getNum(); k++)
{
string l=s[j].search(k);
//依次找到各个车次的序号
int m=searchT(l);
//找到这个车次位置
int n=t[m].searchName(from);
//看这个车次里是否有这个站点;//还要找到这个站点的发车时间
//找到这个车次中该站点的发车时间
if(n!=-1)
{
f=1;
//int l=t[m].getTrain_information()[n].getTimeB();
if(tt<t[m].getTrain_information()[n].getTimeB())
{
cout<<t[m]<<endl;
}
};//n!=-1说明已经找到
}
}
void ClientOp::searchBase()
{
cout<<"请输入起始站点\n";
string from;
string to;
bool f=0;
cin>>from>>to;
int i=searchS(from);
int j=searchS(to);//找到两个站点s[i],s[j];
for(int k=0; k<s[j].getNum(); k++)
{
string l=s[j].search(k);
//依次找到各个车次的序号
int m=searchT(l);
//找到这个车次位置
int n=t[m].searchName(from);
//看这个车次里是否有这个站点;
if(n!=-1)
{
f=1;
cout<<t[m]<<endl;
};//n!=-1说明已经找到
}
if(f==0)
{
cout<<"没找到,请换乘\n";
}
}
int ClientOp::searchS(string where)
{
m1p=m1.find(where);
if(m1p!=m1.end())
{
int i=m1p->second;
return i;
}
else return -1;
}
int ClientOp::searchT(string number)
{
m2p=m2.find(number);
if(m2p!=m2.end())
{
int i=m2p->second;
return i;
}
else return -1;
}
void ClientOp::searchStation()
{
cout<<"您想查询的站点为\n";
string where;
cin>>where;
if(searchS(where)==-1)
cout<<"没找到\n";
else
{
cout<<s[searchS(where)];
}
}
void ClientOp::searchTrain_number()
{
cout<<"您想查询的车次为\n";
string number;
cin>>number;
if(searchT(number)==-1)
cout<<"没找到\n";
else
{
cout<<t[searchT(number)];
}
}
void ClientOp::displayTrain()
{
cout<<"This is all information about train\n";
for(it2=t.begin(); it2!=t.end(); it2++)
{
cout<<*it2;
}
}
void ClientOp::load1()
{
int i;
Train_number tt;
ifstream infile("e:\\train.txt",ios::in);
if(!infile)
return;
t.clear();
i=0;
while(infile>>tt)
{
t.push_back(tt);
//cout<<tt;
m2.insert(make_pair(tt.getNumber(),i));
i++;
tt.deleteInformation();
}
infile.close();
}
void ClientOp::load2()
{
int i;
Station ss;
ifstream infile("e:\\station.txt",ios::in);
if(!infile)
return;
s.clear();
i=0;
while(infile>>ss)
{
s.push_back(ss);
//cout<<ss;
m1.insert(make_pair(ss.getName(),i));
i++;
ss.deleteInformation();
}
infile.close();
}
int main()
{
//AdminOp a;
// a.displayStation();
//a.displayTrain();
AdminOp b;
b.deleteTrain();
//AdminOp b;
//b.addStation();
//ClientOp c;
//c.displayStation();
//c.displayTrain();
//c.searchTrain_number();
//c.changeTrain();
//c.searchStation();
//c.searchTimeBaseBegin();
//ClientOp a;
//a.searchTimeBaseEnd();
// a.addTrain();
//a.addStation();
//a.deleteTrain();
// a.deleteStation();
//a.changeStationTime();
//a.arrangeTrainTime();
//a.arrangeStationTime();
return 0;
}
using namespace std;
class Time
{
int hour;
int minute;
public:
Time(int v,int m ):hour(v),minute(m) {}
Time()
{
hour=0;
minute=0;
}
int getHour()
{
return hour;
};
int getMinute()
{
return minute;
};
bool operator<(const Time&d)const
{
return hour!=d.hour?hour<d.hour:minute<d.minute;
}
friend ostream&operator<<(ostream &os, const Time &d);
friend istream&operator>>(istream &in, Time &d);
};
ostream&operator<<(ostream &os,const Time &d)
{
os<<d.hour<<" "<<d.minute;
return os;
}
istream&operator>>(istream &in,Time &d)
{
in>>d.hour;
in>>d.minute;
return in;
}
class Train_information
{
string Train_number;
string Station;
Time from;
Time to;
public:
Train_information(string Train_number,string Station,Time from,Time to)
{
this->Train_number=Train_number;
this->Station=Station;
this->from=from;
this->to=to;
}
Train_information()
{
}
friend ostream&operator<<(ostream &os,Train_information &T);
friend istream&operator>>(istream &in,Train_information &T);
string getTrain_number();
Time getTimeB();
Time getTimeE();
string getStation();
void changeTime(Time t1,Time t2);
};
string Train_information::getStation()
{
return Station;
};
Time Train_information::getTimeE()
{
return to;
}
Time Train_information::getTimeB()
{
return from;
};
string Train_information::getTrain_number()
{
return Train_number;
};
void Train_information::changeTime(Time t1,Time t2)
{
from=t1;
to=t2;
}
istream&operator>>(istream &in,Train_information &T)
{
in>>T.Train_number;
in>>T.Station;
in>>T.from;
in>>T.to;
return in;
}
ostream&operator<<(ostream &os,Train_information &T)
{
os<<T.Train_number<<" ";
os<<T.Station<<" ";
os<<T.from<<" ";
os<<T.to<<" ";
return os;
}
class Station
{
string name;
int num;
vector<Train_information>T;
multimap<string,int>k;
multimap<string,int>::iterator k1;
public:
Station(string name,int num)
{
this->name=name;
this->num=num;
k.clear();
T.clear();
}
Station()
{
num=0;
k.clear();
T.clear();
}
vector<Train_information>& getTrain_information()
{
return T;
};
multimap<string,int>& getMap()
{
return k;
};
friend ostream&operator<<(ostream &os,Station &s);
friend istream&operator>>(istream &in,Station &s);
int searchIf(string number);
int searchNumber(string number);
int getNum();
string getName();
string search(int i);
Train_information getT(int i);
void changeTime();
void deleteInformation(string number);
void deleteInformation();
void addTrain_information(Train_information t);
};
void Station::deleteInformation(string number)
{
k1=k.find(number);
int i=k1->second;
T.erase(i+T.begin());
num--;
}
string Station::getName()
{
return name;
};
Train_information Station::getT(int i)
{
return T[i];
};
void Station::deleteInformation()
{
T.clear();
};
int Station::getNum()
{
return num;
};
void Station::addTrain_information(Train_information t)
{
num++;
T.push_back(t);
};
int Station::searchIf(string number)
{
return searchNumber(number)+1>0?searchNumber(number)+1:0;
}
int Station::searchNumber(string number)
{
k1=k.find(number);
if(k1!=k.end())
{
int H=k1->second;
return H;
}
return -1;
}
void Station::changeTime()
{
cout<<"请输入车号\n";
string number;
cin>>number;
int i=searchNumber(number);
cout<<"请输入时间\n";
Time t1,t2;
cin>>t1>>t2;
cout<<"修改成功\n";
cout<<T[i].getTimeB();
}
string Station::search(int i)
{
return T[i].getTrain_number();//找站点里第几个位置的车次序号
}
istream&operator>>(istream &in,Station &s)
{
s.getMap().clear();
in>>s.name;
if(s.name=="E")return in;
in>>s.num;//这个站点被哪些车次经过
int j=-1;
for(int i=0; i<s.num; i++)
{
++j;
Train_information TT;
in>>TT;
s.T.push_back(TT);
s.getMap().insert(make_pair(TT.getTrain_number(),j));
}
return in;
}
ostream&operator<<(ostream &os,Station &s)
{
os<<s.name<<" ";
os<<s.num;
os<<endl;
for(int i=0; i<s.num; i++)
{
os<<s.T[i];
os<<endl;
}
return os;
}
class Train_number//车次
{
string number;
string from;
string to;
int num;
vector<Train_information>T;
multimap<string,int>m;
multimap<string,int>::iterator m1;
public:
Train_number(string number,string from,string to,int num)
{
this->number=number;
this->from=from;
this->to=to;
this->num=num;
}
Train_number()
{
num=0;
}
friend ostream&operator<<(ostream &os,Train_number &t);
friend istream&operator>>(istream &in,Train_number &t);
void deleteInformation()
{
T.clear();
m.clear();
};
void deleteInformation(string name)
{
m1=m.find(name);
int i=m1->second;
T.erase(i+T.begin());
num--;
}
string search(int i)
{
return T[i].getStation();
}
int getNum()
{
return num;
};
void setNum(int i)
{
num=i;
};
string getNumber()
{
return number;
};
Time getTimeB()
{
return T[0].getTimeB();
};
Time getTimeE()
{
return T[T.size()].getTimeE();
}
void addTrain_information(Train_information t)
{
++num;
T.push_back(t);
};
multimap<string,int>& getMap()
{
return m;
}
vector<Train_information>& getTrain_information()
{
return T;
};
int searchName(string name);
};
int Train_number::searchName(string name)
{
m1=m.find(name);
int i;
if(m1!=m.end())
{
i=m1->second;
return i;
}
return -1;
}
istream&operator>>(istream &in,Train_number &t)
{
t.getMap().clear();
in>>t.number;
if(t.number=="E")return in;
in>>t.from;
in>>t.to;
in>>t.num;
int j=-1;
for(int i=0; i<t.num; i++)
{
++j;
Train_information TT;
in>>TT;
t.T.push_back(TT);
t.getMap().insert(make_pair(TT.getStation(),j));
}
return in;
}
ostream&operator<<(ostream &os,Train_number &t)
{
os<<t.number<<" ";
os<<t.from<<" ";
os<<t.to<<" ";
os<<t.num;
os<<endl;
for(int i=0; i<t.num; i++)
{
os<<t.T[i];
os<<endl;
}
return os;
}
class AdminOp
{
vector<Station>s;
vector<Station>::iterator it1;
multimap<string,int>m1;
multimap<string,int>::iterator m1p;
multimap<Time,int>m3;
multimap<Time,int>::iterator m3p;
vector<Train_number>t;
vector<Train_number>::iterator it2 ;
multimap<string,int>m2;
multimap<string,int>::iterator m2p;
public:
AdminOp()
{
load1();
load2();
}
~AdminOp()
{
save1();
save2();
}
void load1();
void load2();
void save1();
void save2();
void addTrain();
void deleteTrain();
void addStation();
void deleteStation();
void displayTrain();
void displayStation();
void searchStation();
void searchTrain_number();
int searchS(string where);
int searchT(string number);
void changeStationTime();
//时间调度
void arrangeStationTime();
void arrangeTrainTime();
};
void AdminOp::load1()
{
int i;
Train_number tt;
ifstream infile("e:\\train.txt",ios::in);
if(!infile)
return;
t.clear();
i=0;
while(infile>>tt)
{
t.push_back(tt);
m2.insert(make_pair(tt.getNumber(),i));
i++;
tt.deleteInformation();
}
infile.close();
}
void AdminOp::load2()
{
int i;
Station ss;
ifstream infile("e:\\station.txt",ios::in);
if(!infile)
return;
s.clear();
i=0;
while(infile>>ss)
{
s.push_back(ss);
m1.insert(make_pair(ss.getName(),i));
i++;
ss.deleteInformation();
}
infile.close();
}
void AdminOp::save1()
{
ofstream outfile("e:\\train.txt",ios::out);
if(!outfile)
return;
for(it2=t.begin(); it2!=t.end(); it2++)
{
outfile<<*it2;
}
outfile.close();
}
void AdminOp::save2()
{
ofstream outfile("e:\\station.txt",ios::out);
if(!outfile)
return;
for(it1=s.begin(); it1!=s.end(); it1++)
{
outfile<<*it1;
}
outfile.close();
}
void AdminOp::searchStation()
{
cout<<"您想查询的站点为\n";
string where;
cin>>where;
if(searchT(where)==-1)
cout<<"没找到\n";
else
{
cout<<s[searchS(where)];
}
}
void AdminOp::searchTrain_number()
{
cout<<"您想查询的车次为\n";
string number;
cin>>number;
if(searchS(number)==-1)
cout<<"没找到\n";
else
{
cout<<t[searchS(number)];
}
}
int AdminOp::searchS(string where)
{
m1p=m1.find(where);
if(m1p!=m1.end())
{
int i=m1p->second;
return i;
}
else return -1;
}
int AdminOp::searchT(string number)
{
m2p=m2.find(number);
if(m2p!=m2.end())
{
int i=m2p->second;
return i;
}
else return -1;
}
void AdminOp::changeStationTime()//同时修改站点,车次时间
{
cout<<"您想修改哪个站点,输入E结束\n";
string name;
while(cin>>name)
{
if(name=="E")break;
int i=searchS(name);//找到s[i],某个站点,站点下有各个车次经过的时间,对其修改.
if(i<0)cout<<"没找到\n";
cout<<"输入修改的车次\n";
cout<<"第几个站点: "<<i<<endl;
string number;
cin>>number;
int j=searchT(number);
if(j<0)cout<<"没找到\n";
cout<<"第几班车:"<<j<<endl;
//找到t[j];
// cout<<s[i];
int k;
k=s[i].searchNumber(number);
int l;
l=t[j].searchName(name);?
cout<<"该站点的第几个车: "<<k<<endl;
cout<<"该车次对的第几个站点: "<<l<<endl;;//L
if(k==-1||l==-1)
{
cout<<"没找到\n";
}
else
{
cout<<"请输入时间\n";
Time t1,t2;
cin>>t1>>t2;
s[i].getTrain_information()[k].changeTime( t1, t2);
t[j].getTrain_information()[l].changeTime( t1, t2);
cout<<"成功\n";
}
}
}
void AdminOp::addStation()
{
cout<<"你想增加的站点信息为,输入车站名称E结束\n";
while(1)
{
Station ss;
cin>>ss;
if(ss.getName()=="E")
{
break;
}
s.push_back(ss);
cout<<"添加成功\n";
}
}
void AdminOp::deleteStation()//删除站点的时候删除对应车次
{
cout<<"你想删除的站点信息为,输入车站名称E结束\n";
string name;
while(1)
{
cin>>name;
if(name=="E")break;
int i=searchS(name);//找到这个车站
it1=s.begin()+i;
cout<<"输入1修改对应车次\n";
int n;
cin>>n;
if(n==1)
{
for(int h=0; h<s[i].getNum(); h++)
{
string ll=s[i].search(h);
//依次找到各个车次的序号
int mm=searchT(ll);
//找到这个车次位置
//int nn=t[mm].searchName(name);
// t[mm].erase(nn);
t[mm].deleteInformation(name);
}
}
s.erase(it1);
cout<<"删除成功\n";
}
}
void AdminOp::addTrain()//增加车次的时候增加对应站点的车次
{
cout<<"你想增加的车次信息为,输入车次序号E结束\n";
while(1)
{
string number;
cout<<"输入车号: ";
cin>>number;
if(number=="E")break;
cout<<"输入起止站点: \n";
string from;
string to;
cin>>from>>to;
Train_number tt(number,from,to,0);
int num;
t.push_back(tt);
}
}
void AdminOp::deleteTrain()
{
cout<<"你想删除的车次为,输入车次序号E结束\n";
string number;
while(1)
{
cin>>number;
if(number=="E")break;
int i=searchT(number);
it2=t.begin()+i;
t.erase(it2);
cout<<"删除成功\n";//t[i]被删除
//找到对应的站点进行删除
cout<<"删除对应站点里的信息\n";
for(int h=0;h<t[i].getNum();h++)
{
string ll=t[i].search(h);//返回对应站点名称
int n=searchS(ll);//找到站点位置
s[n].deleteInformation(number);
}
}
}
void AdminOp::displayTrain()
{
cout<<"This is all information about train\n";
for(it2=t.begin(); it2!=t.end(); it2++)
{
cout<<*it2;
}
}
void AdminOp::displayStation()
{
cout<<"This is all information about station\n";
for(it1=s.begin(); it1!=s.end(); it1++)
{
cout<<*it1;
}
}
void AdminOp::arrangeTrainTime()
{
cout<<"你想安排的车次名称为,输入E终止\n";
string number;
while(cin>>number)
{
if(number=="E")break;
int j=searchT(number);
if(j<0)cout<<"没找到\n";
cout<<"第几班车:"<<j<<endl;
cout<<"输入该车次信息数\n";
int num;
cin>>num;
for(int i=0; i<num; i++)
{
Time t1,t2;
string name;
cin>>t1>>t2;
cin>>name;
Train_information r(number,name,t1,t2);
t[j].addTrain_information(r);
int k=searchS(r.getStation());
if(k==-1)
{
cout<<"此站点不存在,请添加\n";
}
else
{
//再判断这个车次是否已经存在于这个站点;
if(s[k].searchIf(r.getTrain_number())==0)
{
s[k].addTrain_information(r);
}
}
}
cout<<"成功安排\n";
}
}
void AdminOp::arrangeStationTime()
{
cout<<"你想安排的站点名称为,输入E终止\n";
string name;
while(cin>>name)
{
if(name=="E")break;
int i=searchS(name);//找到s[i],某个站点,站点下有各个车次经过的时间,对其修改.
if(i<0)cout<<"没找到\n";
cout<<"基本信息条数及信息为\n";
string number;
Time t1;
Time t2;
int num;
cin>>num;
for(int K=0;K<num;K++)
{
cin>>t1>>t2;
cin>>number;
Train_information r(number,name,t1,t2);
s[i].addTrain_information(r);
}
//int j=s[i].searchNumber(number);//站点里面找车次
//s[i].getTrain_information()[j].changeTime( t1, t2);
cout<<"成功安排\n";
}
}
class ClientOp
{
vector<Station>s;
vector<Station>::iterator it1;
multimap<string,int>m1;
multimap<string,int>::iterator m1p;
multimap<Time,int>m3;
multimap<Time,int>::iterator m3p,m4p,m5p;
vector<Train_number>t;
vector<Train_number>::iterator it2 ;
multimap<string,int>m2;
multimap<string,int>::iterator m2p;
public:
ClientOp()
{
load1();
load2();
}
~ClientOp()
{
s.clear();
t.clear();
m1.clear();
m2.clear();
}
void load1();
void load2();
void save1();
void save2();
void changeTrain();
void searchBase();
void searchTimeBaseBegin();
void searchTimeBaseEnd();
void searchStation();
void searchTrain_number();
int searchS(string where);
int searchT(string number);
void displayTrain();
void displayStation();
};
void ClientOp::changeTrain()
{
cout<<"换乘\n";
cout<<"请输入起始站点\n";
string from;
string to;
bool f=0;
cin>>from>>to;
int i=searchS(from);
int j=searchS(to);//找到两个站点s[i],s[j];
for(int k=0; k<s[j].getNum(); k++)
{
string l=s[j].search(k);
//依次找到各个车次的序号
int m=searchT(l);
//找到这个车次位置
int n=t[m].searchName(from);
//看这个车次里是否有这个站点;
if(n!=-1)
{
f=1;
cout<<t[m]<<endl;
};//n!=-1说明已经找到
}
if(f==0)
{
cout<<"没找到,请输入1换乘,其它终止\n";
int n;
cin>>n;
if(n==1)
{
/*以天津南到苏州为例,天津南不可直接到达
但是可以到达济南西,从济南西可以直接到达苏州
所以可以换乘;先找这个站点所属车次继续找这个from的下一个站点,找这个站点所经过的车次,看这个车次是否经过from*/
for(int k=0; k<s[i].getNum(); k++)
{
string l=s[i].search(k);
//依次找到各个车次的序号
int m=searchT(l);
//找到这个车次位置
int n=t[m].searchName(from);
//看这个车次里是否有这个站点;
//返回该站点在车次的第几个位置
for(int q=n; q<t[m].getNum()-1; q++)
{
string o=t[m].getTrain_information()[q].getStation();//返回站点
int oo=searchS(o);//s[oo]
for(int h=0; h<s[oo].getNum(); h++)
{
string ll=s[oo].search(h);
//依次找到各个车次的序号
int mm=searchT(ll);
//找到这个车次位置
int nn=t[mm].searchName(to);
if(nn!=-1)
{
cout<<t[mm]<<"换乘成功!"<<endl;
}
}
}
}
/*找到到达的站点;
在这个站点里寻找车次,在所有车次里寻找开始的站点;
优于二重循环;*/
}
}
}
void ClientOp::displayStation()
{
cout<<"This is all information about station\n";
for(it1=s.begin(); it1!=s.end(); it1++)
{
cout<<*it1;
}
}
void ClientOp::searchTimeBaseEnd()
{
cout<<"请输入出发到达站点\n";
string from;
string to;
cin>>from>>to;
int i=searchS(from);
int j=searchS(to);//找到两个站点s[i],s[j];
bool f=0;
cout<<"到达时间限定查询\n";//此时间后发出的车,相对于初始站
Time tt;
cin>>tt;
for(int k=0; k<s[j].getNum(); k++)
{
string l=s[j].search(k);
//依次找到各个车次的序号
int m=searchT(l);
//找到这个车次位置
int n=t[m].searchName(from);
//看这个车次里是否有这个站点;
if(n!=-1)
{
f=1;
if(t[m].getTrain_information()[n].getTimeB()<tt)
{
cout<<t[m]<<endl;
}
};//n!=-1说明已经找到
}
}
void ClientOp::searchTimeBaseBegin()
{
cout<<"请输入出发到达站点\n";
string from;
string to;
cin>>from>>to;
int i=searchS(from);
int j=searchS(to);//找到两个站点s[i],s[j];
bool f=0;
cout<<"发车时间限定查询\n";//此时间后发出的车,相对于初始站
Time tt;
cin>>tt;
for(int k=0; k<s[j].getNum(); k++)
{
string l=s[j].search(k);
//依次找到各个车次的序号
int m=searchT(l);
//找到这个车次位置
int n=t[m].searchName(from);
//看这个车次里是否有这个站点;//还要找到这个站点的发车时间
//找到这个车次中该站点的发车时间
if(n!=-1)
{
f=1;
//int l=t[m].getTrain_information()[n].getTimeB();
if(tt<t[m].getTrain_information()[n].getTimeB())
{
cout<<t[m]<<endl;
}
};//n!=-1说明已经找到
}
}
void ClientOp::searchBase()
{
cout<<"请输入起始站点\n";
string from;
string to;
bool f=0;
cin>>from>>to;
int i=searchS(from);
int j=searchS(to);//找到两个站点s[i],s[j];
for(int k=0; k<s[j].getNum(); k++)
{
string l=s[j].search(k);
//依次找到各个车次的序号
int m=searchT(l);
//找到这个车次位置
int n=t[m].searchName(from);
//看这个车次里是否有这个站点;
if(n!=-1)
{
f=1;
cout<<t[m]<<endl;
};//n!=-1说明已经找到
}
if(f==0)
{
cout<<"没找到,请输入1换乘,其它终止\n";
int n;
cin>>n;
if(n==1)
{
/*以天津南到苏州为例,天津南不可直接到达
但是可以到达济南西,从济南西可以直接到达苏州
所以可以换乘;先找这个站点所属车次继续找这个from的下一个站点,找这个站点所经过的车次,看这个车次是否经过from*/
for(int k=0; k<s[i].getNum(); k++)
{
string l=s[i].search(k);
//依次找到各个车次的序号
int m=searchT(l);
//找到这个车次位置
int n=t[m].searchName(from);
//看这个车次里是否有这个站点;
//返回该站点在车次的第几个位置
for(int q=n; q<t[m].getNum()-1; q++)
{
string o=t[m].getTrain_information()[q].getStation();//返回站点
int oo=searchS(o);//s[oo]
for(int h=0; h<s[oo].getNum(); h++)
{
string ll=s[oo].search(h);
//依次找到各个车次的序号
int mm=searchT(ll);
//找到这个车次位置
int nn=t[mm].searchName(to);
if(nn!=-1)
{
cout<<t[mm]<<"换乘成功!"<<endl;
break;
}
}
}
}
/*找到到达的站点;
在这个站点里寻找车次,在所有车次里寻找开始的站点;
优于二重循环;*/
}
}
}
int ClientOp::searchS(string where)
{
m1p=m1.find(where);
if(m1p!=m1.end())
{
int i=m1p->second;
return i;
}
else return -1;
}
int ClientOp::searchT(string number)
{
m2p=m2.find(number);
if(m2p!=m2.end())
{
int i=m2p->second;
return i;
}
else return -1;
}
void ClientOp::searchStation()
{
cout<<"您想查询的站点为\n";
string where;
cin>>where;
if(searchS(where)==-1)
cout<<"没找到\n";
else
{
cout<<s[searchS(where)];
}
}
void ClientOp::searchTrain_number()
{
cout<<"您想查询的车次为\n";
string number;
cin>>number;
if(searchT(number)==-1)
cout<<"没找到\n";
else
{
cout<<t[searchT(number)];
}
}
void ClientOp::displayTrain()
{
cout<<"This is all information about train\n";
for(it2=t.begin(); it2!=t.end(); it2++)
{
cout<<*it2;
}
}
void ClientOp::load1()
{
int i;
Train_number tt;
ifstream infile("e:\\train.txt",ios::in);
if(!infile)
return;
t.clear();
i=0;
while(infile>>tt)
{
t.push_back(tt);
//cout<<tt;
m2.insert(make_pair(tt.getNumber(),i));
i++;
tt.deleteInformation();
}
infile.close();
}
void ClientOp::load2()
{
int i;
Station ss;
ifstream infile("e:\\station.txt",ios::in);
if(!infile)
return;
s.clear();
i=0;
while(infile>>ss)
{
s.push_back(ss);
//cout<<ss;
m1.insert(make_pair(ss.getName(),i));
i++;
ss.deleteInformation();
}
infile.close();
}
int main()
{
//AdminOp a;
//a.displayStation();
//a.displayTrain();
//AdminOp b;
//b.addStation();
ClientOp c;
c.displayStation();
c.displayTrain();
//c.searchTrain_number();
c.searchBase();
//c.searchStation();
//c.searchTimeBaseBegin();
//ClientOp a;
//a.searchTimeBaseEnd();
// a.addTrain();
//a.addStation();
//a.deleteTrain();
// a.deleteStation();
//a.changeStationTime();
//a.arrangeTrainTime();
//a.arrangeStationTime();
return 0;
}
using namespace std;
class Time
{
int hour;
int minute;
public:
Time(int v,int m ):hour(v),minute(m) {}
Time()
{
hour=0;
minute=0;
}
int getHour()
{
return hour;
};
int getMinute()
{
return minute;
};
bool operator<(const Time&d)const
{
return hour!=d.hour?hour<d.hour:minute<d.minute;
}
friend ostream&operator<<(ostream &os, const Time &d);
friend istream&operator>>(istream &in, Time &d);
};
ostream&operator<<(ostream &os,const Time &d)
{
os<<d.hour<<" "<<d.minute;
return os;
}
istream&operator>>(istream &in,Time &d)
{
in>>d.hour;
in>>d.minute;
return in;
}
class Train_information
{
string Train_number;
string Station;
Time from;
Time to;
public:
Train_information(string Train_number,string Station,Time from,Time to)
{
this->Train_number=Train_number;
this->Station=Station;
this->from=from;
this->to=to;
}
Train_information()
{
//from=0;
// to=0;
}
friend ostream&operator<<(ostream &os,Train_information &T);
friend istream&operator>>(istream &in,Train_information &T);
string getTrain_number();
Time getTimeB();
Time getTimeE();
string getStation();
void changeTime(Time t1,Time t2);
};
string Train_information::getStation()
{
return Station;
};
Time Train_information::getTimeE()
{
return to;
}
Time Train_information::getTimeB()
{
return from;
};
string Train_information::getTrain_number()
{
return Train_number;
};
void Train_information::changeTime(Time t1,Time t2)
{
from=t1;
to=t2;
}
istream&operator>>(istream &in,Train_information &T)
{
in>>T.Train_number;
in>>T.Station;
in>>T.from;
in>>T.to;
return in;
}
ostream&operator<<(ostream &os,Train_information &T)
{
os<<T.Train_number<<" ";
os<<T.Station<<" ";
os<<T.from<<" ";
os<<T.to<<" ";
return os;
}
class Station
{
string name;
int num;
vector<Train_information>T;
multimap<string,int>k;
multimap<string,int>::iterator k1;
public:
Station(string name,int num)
{
this->name=name;
this->num=num;
k.clear();
T.clear();
}
Station()
{
num=0;
k.clear();
T.clear();
}
vector<Train_information>& getTrain_information()
{
return T;
};
multimap<string,int>& getMap(){return k;};
friend ostream&operator<<(ostream &os,Station &s);
friend istream&operator>>(istream &in,Station &s);
int searchIf(string number);
int searchNumber(string number);
int getNum();
string getName();
string search(int i);
Train_information getT(int i);
void changeTime();
void deleteInformation();
void addTrain_information(Train_information t);
};
string Station::getName()
{
return name;
};
Train_information Station::getT(int i)
{
return T[i];
};
void Station::deleteInformation()
{
T.clear();
};
int Station::getNum()
{
return num;
};
void Station::addTrain_information(Train_information t)
{
num++;
T.push_back(t);
};
int Station::searchIf(string number)
{
return searchNumber(number)+1>0?searchNumber(number)+1:0;
}
int Station::searchNumber(string number)
{
k1=k.find(number);
if(k1!=k.end())
{
int H=k1->second;
return H;
}
return -1;
}
void Station::changeTime()
{
cout<<"请输入车号\n";
string number;
cin>>number;
int i=searchNumber(number);
cout<<"请输入时间\n";
Time t1,t2;
cin>>t1>>t2;
cout<<"修改成功\n";
cout<<T[i].getTimeB();
}
string Station::search(int i)
{
return T[i].getTrain_number();
}
istream&operator>>(istream &in,Station &s)
{
in>>s.name;
if(s.name=="E")return in;
in>>s.num;//这个站点被哪些车次经过
int j=-1;
for(int i=0; i<s.num; i++)
{
++j;
Train_information TT;
in>>TT;
s.T.push_back(TT);
s.getMap().insert(make_pair(TT.getTrain_number(),j));
}
return in;
}
ostream&operator<<(ostream &os,Station &s)
{
os<<s.name<<" ";
os<<s.num;
os<<endl;
for(int i=0; i<s.num; i++)
{
os<<s.T[i];
os<<endl;
}
return os;
}
class Train_number//车次
{
string number;
string from;
string to;
int num;
vector<Train_information>T;
multimap<string,int>m;
multimap<string,int>::iterator m1;
public:
Train_number(string number,string from,string to,int num)
{
this->number=number;
this->from=from;
this->to=to;
this->num=num;
}
Train_number()
{
num=0;
}
friend ostream&operator<<(ostream &os,Train_number &t);
friend istream&operator>>(istream &in,Train_number &t);
void deleteInformation()
{
T.clear();
};
void deleteInformation(string name)
{
m1=m.find(name);
int i=m1->second;
T.erase(i+T.begin());
num--;
}
int getNum()
{
return num;
};
void setNum(int i)
{
num=i;
};
string getNumber()
{
return number;
};
Time getTimeB()
{
return T[0].getTimeB();
};
Time getTimeE()
{
return T[T.size()].getTimeE();
}
void addTrain_information(Train_information t)
{
++num;
T.push_back(t);
};
multimap<string,int>& getMap()
{
return m;
}
vector<Train_information>& getTrain_information()
{
return T;
};
int searchName(string name);
};
int Train_number::searchName(string name)
{
m1=m.find(name);
int i;
if(m1!=m.end())
{
i=m1->second;
return i;
}
return -1;
}
istream&operator>>(istream &in,Train_number &t)
{
t.getMap().clear();
in>>t.number;
if(t.number=="E")return in;
in>>t.from;
in>>t.to;
in>>t.num;
int j=-1;
for(int i=0; i<t.num; i++)
{
++j;
Train_information TT;
in>>TT;
t.T.push_back(TT);
t.getMap().insert(make_pair(TT.getStation(),j));
return in;
}
ostream&operator<<(ostream &os,Train_number &t)
{
os<<t.number<<" ";
os<<t.from<<" ";
os<<t.to<<" ";
os<<t.num;
os<<endl;
for(int i=0; i<t.num; i++)
{
os<<t.T[i];
os<<endl;
}
return os;
}
class AdminOp
{
vector<Station>s;
vector<Station>::iterator it1;
multimap<string,int>m1;
multimap<string,int>::iterator m1p;
multimap<Time,int>m3;
multimap<Time,int>::iterator m3p;
vector<Train_number>t;
vector<Train_number>::iterator it2 ;
multimap<string,int>m2;
multimap<string,int>::iterator m2p;
public:
AdminOp()
{
load1();
load2();
}
~AdminOp()
{
save1();
save2();
}
void load1();
void load2();
void save1();
void save2();
void addTrain();
void deleteTrain();
void addStation();
void deleteStation();
void displayTrain();
void displayStation();
void searchStation();
void searchTrain_number();
int searchS(string where);
int searchT(string number);
void changeStationTime();
//时间调度
void arrangeStationTime();
void arrangeTrainTime();
};
void AdminOp::load1()
{
int i;
Train_number tt;
ifstream infile("e:\\train.txt",ios::in);
if(!infile)
return;
t.clear();
i=0;
while(infile>>tt)
{
t.push_back(tt);
m2.insert(make_pair(tt.getNumber(),i));
i++;
tt.deleteInformation();
}
infile.close();
}
void AdminOp::load2()
{
int i;
Station ss;
ifstream infile("e:\\station.txt",ios::in);
if(!infile)
return;
s.clear();
i=0;
while(infile>>ss)
{
s.push_back(ss);
m1.insert(make_pair(ss.getName(),i));
i++;
ss.deleteInformation();
}
infile.close();
}
void AdminOp::save1()
{
ofstream outfile("e:\\train.txt",ios::out);
if(!outfile)
return;
for(it2=t.begin(); it2!=t.end(); it2++)
{
outfile<<*it2;
}
outfile.close();
}
void AdminOp::save2()
{
ofstream outfile("e:\\station.txt",ios::out);
if(!outfile)
return;
for(it1=s.begin(); it1!=s.end(); it1++)
{
outfile<<*it1;
}
outfile.close();
}
void AdminOp::searchStation()
{
cout<<"您想查询的站点为\n";
string where;
cin>>where;
if(searchT(where)==-1)
cout<<"没找到\n";
else
{
cout<<s[searchS(where)];
}
}
void AdminOp::searchTrain_number()
{
cout<<"您想查询的车次为\n";
string number;
cin>>number;
if(searchS(number)==-1)
cout<<"没找到\n";
else
{
cout<<t[searchS(number)];
}
}
int AdminOp::searchS(string where)
{
m1p=m1.find(where);
if(m1p!=m1.end())
{
int i=m1p->second;
return i;
}
else return -1;
}
int AdminOp::searchT(string number)
{
m2p=m2.find(number);
if(m2p!=m2.end())
{
int i=m2p->second;
return i;
}
else return -1;
}
void AdminOp::changeStationTime()//同时修改站点,车次时间
{
cout<<"您想修改哪个站点,输入E结束\n";
string name;
while(cin>>name)
{
int i=searchS(name);//找到s[i],某个站点,站点下有各个车次经过的时间,对其修改.
if(i<0)cout<<"没找到\n";
cout<<"输入修改的车次\n";
cout<<"第几个站点: "<<i<<endl;
string number;
cin>>number;
int j=searchT(number);
if(j<0)cout<<"没找到\n";
cout<<"第几班车:"<<j<<endl;
//找到t[j];
cout<<s[i];
int k;
k=s[i].searchNumber(number);
int l;
l=t[j].searchName(name);?
cout<<"该站点的第几个车: "<<k<<endl;
cout<<"该车次对的第几个站点: "<<l<<endl;;//L
if(k==-1||l==-1)
{
cout<<"没找到\n";
}
else
{
cout<<"请输入时间\n";
Time t1,t2;
cin>>t1>>t2;
s[i].getTrain_information()[k].changeTime( t1, t2);
t[j].getTrain_information()[l].changeTime( t1, t2);
cout<<"成功\n";
}
}
void AdminOp::addStation()
{
cout<<"你想增加的站点信息为,输入车站名称E结束\n";
while(1)
{
Station ss;
cin>>ss;
if(ss.getName()=="E")
{
break;
}
s.push_back(ss);
cout<<"添加成功\n";
}
}
void AdminOp::deleteStation()//删除站点的时候删除对应车次
{
cout<<"你想删除的站点信息为,输入车站名称E结束\n";
string name;
while(1)
{
cin>>name;
if(name=="E")break;
int i=searchS(name);//找到这个车站
it1=s.begin()+i;
cout<<"输入1修改对应车次\n";
int n;
cin>>n;
if(n==1)
{
for(int h=0; h<s[i].getNum(); h++)
{
string ll=s[i].search(h);
//依次找到各个车次的序号
int mm=searchT(ll);
//找到这个车次位置
//int nn=t[mm].searchName(name);
// t[mm].erase(nn);
t[mm].deleteInformation(name);
}
}
s.erase(it1);
cout<<"删除成功\n";
}
}
void AdminOp::addTrain()//增加车次的时候增加对应站点的车次
{
cout<<"你想增加的车次信息为,输入车次序号E结束\n";
while(1)
{
string number;
cout<<"输入车号: ";
cin>>number;
if(number=="E")break;
cout<<"输入起止站点: ";
string from;
string to;
cin>>from>>to;
cout<<"输入所经站点数: ";
Train_number tt(number,from,to,0);
int num;
cin>>num;
int k;
cout<<"输入站点信息\n";
for(int i=0; i<num; i++)
{
Train_information in;
cin>>in;
tt.addTrain_information(in);
k=searchS(in.getStation());
if(k==-1)
{
cout<<"此站点不存在,请添加\n";
}
else
{
//再判断这个车次是否已经存在于这个站点;
if(s[k].searchIf(in.getTrain_number())==0)
{
s[k].addTrain_information(in);
}
}
}
t.push_back(tt);
//在已有的站点再添加这个车次
} //可以同时添加站点
}
void AdminOp::deleteTrain()
{
cout<<"你想删除的车次为,输入车次序号E结束\n";
string number;
while(1)
{
cin>>number;
if(number=="E")break;
int i=searchT(number);
it2=t.begin()+i;
t.erase(it2);
cout<<"删除成功\n";
}
}
void AdminOp::displayTrain()
{
cout<<"This is all information about train\n";
for(it2=t.begin(); it2!=t.end(); it2++)
{
cout<<*it2;
}
}
void AdminOp::displayStation()
{
cout<<"This is all information about station\n";
for(it1=s.begin(); it1!=s.end(); it1++)
{
cout<<*it1;
}
}
void AdminOp::arrangeTrainTime()
{
cout<<"你想安排的车次名称为,输入E终止\n";
string number;
while(cin>>number)
{
if(number=="E")break;
int j=searchT(number);
if(j<0)cout<<"没找到\n";
cout<<"第几班车:"<<j<<endl;
//找到t[j];
cout<<"安排的站点起止时间依次为\n";
int num;
cin>>num;
for(int i=0; i<num; i++)
{
Time t1,t2;
cin>>t1>>t2;
t[j].getTrain_information()[i].changeTime( t1, t2);
}
cout<<"成功安排\n";
}
}
void AdminOp::arrangeStationTime()
{
cout<<"你想安排的站点名称为,输入E终止\n";
string name;
while(cin>>name)
{
if(name=="E")break;
int i=searchS(name);//找到s[i],某个站点,站点下有各个车次经过的时间,对其修改.
if(i<0)cout<<"没找到\n";
cout<<"基本信息为\n";
string number;
Time t1;
Time t2;
cin>>t1>>t2;
cin>>number;
int j=s[i].searchNumber(number);//站点里面找车次
s[i].getTrain_information()[j].changeTime( t1, t2);
cout<<"成功安排\n";
}
}
class ClientOp
{
vector<Station>s;
vector<Station>::iterator it1;
multimap<string,int>m1;
multimap<string,int>::iterator m1p;
multimap<Time,int>m3;
multimap<Time,int>::iterator m3p,m4p,m5p;
vector<Train_number>t;
vector<Train_number>::iterator it2 ;
multimap<string,int>m2;
multimap<string,int>::iterator m2p;
public:
ClientOp()
{
load1();
load2();
}
~ClientOp()
{
}
void load1();
void load2();
void save1();
void save2();
void searchBase();
void searchTimeBaseBegin();
void searchTimeBaseEnd();
void searchStation();
void searchTrain_number();
int searchS(string where);
int searchT(string number);
void displayTrain();
void displayStation();
};
void ClientOp::displayStation()
{
cout<<"This is all information about station\n";
for(it1=s.begin(); it1!=s.end(); it1++)
{
cout<<*it1;
}
}
void ClientOp::searchTimeBaseEnd()
{
cout<<"请输入出发到达站点\n";
string from;
string to;
cin>>from>>to;
int i=searchS(from);
int j=searchS(to);//找到两个站点s[i],s[j];
bool f=0;
cout<<"到达时间限定查询\n";//此时间后发出的车,相对于初始站
Time tt;
cin>>tt;
for(int k=0; k<s[j].getNum(); k++)
{
string l=s[j].search(k);
//依次找到各个车次的序号
int m=searchT(l);
//找到这个车次位置
int n=t[m].searchName(from);
//看这个车次里是否有这个站点;
if(n!=-1)
{
f=1;
if(t[m].getTimeB()<tt)
{
cout<<t[m]<<endl;
}
};//n!=-1说明已经找到
}
void ClientOp::searchTimeBaseBegin()
{
cout<<"请输入出发到达站点\n";
string from;
string to;
cin>>from>>to;
int i=searchS(from);
int j=searchS(to);//找到两个站点s[i],s[j];
bool f=0;
cout<<"发车时间限定查询\n";//此时间后发出的车,相对于初始站
Time tt;
cin>>tt;
for(int k=0; k<s[j].getNum(); k++)
{
string l=s[j].search(k);
//依次找到各个车次的序号
int m=searchT(l);
//找到这个车次位置
int n=t[m].searchName(from);
//看这个车次里是否有这个站点;
if(n!=-1)
{
f=1;
if(tt<t[m].getTimeB())
{
cout<<t[m]<<endl;
}
};//n!=-1说明已经找到
}
}
void ClientOp::searchBase()
{
cout<<"请输入起始站点\n";
string from;
string to;
bool f=0;
cin>>from>>to;
int i=searchS(from);
int j=searchS(to);//找到两个站点s[i],s[j];
for(int k=0; k<s[j].getNum(); k++)
{
string l=s[j].search(k);
//依次找到各个车次的序号
int m=searchT(l);
//找到这个车次位置
int n=t[m].searchName(from);
//看这个车次里是否有这个站点;
if(n!=-1)
{
f=1;
cout<<t[m]<<endl;
};//n!=-1说明已经找到
}
if(f==0)
{
cout<<"没找到,请输入1换乘,其它终止\n";
int n;
cin>>n;
if(n==1)
{
/*以天津南到苏州为例,天津南不可直接到达
但是可以到达济南西,从济南西可以直接到达苏州
所以可以换乘;先找这个站点所属车次继续找这个from的下一个站点,找这个站点所经过的车次,看这个车次是否经过from*/
for(int k=0; k<s[i].getNum(); k++)
{
string l=s[i].search(k);
//依次找到各个车次的序号
int m=searchT(l);
//找到这个车次位置
int n=t[m].searchName(from);
//看这个车次里是否有这个站点;
//返回该站点在车次的第几个位置
for(int q=n; q<t[m].getNum()-1; q++)
{
string o=t[m].getTrain_information()[q].getStation();//返回站点
int oo=searchS(o);//s[oo]
for(int h=0; h<s[oo].getNum(); h++)
{
string ll=s[oo].search(h);
//依次找到各个车次的序号
int mm=searchT(ll);
//找到这个车次位置
int nn=t[mm].searchName(to);
if(nn!=-1)
{
cout<<t[mm]<<"换乘成功!"<<endl;
}
}
}
}
/*找到到达的站点;
在这个站点里寻找车次,在所有车次里寻找开始的站点;
优于二重循环;*/
}
}
}
int ClientOp::searchS(string where)
{
m1p=m1.find(where);
if(m1p!=m1.end())
{
int i=m1p->second;
return i;
}
else return -1;
}
int ClientOp::searchT(string number)
{
m2p=m2.find(number);
if(m2p!=m2.end())
{
int i=m2p->second;
return i;
}
else return -1;
}
void ClientOp::searchStation()
{
cout<<"您想查询的站点为\n";
string where;
cin>>where;
if(searchS(where)==-1)
cout<<"没找到\n";
else
{
cout<<s[searchS(where)];
}
}
void ClientOp::searchTrain_number()
{
cout<<"您想查询的车次为\n";
string number;
cin>>number;
if(searchT(number)==-1)
cout<<"没找到\n";
else
{
cout<<t[searchT(number)];
}
}
void ClientOp::displayTrain()
{
cout<<"This is all information about train\n";
for(it2=t.begin(); it2!=t.end(); it2++)
{
cout<<*it2;
}
}
void ClientOp::load1()
{
int i;
Train_number tt;
ifstream infile("e:\\train.txt",ios::in);
if(!infile)
return;
t.clear();
i=0;
while(infile>>tt)
{
t.push_back(tt);
//cout<<tt;
m2.insert(make_pair(tt.getNumber(),i));
i++;
tt.deleteInformation();
}
infile.close();
}
void ClientOp::load2()
{
int i;
Station ss;
ifstream infile("e:\\station.txt",ios::in);
if(!infile)
return;
s.clear();
i=0;
while(infile>>ss)
{
s.push_back(ss);
//cout<<ss;
m1.insert(make_pair(ss.getName(),i));
i++;
ss.deleteInformation();
}
infile.close();
}
int main()
{
AdminOp a;
a.displayStation();
a.displayTrain();
//AdminOp b;
//b.addStation();
ClientOp c;
//c.searchTrain_number();
c.searchBase();
//c.searchStation();
//c.searchTimeBaseBegin();
//a.addTrain();
//a.addStation();
//a.deleteTrain();
// a.deleteStation();
// a.changeStationTime();
//a.arrangeTrainTime();
//a.arrangeStationTime();
return 0;
}
using namespace std;
class Time
{
int hour;
int minute;
public:
Time(int v,int m ):hour(v),minute(m) {}
Time()
{
hour=0;
minute=0;
}
int getHour()
{
return hour;
};
int getMinute()
{
return minute;
};
bool operator<(const Time&d)const
{
return hour!=d.hour?hour<d.hour:minute<d.minute;
}
friend ostream&operator<<(ostream &os, const Time &d);
friend istream&operator>>(istream &in, Time &d);
};
ostream&operator<<(ostream &os,const Time &d)
{
os<<d.hour<<" "<<d.minute;
return os;
}
istream&operator>>(istream &in,Time &d)
{
in>>d.hour;
in>>d.minute;
return in;
}
class Train_information
{
string Train_number;
string Station;
Time from;
Time to;
public:
Train_information(string Train_number,string Station,Time from,Time to)
{
this->Train_number=Train_number;
this->Station=Station;
this->from=from;
this->to=to;
}
Train_information() {}
friend ostream&operator<<(ostream &os,Train_information &T);
friend istream&operator>>(istream &in,Train_information &T);
string getTrain_number();
Time getTimeB();
Time getTimeE();
string getStation();
void changeTime(Time t1,Time t2);
};
string Train_information::getStation()
{
return Station;
};
Time Train_information::getTimeE()
{
return to;
}
Time Train_information::getTimeB()
{
return from;
};
string Train_information::getTrain_number()
{
return Train_number;
};
void Train_information::changeTime(Time t1,Time t2)
{
from=t1;
to=t2;
}
istream&operator>>(istream &in,Train_information &T)
{
in>>T.Train_number;
in>>T.Station;
in>>T.from;
in>>T.to;
return in;
}
ostream&operator<<(ostream &os,Train_information &T)
{
os<<T.Train_number<<" ";
os<<T.Station<<" ";
os<<T.from<<" ";
os<<T.to<<" ";
return os;
}
class Station
{
string name;
int num;
vector<Train_information>T;
multimap<string,int>k;
multimap<string,int>::iterator k1;
public:
Station(string name,int num)
{
this->name=name;
this->num=num;
k.clear();
T.clear();
}
Station()
{
num=0;
k.clear();
T.clear();
}
vector<Train_information>& getTrain_information()
{
return T;
};
friend ostream&operator<<(ostream &os,Station &s);
friend istream&operator>>(istream &in,Station &s);
int searchIf(string number);
int searchNumber(string number);
int getNum();
string getName();
string search(int i);
Train_information getT(int i);
void changeTime();
void deleteInformation();
void addTrain_information(Train_information t);
};
string Station::getName()
{
return name;
};
Train_information Station::getT(int i)
{
return T[i];
};
void Station::deleteInformation()
{
T.clear();
};
int Station::getNum()
{
return num;
};
void Station::addTrain_information(Train_information t)
{
num++;
T.push_back(t);
};
int Station::searchIf(string number)
{
return searchNumber(number)+1>0?searchNumber(number)+1:0;
}
int Station::searchNumber(string number)
{
k1=k.find(number);
if(k1!=k.end())
{
int H=k1->second;
cout<<"this "<<H<<endl;
return H;
}
return -1;
}
void Station::changeTime()
{
cout<<"请输入车号\n";
string number;
cin>>number;
int i=searchNumber(number);
cout<<"请输入时间\n";
Time t1,t2;
cin>>t1>>t2;
cout<<"修改成功\n";
cout<<T[i].getTimeB();
}
string Station::search(int i)
{
return T[i].getTrain_number();
}
istream&operator>>(istream &in,Station &s)
{
in>>s.name;
if(s.name=="E")return in;
in>>s.num;//这个站点被哪些车次经过
int j=-1;
for(int i=0; i<s.num; i++)
{
++j;
Train_information TT;
in>>TT;
s.T.push_back(TT);
s.k.insert(make_pair(TT.getTrain_number(),j));
}
return in;
}
ostream&operator<<(ostream &os,Station &s)
{
os<<s.name<<" ";
os<<s.num;
os<<endl;
for(int i=0; i<s.num; i++)
{
os<<s.T[i];
os<<endl;
}
return os;
}
class Train_number//车次
{
string number;
string from;
string to;
int num;
vector<Train_information>T;
multimap<string,int>m;
multimap<string,int>::iterator m1;
public:
Train_number(string number,string from,string to,int num)
{
this->number=number;
this->from=from;
this->to=to;
this->num=num;
}
Train_number()
{
num=0;
}
friend ostream&operator<<(ostream &os,Train_number &t);
friend istream&operator>>(istream &in,Train_number &t);
void deleteInformation()
{
T.clear();
};
void deleteInformation(string name)
{
m1=m.find(name);
int i=m1->second;
T.erase(i+T.begin());
}
int getNum()
{
return num;
};
void setNum(int i)
{
num=i;
};
string getNumber()
{
return number;
};
Time getTimeB()
{
return T[0].getTimeB();
};
Time getTimeE()
{
return T[T.size()].getTimeE();
}
void addTrain_information(Train_information t)
{
++num;
T.push_back(t);
};
vector<Train_information>& getTrain_information()
{
return T;
};
int searchName(string name);
};
int Train_number::searchName(string name)
{
m1=m.find(name);
int i;
if(m1!=m.end())
{
i=m1->second;
return i;
}
return -1;
}
istream&operator>>(istream &in,Train_number &t)
{
in>>t.number;
if(t.number=="E")return in;
in>>t.from;
in>>t.to;
in>>t.num;
int j=0;
for(int i=0; i<t.num; i++)
{
Train_information TT;
in>>TT;
t.T.push_back(TT);
t.m.insert(make_pair(TT.getStation(),j));
j++;
}
return in;
}
ostream&operator<<(ostream &os,Train_number &t)
{
os<<t.number<<" ";
os<<t.from<<" ";
os<<t.to<<" ";
os<<t.num;
os<<endl;
for(int i=0; i<t.num; i++)
{
os<<t.T[i];
os<<endl;
}
return os;
}
class AdminOp
{
vector<Station>s;
vector<Station>::iterator it1;
multimap<string,int>m1;
multimap<string,int>::iterator m1p;
multimap<Time,int>m3;
multimap<Time,int>::iterator m3p;
vector<Train_number>t;
vector<Train_number>::iterator it2 ;
multimap<string,int>m2;
multimap<string,int>::iterator m2p;
public:
AdminOp()
{
load1();
load2();
}
~AdminOp()
{
save1();
save2();
}
void load1();
void load2();
void save1();
void save2();
void addTrain();
void deleteTrain();
void addStation();
void deleteStation();
void displayTrain();
void displayStation();
void searchStation();
void searchTrain_number();
int searchS(string where);
int searchT(string number);
void changeStationTime();
//时间调度
void arrangeStationTime();
void arrangeTrainTime();
};
void AdminOp::load1()
{
int i;
Train_number tt;
ifstream infile("e:\\train.txt",ios::in);
if(!infile)
return;
t.clear();
i=0;
while(infile>>tt)
{
t.push_back(tt);
m2.insert(make_pair(tt.getNumber(),i));
i++;
tt.deleteInformation();
}
infile.close();
}
void AdminOp::load2()
{
int i;
Station ss;
ifstream infile("e:\\station.txt",ios::in);
if(!infile)
return;
s.clear();
i=0;
while(infile>>ss)
{
s.push_back(ss);
m1.insert(make_pair(ss.getName(),i));
i++;
ss.deleteInformation();
}
infile.close();
}
void AdminOp::save1()
{
ofstream outfile("e:\\train.txt",ios::out);
if(!outfile)
return;
for(it2=t.begin(); it2!=t.end(); it2++)
{
outfile<<*it2;
}
outfile.close();
}
void AdminOp::save2()
{
ofstream outfile("e:\\station.txt",ios::out);
if(!outfile)
return;
for(it1=s.begin(); it1!=s.end(); it1++)
{
outfile<<*it1;
}
outfile.close();
}
void AdminOp::searchStation()
{
cout<<"您想查询的站点为\n";
string where;
cin>>where;
if(searchT(where)==-1)
cout<<"没找到\n";
else
{
cout<<s[searchS(where)];
}
}
void AdminOp::searchTrain_number()
{
cout<<"您想查询的车次为\n";
string number;
cin>>number;
if(searchS(number)==-1)
cout<<"没找到\n";
else
{
cout<<t[searchS(number)];
}
}
int AdminOp::searchS(string where)
{
m1p=m1.find(where);
if(m1p!=m1.end())
{
int i=m1p->second;
return i;
}
else return -1;
}
int AdminOp::searchT(string number)
{
m2p=m2.find(number);
if(m2p!=m2.end())
{
int i=m2p->second;
return i;
}
else return -1;
}
void AdminOp::changeStationTime()//同时修改站点,车次时间
{
cout<<"您想修改哪个站点,输入E结束\n";
string name;
while(cin>>name)
{
if(name=="E")break;
int i=searchS(name);//找到s[i],某个站点,站点下有各个车次经过的时间,对其修改.
if(i<0)cout<<"没找到\n";
cout<<"输入修改的车次\n";
cout<<"第几个站点: "<<i<<endl;
string number;
cin>>number;
int j=searchT(number);
if(j<0)cout<<"没找到\n";
cout<<"第几班车:"<<j<<endl;
//找到t[j];
cout<<s[i];
int k;
k=s[i].searchNumber(number);
int l;
l=t[j].searchName(name);//地点查询
cout<<"该站点的第几个车: "<<k<<endl;
cout<<"该车次对的第几个站点: "<<l<<endl;;
if(k==-1||l==-1)
{
cout<<"没找到\n";
}
else
{
cout<<"请输入时间\n";
Time t1,t2;
cin>>t1>>t2;
s[i].getTrain_information()[k].changeTime( t1, t2);
t[j].getTrain_information()[l].changeTime( t1, t2);
cout<<"成功\n";
}
}
void AdminOp::addStation()
{
cout<<"你想增加的站点信息为,输入车站名称E结束\n";
while(1)
{
Station ss;
cin>>ss;
if(ss.getName()=="E")
{
break;
}
s.push_back(ss);
cout<<"添加成功\n";
}
}
void AdminOp::deleteStation()//删除站点的时候删除对应车次
{
cout<<"你想删除的站点信息为,输入车站名称E结束\n";
string name;
while(1)
{
cin>>name;
if(name=="E")break;
int i=searchS(name);//找到这个车站
it1=s.begin()+i;
cout<<"输入1修改对应车次\n";
int n;
cin>>n;
if(n==1)
{
for(int h=0; h<s[i].getNum(); h++)
{
string ll=s[i].search(h);
//依次找到各个车次的序号
int mm=searchT(ll);
//找到这个车次位置
//int nn=t[mm].searchName(name);
// t[mm].erase(nn);
t[mm].deleteInformation(name);
}
}
s.erase(it1);
cout<<"删除成功\n";
}
}
void AdminOp::addTrain()//增加车次的时候增加对应站点的车次
{
cout<<"你想增加的车次信息为,输入车次序号E结束\n";
while(1)
{
string number;
cout<<"输入车号: ";
cin>>number;
if(number=="E")break;
cout<<"输入起止站点: ";
string from;
string to;
cin>>from>>to;
cout<<"输入所经站点数: ";
Train_number tt(number,from,to,0);
int num;
cin>>num;
int k;
cout<<"输入站点信息\n";
for(int i=0; i<num; i++)
{
Train_information in;
cin>>in;
tt.addTrain_information(in);
k=searchS(in.getStation());
if(k==-1)
{
cout<<"此站点不存在,请添加\n";
}
else
{
//再判断这个车次是否已经存在于这个站点;
if(s[k].searchIf(in.getTrain_number())==0)
{
s[k].addTrain_information(in);
}
}
}
t.push_back(tt);
//在已有的站点再添加这个车次
} //可以同时添加站点
}
void AdminOp::deleteTrain()
{
cout<<"你想删除的车次为,输入车次序号E结束\n";
string number;
while(1)
{
cin>>number;
if(number=="E")break;
int i=searchT(number);
it2=t.begin()+i;
t.erase(it2);
cout<<"删除成功\n";
}
}
void AdminOp::displayTrain()
{
cout<<"This is all information about train\n";
for(it2=t.begin(); it2!=t.end(); it2++)
{
cout<<*it2;
}
}
void AdminOp::displayStation()
{
cout<<"This is all information about station\n";
for(it1=s.begin(); it1!=s.end(); it1++)
{
cout<<*it1;
}
}
void AdminOp::arrangeTrainTime()
{
cout<<"你想安排的车次名称为,输入E终止\n";
string number;
while(cin>>number)
{
if(number=="E")break;
int j=searchT(number);
if(j<0)cout<<"没找到\n";
cout<<"第几班车:"<<j<<endl;
//找到t[j];
cout<<"安排的站点起止时间依次为\n";
int num;
cin>>num;
for(int i=0; i<num; i++)
{
Time t1,t2;
cin>>t1>>t2;
t[j].getTrain_information()[i].changeTime( t1, t2);
}
cout<<"成功安排\n";
}
}
void AdminOp::arrangeStationTime()
{
cout<<"你想安排的站点名称为,输入E终止\n";
string name;
while(cin>>name)
{
if(name=="E")break;
int i=searchS(name);//找到s[i],某个站点,站点下有各个车次经过的时间,对其修改.
if(i<0)cout<<"没找到\n";
cout<<"基本信息条数及基本信息为\n";
int num;
cin>>num;
for(int j=0; j<num; j++)
{
string number;
Time t1;
Time t2;
cin>>number>>t1>>t2;
Train_information in(number,name,t1,t2);
s[i].addTrain_information(in);
cout<<"成功安排\n";
}
}
}
class ClientOp
{
vector<Station>s;
vector<Station>::iterator it1;
multimap<string,int>m1;
multimap<string,int>::iterator m1p;
multimap<Time,int>m3;
multimap<Time,int>::iterator m3p,m4p,m5p;
vector<Train_number>t;
vector<Train_number>::iterator it2 ;
multimap<string,int>m2;
multimap<string,int>::iterator m2p;
public:
ClientOp()
{
load1();
load2();
}
~ClientOp()
{
}
void load1();
void load2();
void save1();
void save2();
void searchBase();
void searchTimeBaseBegin();
void searchTimeBaseEnd();
void searchStation();
void searchTrain_number();
int searchS(string where);
int searchT(string number);
void displayTrain();
void displayStation();
};
void ClientOp::displayStation()
{
cout<<"This is all information about station\n";
for(it1=s.begin(); it1!=s.end(); it1++)
{
cout<<*it1;
}
}
void ClientOp::searchTimeBaseEnd()
{
cout<<"请输入出发到达站点\n";
string from;
string to;
cin>>from>>to;
int i=searchS(from);
int j=searchS(to);//找到两个站点s[i],s[j];
bool f=0;
cout<<"到达时间限定查询\n";//此时间后发出的车,相对于初始站
Time tt;
cin>>tt;
for(int k=0; k<s[j].getNum(); k++)
{
string l=s[j].search(k);
//依次找到各个车次的序号
int m=searchT(l);
//找到这个车次位置
int n=t[m].searchName(from);
//看这个车次里是否有这个站点;
if(n!=-1)
{
f=1;
if(t[m].getTimeB()<tt)
{
cout<<t[m]<<endl;
}
};//n!=-1说明已经找到
}
void ClientOp::searchTimeBaseBegin()
{
cout<<"请输入出发到达站点\n";
string from;
string to;
cin>>from>>to;
int i=searchS(from);
int j=searchS(to);//找到两个站点s[i],s[j];
bool f=0;
cout<<"发车时间限定查询\n";//此时间后发出的车,相对于初始站
Time tt;
cin>>tt;
for(int k=0; k<s[j].getNum(); k++)
{
string l=s[j].search(k);
//依次找到各个车次的序号
int m=searchT(l);
//找到这个车次位置
int n=t[m].searchName(from);
//看这个车次里是否有这个站点;
if(n!=-1)
{
f=1;
if(tt<t[m].getTimeB())
{
cout<<t[m]<<endl;
}
};//n!=-1说明已经找到
}
}
void ClientOp::searchBase()
{
cout<<"请输入起始站点\n";
string from;
string to;
bool f=0;
cin>>from>>to;
int i=searchS(from);
int j=searchS(to);//找到两个站点s[i],s[j];
for(int k=0; k<s[j].getNum(); k++)
{
string l=s[j].search(k);
//依次找到各个车次的序号
int m=searchT(l);
//找到这个车次位置
int n=t[m].searchName(from);
//看这个车次里是否有这个站点;
if(n!=-1)
{
f=1;
cout<<t[m]<<endl;
};//n!=-1说明已经找到
}
if(f==0)
{
cout<<"没找到,请输入1换乘,其它终止\n";
int n;
cin>>n;
if(n==1)
{
/*以天津南到苏州为例,天津南不可直接到达
但是可以到达济南西,从济南西可以直接到达苏州
所以可以换乘;先找这个站点所属车次继续找这个from的下一个站点,找这个站点所经过的车次,看这个车次是否经过from*/
for(int k=0; k<s[i].getNum(); k++)
{
string l=s[i].search(k);
//依次找到各个车次的序号
int m=searchT(l);
//找到这个车次位置
int n=t[m].searchName(from);
//看这个车次里是否有这个站点;
//返回该站点在车次的第几个位置
for(int q=n; q<t[m].getNum()-1; q++)
{
string o=t[m].getTrain_information()[q].getStation();//返回站点
int oo=searchS(o);//s[oo]
for(int h=0; h<s[oo].getNum(); h++)
{
string ll=s[oo].search(h);
//依次找到各个车次的序号
int mm=searchT(ll);
//找到这个车次位置
int nn=t[mm].searchName(to);
if(nn!=-1)
{
cout<<t[mm]<<"换乘成功!"<<endl;
}
}
}
}
/*找到到达的站点;
在这个站点里寻找车次,在所有车次里寻找开始的站点;
优于二重循环;*/
}
}
}
int ClientOp::searchS(string where)
{
m1p=m1.find(where);
if(m1p!=m1.end())
{
int i=m1p->second;
return i;
}
else return -1;
}
int ClientOp::searchT(string number)
{
m2p=m2.find(number);
if(m2p!=m2.end())
{
int i=m2p->second;
return i;
}
else return -1;
}
void ClientOp::searchStation()
{
cout<<"您想查询的站点为\n";
string where;
cin>>where;
if(searchS(where)==-1)
cout<<"没找到\n";
else
{
cout<<s[searchS(where)];
}
}
void ClientOp::searchTrain_number()
{
cout<<"您想查询的车次为\n";
string number;
cin>>number;
if(searchT(number)==-1)
cout<<"没找到\n";
else
{
cout<<t[searchT(number)];
}
}
void ClientOp::displayTrain()
{
cout<<"This is all information about train\n";
for(it2=t.begin(); it2!=t.end(); it2++)
{
cout<<*it2;
}
}
void ClientOp::load1()
{
int i;
Train_number tt;
ifstream infile("e:\\train.txt",ios::in);
if(!infile)
return;
t.clear();
i=0;
while(infile>>tt)
{
t.push_back(tt);
cout<<tt;
m2.insert(make_pair(tt.getNumber(),i));
i++;
tt.deleteInformation();
}
infile.close();
}
void ClientOp::load2()
{
int i;
Station ss;
ifstream infile("e:\\station.txt",ios::in);
if(!infile)
return;
s.clear();
i=0;
while(infile>>ss)
{
s.push_back(ss);
cout<<ss;
m1.insert(make_pair(ss.getName(),i));
i++;
ss.deleteInformation();
}
infile.close();
}
int main()
{
AdminOp a;
a.displayStation();
a.displayTrain();
//AdminOp b;
//b.addStation();
//ClientOp c;
// c.searchTrain_number();
//c.searchBase();
// c.searchStation();
//c.searchTimeBaseBegin();
//a.addTrain();
//a.addStation();
//a.deleteTrain();
// b.deleteStation();
a.changeStationTime();
//a.arrangeTrainTime();
return 0;
}
using namespace std;
class Time
{
int hour;
int minute;
public:
Time(int v,int m ):hour(v),minute(m) {}
Time()
{
hour=0;
minute=0;
}
int getHour()
{
return hour;
};
int getMinute()
{
return minute;
};
bool operator<(const Time&d)const
{
return hour!=d.hour?hour<d.hour:minute<d.minute;
}
friend ostream&operator<<(ostream &os, const Time &d);
friend istream&operator>>(istream &in, Time &d);
};
ostream&operator<<(ostream &os,const Time &d)
{
os<<d.hour<<" "<<d.minute;
return os;
}
istream&operator>>(istream &in,Time &d)
{
in>>d.hour;
in>>d.minute;
return in;
}
class Train_information
{
string Train_number;
string Station;
Time from;
Time to;
public:
friend ostream&operator<<(ostream &os,Train_information &T);
friend istream&operator>>(istream &in,Train_information &T);
string getTrain_number()
{
return Train_number;
};
Time getTimeB()
{
return from;
};
Time getTimeE()
{
return to;
}
string getStation()
{
return Station;
};
void changeTime(Time t1,Time t2);
};
void Train_information::changeTime(Time t1,Time t2)
{
from=t1;
to=t2;
}
istream&operator>>(istream &in,Train_information &T)
{
in>>T.Train_number;
in>>T.Station;
in>>T.from;
in>>T.to;
return in;
}
ostream&operator<<(ostream &os,Train_information &T)
{
os<<T.Train_number<<" ";
os<<T.Station<<" ";
os<<T.from<<" ";
os<<T.to<<" ";
return os;
}
class Station
{
string name;
int num;//数目
vector<Train_information>T;
public:
Station()
{
num=0;
}
vector<Train_information>& getTrain_information()
{
return T;
};
friend ostream&operator<<(ostream &os,Station &s);
friend istream&operator>>(istream &in,Station &s);
void deleteInformation()
{
T.clear();
};
int searchIf(string number);
Train_information getT(int i)
{
return T[i];
};
string getName()
{
return name;
};
string search(int i);
int searchNumber(string number);
int getNum()
{
return num;
};
Time search(Time t) {}
void changeTime();//按车次序号查找列车并修改对应时间
void addTrain_information(Train_information t)
{
++num;
T.push_back(t);
};
};
int Station::searchIf(string number)
{
return searchNumber(number)+1>0?searchNumber(number)+1:0;
}
int Station::searchNumber(string number)
{
for(int i=0; i<T.size(); i++)
{
if(T[i].getTrain_number()==number)
{
return i;
break;
}
}
return -1;
}
void Station::changeTime()
{
cout<<"请输入车号\n";
string number;
cin>>number;
int i=searchNumber(number);
cout<<"请输入时间\n";
Time t1,t2;
cin>>t1>>t2;
//T[i].changeTime(t1,t2);
cout<<"修改成功\n";
cout<<T[i].getTimeB();
}
string Station::search(int i)
{
return T[i].getTrain_number();
}
istream&operator>>(istream &in,Station &s)
{
in>>s.name;
if(s.name=="E")return in;
in>>s.num;//这个站点被哪些车次经过
for(int i=0; i<s.num; i++)
{
Train_information TT;
in>>TT;
s.T.push_back(TT);
}
return in;
}
ostream&operator<<(ostream &os,Station &s)
{
os<<s.name<<" ";
os<<s.num;
os<<endl;
for(int i=0; i<s.num; i++)
{
os<<s.T[i];
os<<endl;
}
return os;
}
class Train_number//车次
{
string number;
string from;
string to;
int num;//站点数量
vector<Train_information>T;
public:
Train_number(string number,string from,string to,int num)
{
this->number=number;
this->from=from;
this->to=to;
this->num=num;
}
Train_number()
{
num=0;
}
friend ostream&operator<<(ostream &os,Train_number &t);
friend istream&operator>>(istream &in,Train_number &t);
void deleteInformation()
{
T.clear();
};
void setNum(int i)
{
num=i;
};
string getNumber()
{
return number;
};
Time getTimeB()
{
return T[0].getTimeB();
};
Time getTimeE()
{
return T[T.size()].getTimeE();
}
void addTrain_information(Train_information t)
{
++num;
T.push_back(t);
};
vector<Train_information>& getTrain_information()
{
return T;
};
int searchName(string name);
};
int Train_number::searchName(string name)
{
for(int i=0; i<T.size(); i++)
{
if(T[i].getStation()==name)
{
return i;
break;
}
}
return -1;///
}
istream&operator>>(istream &in,Train_number &t)
{
in>>t.number;
if(t.number=="E")return in;
in>>t.from;
in>>t.to;
in>>t.num;
for(int i=0; i<t.num; i++)
{
Train_information TT;
in>>TT;
t.T.push_back(TT);
}
return in;
}
ostream&operator<<(ostream &os,Train_number &t)
{
os<<t.number<<" ";
os<<t.from<<" ";
os<<t.to<<" ";
os<<t.num;
os<<endl;
for(int i=0; i<t.num; i++)
{
os<<t.T[i];
os<<endl;
}
return os;
}
class AdminOp
{
vector<Station>s;
vector<Station>::iterator it1;
multimap<string,int>m1;
multimap<string,int>::iterator m1p;
multimap<Time,int>m3;
multimap<Time,int>::iterator m3p;
vector<Train_number>t;
vector<Train_number>::iterator it2 ;
multimap<string,int>m2;
multimap<string,int>::iterator m2p;
public:
AdminOp()
{
load1();
load2();
}
~AdminOp()
{
save1();
save2();
}
void load1();
void load2();
void save1();
void save2();
void displayTrain();
void displayStation();
void searchStation();
void searchTrain_number();
int searchS(string where);
int searchT(string number);
void addTrain();//增加车次
void deleteTrain();//删除车次
void addStation();//增加站点
void deleteStation();//删除站点
void changeStationTime();
};
void AdminOp::changeStationTime()/?????
{
cout<<"您想修改哪个站点,输入E结束\n";
string name;
while(cin>>name)
{
if(name=="E")break;
int i=searchS(name);//找到s[i],某个站点,站点下有各个车次经过的时间,对其修改.
cout<<"输入修改的车次\n";
cout<<"第几个站点: "<<i<<endl;
string number;
cin>>number;
int j=searchT(number);
cout<<"第几班车:"<<j<<endl;
//找到t[j];
cout<<s[i];
int k=s[i].searchNumber(number);
int l=t[j].searchName(name);//安地点查询""""""""
cout<<"该站点的第几个车: "<<k<<endl;
cout<<"该车次对的第几个站点: "<<l<<endl;;
if(k==-1||l==-1)
{
cout<<"没找到\n";
}
else
{
cout<<"请输入时间\n";
Time t1,t2;
cin>>t1>>t2;
s[i].getTrain_information()[k].changeTime( t1, t2);
t[j].getTrain_information()[l].changeTime( t1, t2);
}
//s[i].changeTime();
//s[i].changeTime(number,t1,t2);
//cout<<s[i];
//int k=s[i].searchNumber(number);
//s[i].getT(s[i].searchNumber(number)).changeTime(t1,t2);
}
}
void AdminOp::searchStation()
{
cout<<"您想查询的站点为\n";
string where;
cin>>where;
if(searchT(where)==-1)
cout<<"没找到\n";
else
{
cout<<s[searchS(where)];
}
}
void AdminOp::searchTrain_number()
{
cout<<"您想查询的车次为\n";
string number;
cin>>number;
if(searchS(number)==-1)
cout<<"没找到\n";
else
{
cout<<t[searchS(number)];
}
}
int AdminOp::searchS(string where)
{
m1p=m1.find(where);
if(m1p!=m1.end())
{
int i=m1p->second;
return i;
}
else return -1;
}
int AdminOp::searchT(string number)
{
m2p=m2.find(number);
if(m2p!=m2.end())
{
int i=m2p->second;
return i;
}
else return -1;
}
void AdminOp::addStation()
{
cout<<"你想增加的站点信息为,输入车站名称E结束\n";
while(1)
{
Station ss;
cin>>ss;
if(ss.getName()=="E")
{
break;
}
s.push_back(ss);
cout<<"添加成功\n";
}//后来要改
}
void AdminOp::deleteStation()
{
cout<<"你想删除的站点信息为,输入车站名称E结束\n";
string name;
while(1)
{
cin>>name;
if(name=="E")break;
int i=searchS(name);
it1=s.begin()+i;
s.erase(it1);
cout<<"删除成功\n";
}
}
void AdminOp::addTrain()
{
cout<<"你想增加的车次信息为,输入车次序号E结束\n";
while(1)
{
string number;
cout<<"输入车号: ";
cin>>number;
if(number=="E")break;
cout<<"输入起止站点: ";
string from;
string to;
cin>>from>>to;
cout<<"输入所经站点数: ";
Train_number tt(number,from,to,0);
int num;
cin>>num;
int k;
cout<<"输入站点信息\n";
for(int i=0; i<num; i++)
{
Train_information in;
cin>>in;
tt.addTrain_information(in);
k=searchS(in.getStation());
if(k==-1)
{
cout<<"此站点不存在,请添加\n";
}
else
{
//再判断这个车次是否已经存在于这个站点;
if(s[k].searchIf(in.getTrain_number())==0)
{
s[k].addTrain_information(in);
}
}
}
t.push_back(tt);
//在已有的站点再添加这个车次
} //可以同时添加站点
}
void AdminOp::deleteTrain()
{
cout<<"你想删除的车次为,输入车次序号E结束\n";
string number;
while(1)
{
cin>>number;
if(number=="E")break;
int i=searchT(number);
it2=t.begin()+i;
t.erase(it2);
cout<<"删除成功\n";
}
}
void AdminOp::displayTrain()
{
cout<<"This is all information about train\n";
for(it2=t.begin(); it2!=t.end(); it2++)
{
cout<<*it2;
}
}
void AdminOp::displayStation()
{
cout<<"This is all information about station\n";
for(it1=s.begin(); it1!=s.end(); it1++)
{
cout<<*it1;
}
}
void AdminOp::load1()
{
int i;
Train_number tt;
ifstream infile("e:\\train.txt",ios::in);
if(!infile)
return;
t.clear();
i=0;
while(infile>>tt)
{
t.push_back(tt);
//cout<<tt;
m2.insert(make_pair(tt.getNumber(),i));
i++;
tt.deleteInformation();
}
infile.close();
}
void AdminOp::load2()
{
int i;
Station ss;
ifstream infile("e:\\station.txt",ios::in);
if(!infile)
return;
s.clear();
i=0;
while(infile>>ss)
{
s.push_back(ss);
//cout<<ss;
m1.insert(make_pair(ss.getName(),i));
i++;
ss.deleteInformation();
}
infile.close();
}
void AdminOp::save1()
{
ofstream outfile("e:\\train.txt",ios::out);
if(!outfile)
return;
for(it2=t.begin(); it2!=t.end(); it2++)
{
outfile<<*it2;
}
outfile.close();
}
void AdminOp::save2()
{
ofstream outfile("e:\\station.txt",ios::out);
if(!outfile)
return;
for(it1=s.begin(); it1!=s.end(); it1++)
{
outfile<<*it1;
}
outfile.close();
}
class ClientOp
{
vector<Station>s;
vector<Station>::iterator it1;
multimap<string,int>m1;
multimap<string,int>::iterator m1p;
multimap<Time,int>m3;
multimap<Time,int>::iterator m3p,m4p,m5p;
vector<Train_number>t;
vector<Train_number>::iterator it2 ;
multimap<string,int>m2;
multimap<string,int>::iterator m2p;
public:
ClientOp()
{
load1();
load2();
}
~ClientOp()
{
//save1();
//save2();
}
void load1();
void load2();
void save1();
void save2();
void searchBase();
void searchTimeBase();
void searchStation();
void searchTrain_number();
int searchS(string where);
int searchT(string number);
void display();
};
void ClientOp::searchTimeBase()
{
cout<<"请输入起始站点\n";
string from;
string to;
cin>>from>>to;
int i=searchS(from);
int j=searchS(to);//找到两个站点s[i],s[j];
cout<<"请输入:1.发车时间限定查询;2.目的地到达时间限定查询\n";
int n;
cin>>n;
if(n==1)
{
cout<<"发车时间限定查询\n";//此时间后发出的车
Time tt;
cin>>tt;
for(int k=0; k<s[i].getNum()&&k<s[j].getNum(); k++)
{
for(int l=0; l<s[i].getNum()&&l<s[j].getNum(); l++)
{
if(s[i].search(k)==s[j].search(l))
{
int m=searchT(s[i].search(k));
if(tt<t[m].getTimeB())
{
cout<<t[m]<<endl;
}
}
}
}
}
else
{
cout<<"目的地到达时间限定查询\n";//此时间前到达的车
Time tt;
cin>>tt;
for(int k=0; k<s[i].getNum()&&k<s[j].getNum(); k++)
{
for(int l=0; l<s[i].getNum()&&l<s[j].getNum(); l++)
{
if(s[i].search(k)==s[j].search(l))
{
int m=searchT(s[i].search(k));
if(t[m].getTimeE()<tt)
{
cout<<t[m]<<endl;
}
}
}
}
}
}
void ClientOp::searchBase()
{
cout<<"请输入起始站点\n";
string from;
string to;
cin>>from>>to;
int i=searchS(from);
int j=searchS(to);//找到两个站点s[i],s[j];
for(int k=0; k<s[i].getNum()&&k<s[j].getNum(); k++)
{
for(int l=0; l<s[i].getNum()&&l<s[j].getNum(); l++)
{
if(s[i].search(k)==s[j].search(l))
{
int m=searchT(s[i].search(k));
cout<<t[m]<<endl;
}
}
}
}
int ClientOp::searchS(string where)
{
m1p=m1.find(where);
if(m1p!=m1.end())
{
int i=m1p->second;
return i;
}
else return -1;
}
int ClientOp::searchT(string number)
{
m2p=m2.find(number);
if(m2p!=m2.end())
{
int i=m2p->second;
return i;
}
else return -1;
}
void ClientOp::searchStation()
{
cout<<"您想查询的站点为\n";
string where;
cin>>where;
if(searchT(where)==-1)
cout<<"没找到\n";
else
{
cout<<s[searchS(where)];
}
}
void ClientOp::searchTrain_number()
{
cout<<"您想查询的车次为\n";
string number;
cin>>number;
if(searchS(number)==-1)
cout<<"没找到\n";
else
{
cout<<t[searchS(number)];
}
}
void ClientOp::display()
{
for(it2=t.begin(); it2!=t.end(); it2++)
{
cout<<*it2;
}
}
void ClientOp::load1()
{
int i;
Train_number tt;
ifstream infile("e:\\train.txt",ios::in);
if(!infile)
return;
t.clear();
i=0;
while(infile>>tt)
{
t.push_back(tt);
cout<<tt;
m2.insert(make_pair(tt.getNumber(),i));
i++;
tt.deleteInformation();
}
infile.close();
}
void ClientOp::load2()
{
int i;
Station ss;
ifstream infile("e:\\station.txt",ios::in);
if(!infile)
return;
s.clear();
i=0;
while(infile>>ss)
{
s.push_back(ss);
cout<<ss;
m1.insert(make_pair(ss.getName(),i));
i++;
ss.deleteInformation();
}
infile.close();
}
void ClientOp::save1()
{
ofstream outfile("e:\\train.txt",ios::out);
if(!outfile)
return;
for(it2=t.begin(); it2!=t.end(); it2++)
{
outfile<<*it2;
}
outfile.close();
}
void ClientOp::save2()
{
ofstream outfile("e:\\station.txt",ios::out);
if(!outfile)
return;
for(it1=s.begin(); it1!=s.end(); it1++)
{
outfile<<*it1;
}
outfile.close();
}
int main()
{
//ClientOp c;
//c.searchStation();
//c.searchTimeBase();
AdminOp a;
a.displayStation();
a.displayTrain();
//a.addTrain();
//a.addStation();
//a.deleteTrain();
//a.deleteStation();
a.changeStationTime();
}
using namespace std;
class Time
{
int hour;
int minute;
public:
Time(int v,int m ):hour(v),minute(m) {}
Time()
{
hour=0;
minute=0;
}
int getHour()
{
return hour;
};
int getMinute()
{
return minute;
};
bool operator<(const Time&d)const
{
return hour!=d.hour?hour<d.hour:minute<d.minute;
}
friend ostream&operator<<(ostream &os, const Time &d);
friend istream&operator>>(istream &in, Time &d);
};
ostream&operator<<(ostream &os,const Time &d)
{
os<<d.hour<<" "<<d.minute;
return os;
}
istream&operator>>(istream &in,Time &d)
{
in>>d.hour;
in>>d.minute;
return in;
}
class Train_information
{
string Train_number;
string Station;
Time from;
Time to;
public:
friend ostream&operator<<(ostream &os,Train_information &T);
friend istream&operator>>(istream &in,Train_information &T);
string getTrain_number()
{
return Train_number;
};
Time getTimeB()
{
return from;
};
Time getTimeE()
{
return to;
}
string getStation()
{
return Station;
};
void changeTime(Time t1,Time t2);
};
void Train_information::changeTime(Time t1,Time t2)
{
from=t1;
to=t2;
}
istream&operator>>(istream &in,Train_information &T)
{
in>>T.Train_number;
in>>T.Station;
in>>T.from;
in>>T.to;
return in;
}
ostream&operator<<(ostream &os,Train_information &T)
{
os<<T.Train_number<<" ";
os<<T.Station<<" ";
os<<T.from<<" ";
os<<T.to<<" ";
return os;
}
class Station
{
string name;
int num;//数目
vector<Train_information>T;
public:
Station()
{
num=0;
}
vector<Train_information>& getTrain_information()
{
return T;
};
friend ostream&operator<<(ostream &os,Station &s);
friend istream&operator>>(istream &in,Station &s);
void deleteInformation()
{
T.clear();
};
Train_information getT(int i)
{
return T[i];
};
string getName()
{
return name;
};
string search(int i);
int searchNumber(string number);
int getNum()
{
return num;
};
Time search(Time t) {}
void changeTime();//按车次序号查找列车并修改对应时间
void addTrain_information(Train_information t)
{
++num;
T.push_back(t);
};
};
int Station::searchNumber(string number)
{
for(int i=0; i<T.size(); i++)
{
if(T[i].getTrain_number()==number)
{
return i;
break;
}
}
}
void Station::changeTime()
{
cout<<"请输入车号\n";
string number;
cin>>number;
int i=searchNumber(number);
cout<<"请输入时间\n";
Time t1,t2;
cin>>t1>>t2;
//T[i].changeTime(t1,t2);
cout<<"修改成功\n";
cout<<T[i].getTimeB();
}
string Station::search(int i)
{
return T[i].getTrain_number();
}
istream&operator>>(istream &in,Station &s)
{
in>>s.name;
if(s.name=="E")return in;
in>>s.num;//这个站点被哪些车次经过
for(int i=0; i<s.num; i++)
{
Train_information TT;
in>>TT;
s.T.push_back(TT);
}
return in;
}
ostream&operator<<(ostream &os,Station &s)
{
os<<s.name<<" ";
os<<s.num;
os<<endl;
for(int i=0; i<s.num; i++)
{
os<<s.T[i];
os<<endl;
}
return os;
}
class Train_number//车次
{
string number;
string from;
string to;
int num;//站点数量
vector<Train_information>T;
public:
Train_number(string number,string from,string to,int num)
{
this->number=number;
this->from=from;
this->to=to;
this->num=num;
}
Train_number()
{
num=0;
}
friend ostream&operator<<(ostream &os,Train_number &t);
friend istream&operator>>(istream &in,Train_number &t);
void deleteInformation()
{
T.clear();
};
void setNum(int i)
{
num=i;
};
string getNumber()
{
return number;
};
Time getTimeB()
{
return T[0].getTimeB();
};
Time getTimeE()
{
return T[T.size()].getTimeE();
}
void addTrain_information(Train_information t)
{
++num;
T.push_back(t);
};
vector<Train_information>& getTrain_information()
{
return T;
};
int searchNumber(string number);
};
int Train_number::searchNumber(string number)
{
for(int i=0; i<T.size(); i++)
{
if(T[i].getTrain_number()==number)
{
return i;
break;
}
}
}
istream&operator>>(istream &in,Train_number &t)
{
in>>t.number;
if(t.number=="E")return in;
in>>t.from;
in>>t.to;
in>>t.num;
for(int i=0; i<t.num; i++)
{
Train_information TT;
in>>TT;
t.T.push_back(TT);
}
return in;
}
ostream&operator<<(ostream &os,Train_number &t)
{
os<<t.number<<" ";
os<<t.from<<" ";
os<<t.to<<" ";
os<<t.num;
os<<endl;
for(int i=0; i<t.num; i++)
{
os<<t.T[i];
os<<endl;
}
return os;
}
class AdminOp
{
vector<Station>s;
vector<Station>::iterator it1;
multimap<string,int>m1;
multimap<string,int>::iterator m1p;
multimap<Time,int>m3;
multimap<Time,int>::iterator m3p;
vector<Train_number>t;
vector<Train_number>::iterator it2 ;
multimap<string,int>m2;
multimap<string,int>::iterator m2p;
public:
AdminOp()
{
load1();
load2();
}
~AdminOp()
{
save1();
save2();
}
void load1();
void load2();
void save1();
void save2();
void displayTrain();
void displayStation();
void searchStation();
void searchTrain_number();
int searchS(string where);
int searchT(string number);
void addTrain();//增加车次
void deleteTrain();//删除车次
void addStation();//增加站点
void deleteStation();//删除站点
void changeStationTime();
};
void AdminOp::changeStationTime()/?????
{
cout<<"您想修改哪个站点,输入E结束\n";
string name;
while(cin>>name)
{
if(name=="E")break;
int i=searchS(name);//找到s[i],某个站点,站点下有各个车次经过的时间,对其修改.
cout<<"输入修改的车次\n";
cout<<"第几个站点: "<<i<<endl;
string number;
cin>>number;
int j=searchT(number);
cout<<"第几班车:"<<j<<endl;
//找到t[j];
cout<<s[i];
int k=s[i].searchNumber(number);
int l=t[j].searchNumber(number);//安地点查询""""""""
cout<<k<<" "<<l;
if(k==-1||l==-1)
{
cout<<"没找到\n";
}
else
{
cout<<"请输入时间\n";
Time t1,t2;
cin>>t1>>t2;
s[i].getTrain_information()[k-1].changeTime( t1, t2);
t[j].getTrain_information()[l].changeTime( t1, t2);
}
//s[i].changeTime();
//s[i].changeTime(number,t1,t2);
//cout<<s[i];
//int k=s[i].searchNumber(number);
//s[i].getT(s[i].searchNumber(number)).changeTime(t1,t2);
}
}
void AdminOp::searchStation()
{
cout<<"您想查询的站点为\n";
string where;
cin>>where;
if(searchT(where)==-1)
cout<<"没找到\n";
else
{
cout<<s[searchS(where)];
}
}
void AdminOp::searchTrain_number()
{
cout<<"您想查询的车次为\n";
string number;
cin>>number;
if(searchS(number)==-1)
cout<<"没找到\n";
else
{
cout<<t[searchS(number)];
}
}
int AdminOp::searchS(string where)
{
m1p=m1.find(where);
if(m1p!=m1.end())
{
int i=m1p->second;
return i;
}
else return -1;
}
int AdminOp::searchT(string number)
{
m2p=m2.find(number);
if(m2p!=m2.end())
{
int i=m2p->second;
return i;
}
else return -1;
}
void AdminOp::addStation()
{
cout<<"你想增加的站点信息为,输入车站名称E结束\n";
while(1)
{
Station ss;
cin>>ss;
if(ss.getName()=="E")
{
break;
}
s.push_back(ss);
cout<<"添加成功\n";
}//后来要改
}
void AdminOp::deleteStation()
{
cout<<"你想删除的站点信息为,输入车站名称E结束\n";
string name;
while(1)
{
cin>>name;
if(name=="E")break;
int i=searchS(name);
it1=s.begin()+i;
s.erase(it1);
cout<<"删除成功\n";
}
}
void AdminOp::addTrain()
{
cout<<"你想增加的车次信息为,输入车次序号E结束\n";
while(1)
{
string number;
cout<<"输入车号: ";
cin>>number;
if(number=="E")break;
cout<<"输入起止站点: ";
string from;
string to;
cin>>from>>to;
cout<<"输入所经站点数: ";
Train_number tt(number,from,to,0);
int num;
cin>>num;
int k;
cout<<"输入站点信息\n";
for(int i=0; i<num; i++)
{
Train_information in;
cin>>in;
tt.addTrain_information(in);
k=searchS(in.getStation());
if(k==-1)
{
cout<<"此站点不存在\n";
}
else
{
s[k].addTrain_information(in);
}
t.push_back(tt);
//在已有的站点再添加这个车次
} //可以同时添加站点
}
void AdminOp::deleteTrain()
{
cout<<"你想删除的车次为,输入车次序号E结束\n";
string number;
while(1)
{
cin>>number;
if(number=="E")break;
int i=searchT(number);
it2=t.begin()+i;
t.erase(it2);
cout<<"删除成功\n";
}
}
void AdminOp::displayTrain()
{
cout<<"This is all information about train\n";
for(it2=t.begin(); it2!=t.end(); it2++)
{
cout<<*it2;
}
}
void AdminOp::displayStation()
{
cout<<"This is all information about station\n";
for(it1=s.begin(); it1!=s.end(); it1++)
{
cout<<*it1;
}
}
void AdminOp::load1()
{
int i;
Train_number tt;
ifstream infile("e:\\train.txt",ios::in);
if(!infile)
return;
t.clear();
i=0;
while(infile>>tt)
{
t.push_back(tt);
//cout<<tt;
m2.insert(make_pair(tt.getNumber(),i));
i++;
tt.deleteInformation();
}
infile.close();
}
void AdminOp::load2()
{
int i;
Station ss;
ifstream infile("e:\\station.txt",ios::in);
if(!infile)
return;
s.clear();
i=0;
while(infile>>ss)
{
s.push_back(ss);
//cout<<ss;
m1.insert(make_pair(ss.getName(),i));
i++;
ss.deleteInformation();
}
infile.close();
}
void AdminOp::save1()
{
ofstream outfile("e:\\train.txt",ios::out);
if(!outfile)
return;
for(it2=t.begin(); it2!=t.end(); it2++)
{
outfile<<*it2;
}
outfile.close();
}
void AdminOp::save2()
{
ofstream outfile("e:\\station.txt",ios::out);
if(!outfile)
return;
for(it1=s.begin(); it1!=s.end(); it1++)
{
outfile<<*it1;
}
outfile.close();
}
class ClientOp
{
vector<Station>s;
vector<Station>::iterator it1;
multimap<string,int>m1;
multimap<string,int>::iterator m1p;
multimap<Time,int>m3;
multimap<Time,int>::iterator m3p,m4p,m5p;
vector<Train_number>t;
vector<Train_number>::iterator it2 ;
multimap<string,int>m2;
multimap<string,int>::iterator m2p;
public:
ClientOp()
{
load1();
load2();
}
~ClientOp()
{
//save1();
//save2();
}
void load1();
void load2();
void save1();
void save2();
void searchBase();
void searchTimeBase();
void searchStation();
void searchTrain_number();
int searchS(string where);
int searchT(string number);
void display();
};
void ClientOp::searchTimeBase()
{
cout<<"请输入起始站点\n";
string from;
string to;
cin>>from>>to;
int i=searchS(from);
int j=searchS(to);//找到两个站点s[i],s[j];
cout<<"请输入:1.发车时间限定查询;2.目的地到达时间限定查询\n";
int n;
cin>>n;
if(n==1)
{
cout<<"发车时间限定查询\n";//此时间后发出的车
Time tt;
cin>>tt;
for(int k=0; k<s[i].getNum()&&k<s[j].getNum(); k++)
{
for(int l=0; l<s[i].getNum()&&l<s[j].getNum(); l++)
{
if(s[i].search(k)==s[j].search(l))
{
int m=searchT(s[i].search(k));
if(tt<t[m].getTimeB())
{
cout<<t[m]<<endl;
}
}
}
}
}
else
{
cout<<"目的地到达时间限定查询\n";//此时间前到达的车
Time tt;
cin>>tt;
for(int k=0; k<s[i].getNum()&&k<s[j].getNum(); k++)
{
for(int l=0; l<s[i].getNum()&&l<s[j].getNum(); l++)
{
if(s[i].search(k)==s[j].search(l))
{
int m=searchT(s[i].search(k));
if(t[m].getTimeE()<tt)
{
cout<<t[m]<<endl;
}
}
}
}
}
}
void ClientOp::searchBase()
{
cout<<"请输入起始站点\n";
string from;
string to;
cin>>from>>to;
int i=searchS(from);
int j=searchS(to);//找到两个站点s[i],s[j];
for(int k=0; k<s[i].getNum()&&k<s[j].getNum(); k++)
{
for(int l=0; l<s[i].getNum()&&l<s[j].getNum(); l++)
{
if(s[i].search(k)==s[j].search(l))
{
int m=searchT(s[i].search(k));
cout<<t[m]<<endl;
}
}
}
}
int ClientOp::searchS(string where)
{
m1p=m1.find(where);
if(m1p!=m1.end())
{
int i=m1p->second;
return i;
}
else return -1;
}
int ClientOp::searchT(string number)
{
m2p=m2.find(number);
if(m2p!=m2.end())
{
int i=m2p->second;
return i;
}
else return -1;
}
void ClientOp::searchStation()
{
cout<<"您想查询的站点为\n";
string where;
cin>>where;
if(searchT(where)==-1)
cout<<"没找到\n";
else
{
cout<<s[searchS(where)];
}
}
void ClientOp::searchTrain_number()
{
cout<<"您想查询的车次为\n";
string number;
cin>>number;
if(searchS(number)==-1)
cout<<"没找到\n";
else
{
cout<<t[searchS(number)];
}
}
void ClientOp::display()
{
for(it2=t.begin(); it2!=t.end(); it2++)
{
cout<<*it2;
}
}
void ClientOp::load1()
{
int i;
Train_number tt;
ifstream infile("e:\\train.txt",ios::in);
if(!infile)
return;
t.clear();
i=0;
while(infile>>tt)
{
t.push_back(tt);
cout<<tt;
m2.insert(make_pair(tt.getNumber(),i));
i++;
tt.deleteInformation();
}
infile.close();
}
void ClientOp::load2()
{
int i;
Station ss;
ifstream infile("e:\\station.txt",ios::in);
if(!infile)
return;
s.clear();
i=0;
while(infile>>ss)
{
s.push_back(ss);
cout<<ss;
m1.insert(make_pair(ss.getName(),i));
i++;
ss.deleteInformation();
}
infile.close();
}
void ClientOp::save1()
{
ofstream outfile("e:\\train.txt",ios::out);
if(!outfile)
return;
for(it2=t.begin(); it2!=t.end(); it2++)
{
outfile<<*it2;
}
outfile.close();
}
void ClientOp::save2()
{
ofstream outfile("e:\\station.txt",ios::out);
if(!outfile)
return;
for(it1=s.begin(); it1!=s.end(); it1++)
{
outfile<<*it1;
}
outfile.close();
}
int main()
{
//ClientOp c;
//c.searchStation();
//c.searchTimeBase();
AdminOp a;
a.displayStation();
a.displayTrain();
//a.addTrain();
//a.addStation();
//a.deleteTrain();
//a.deleteStation();
a.changeStationTime();
}
using namespace std;
class Time
{
int hour;
int minute;
public:
Time(int v,int m ):hour(v),minute(m) {}
Time()
{
hour=0;
minute=0;
}
int getHour()
{
return hour;
};
int getMinute()
{
return minute;
};
bool operator<(const Time&d)const
{
return hour!=d.hour?hour<d.hour:minute<d.minute;
}
friend ostream&operator<<(ostream &os, const Time &d);
friend istream&operator>>(istream &in, Time &d);
};
ostream&operator<<(ostream &os,const Time &d)
{
os<<d.hour<<" "<<d.minute;
return os;
}
istream&operator>>(istream &in,Time &d)
{
in>>d.hour;
in>>d.minute;
return in;
}
class Train_information
{
string Train_number;
string Station;
Time from;
Time to;
public:
friend ostream&operator<<(ostream &os,Train_information &T);
friend istream&operator>>(istream &in,Train_information &T);
string getTrain_number()
{
return Train_number;
};
Time getTimeB()
{
return from;
};
Time getTimeE()
{
return to;
}
string getStation()
{
return Station;
};
void changeTime(Time t1,Time t2);
};
void Train_information::changeTime(Time t1,Time t2)
{
from=t1;
to=t2;
}
istream&operator>>(istream &in,Train_information &T)
{
in>>T.Train_number;
in>>T.Station;
in>>T.from;
in>>T.to;
return in;
}
ostream&operator<<(ostream &os,Train_information &T)
{
os<<T.Train_number<<" ";
os<<T.Station<<" ";
os<<T.from<<" ";
os<<T.to<<" ";
return os;
}
class Station
{
string name;
int num;//数目
vector<Train_information>T;
public:
Station()
{
num=0;
}
vector<Train_information>& getTrain_information()
{
return T;
};
friend ostream&operator<<(ostream &os,Station &s);
friend istream&operator>>(istream &in,Station &s);
void deleteInformation()
{
T.clear();
};
Train_information getT(int i)
{
return T[i];
};
string getName()
{
return name;
};
string search(int i);
int searchNumber(string number);
int getNum()
{
return num;
};
Time search(Time t) {}
void changeTime();//按车次序号查找列车并修改对应时间
void addTrain_information(Train_information t)
{
++num;
T.push_back(t);
};
};
int Station::searchNumber(string number)
{
for(int i=0; i<T.size(); i++)
{
if(T[i].getTrain_number()==number)
{
return i;
break;
}
}
}
void Station::changeTime()
{
cout<<"请输入车号\n";
string number;
cin>>number;
int i=searchNumber(number);
cout<<"请输入时间\n";
Time t1,t2;
cin>>t1>>t2;
//T[i].changeTime(t1,t2);
cout<<"修改成功\n";
cout<<T[i].getTimeB();
}
string Station::search(int i)
{
return T[i].getTrain_number();
}
istream&operator>>(istream &in,Station &s)
{
in>>s.name;
if(s.name=="E")return in;
in>>s.num;//这个站点被哪些车次经过
for(int i=0; i<s.num; i++)
{
Train_information TT;
in>>TT;
s.T.push_back(TT);
}
return in;
}
ostream&operator<<(ostream &os,Station &s)
{
os<<s.name<<" ";
os<<s.num;
os<<endl;
for(int i=0; i<s.num; i++)
{
os<<s.T[i];
os<<endl;
}
return os;
}
class Train_number//车次
{
string number;
string from;
string to;
int num;//站点数量
vector<Train_information>T;
public:
Train_number(string number,string from,string to,int num)
{
this->number=number;
this->from=from;
this->to=to;
this->num=num;
}
Train_number()
{
num=0;
}
friend ostream&operator<<(ostream &os,Train_number &t);
friend istream&operator>>(istream &in,Train_number &t);
void deleteInformation()
{
T.clear();
};
void setNum(int i)
{
num=i;
};
string getNumber()
{
return number;
};
Time getTimeB()
{
return T[0].getTimeB();
};
Time getTimeE()
{
return T[T.size()].getTimeE();
}
void addTrain_information(Train_information t)
{
++num;
T.push_back(t);
};
vector<Train_information>& getTrain_information()
{
return T;
};
int searchNumber(string number);
};
int Train_number::searchNumber(string number)
{
for(int i=0; i<T.size(); i++)
{
if(T[i].getTrain_number()==number)
{
return i;
break;
}
}
}
istream&operator>>(istream &in,Train_number &t)
{
in>>t.number;
if(t.number=="E")return in;
in>>t.from;
in>>t.to;
in>>t.num;
for(int i=0; i<t.num; i++)
{
Train_information TT;
in>>TT;
t.T.push_back(TT);
}
return in;
}
ostream&operator<<(ostream &os,Train_number &t)
{
os<<t.number<<" ";
os<<t.from<<" ";
os<<t.to<<" ";
os<<t.num;
os<<endl;
for(int i=0; i<t.num; i++)
{
os<<t.T[i];
os<<endl;
}
return os;
}
class AdminOp
{
vector<Station>s;
vector<Station>::iterator it1;
multimap<string,int>m1;
multimap<string,int>::iterator m1p;
multimap<Time,int>m3;
multimap<Time,int>::iterator m3p;
vector<Train_number>t;
vector<Train_number>::iterator it2 ;
multimap<string,int>m2;
multimap<string,int>::iterator m2p;
public:
AdminOp()
{
load1();
load2();
}
~AdminOp()
{
save1();
save2();
}
void load1();
void load2();
void save1();
void save2();
void displayTrain();
void displayStation();
void searchStation();
void searchTrain_number();
int searchS(string where);
int searchT(string number);
void addTrain();//增加车次
void deleteTrain();//删除车次
void addStation();//增加站点
void deleteStation();//删除站点
void changeStationTime();
};
void AdminOp::changeStationTime()/?????
{
cout<<"您想修改哪个站点,输入E结束\n";
string name;
while(cin>>name)
{
if(name=="E")break;
int i=searchS(name);//找到s[i],某个站点,站点下有各个车次经过的时间,对其修改.
cout<<"输入修改的车次\n";
cout<<"第几个站点: "<<i<<endl;
string number;
cin>>number;
int j=searchT(number);
cout<<"第几班车:"<<j<<endl;
//找到t[j];
cout<<s[i];
int k=s[i].searchNumber(number);
int l=t[j].searchNumber(number);//安地点查询""""""""
cout<<k<<" "<<l;
if(k==-1||l==-1)
{
cout<<"没找到\n";
}
else
{
cout<<"请输入时间\n";
Time t1,t2;
cin>>t1>>t2;
s[i].getTrain_information()[k-1].changeTime( t1, t2);
t[j].getTrain_information()[l].changeTime( t1, t2);
}
//s[i].changeTime();
//s[i].changeTime(number,t1,t2);
//cout<<s[i];
//int k=s[i].searchNumber(number);
//s[i].getT(s[i].searchNumber(number)).changeTime(t1,t2);
}
}
void AdminOp::searchStation()
{
cout<<"您想查询的站点为\n";
string where;
cin>>where;
if(searchT(where)==-1)
cout<<"没找到\n";
else
{
cout<<s[searchS(where)];
}
}
void AdminOp::searchTrain_number()
{
cout<<"您想查询的车次为\n";
string number;
cin>>number;
if(searchS(number)==-1)
cout<<"没找到\n";
else
{
cout<<t[searchS(number)];
}
}
int AdminOp::searchS(string where)
{
m1p=m1.find(where);
if(m1p!=m1.end())
{
int i=m1p->second;
return i;
}
else return -1;
}
int AdminOp::searchT(string number)
{
m2p=m2.find(number);
if(m2p!=m2.end())
{
int i=m2p->second;
return i;
}
else return -1;
}
void AdminOp::addStation()
{
cout<<"你想增加的站点信息为,输入车站名称E结束\n";
while(1)
{
Station ss;
cin>>ss;
if(ss.getName()=="E")
{
break;
}
s.push_back(ss);
cout<<"添加成功\n";
}//后来要改
}
void AdminOp::deleteStation()
{
cout<<"你想删除的站点信息为,输入车站名称E结束\n";
string name;
while(1)
{
cin>>name;
if(name=="E")break;
int i=searchS(name);
it1=s.begin()+i;
s.erase(it1);
cout<<"删除成功\n";
}
}
void AdminOp::addTrain()
{
cout<<"你想增加的车次信息为,输入车次序号E结束\n";
while(1)
{
string number;
cout<<"输入车号: ";
cin>>number;
if(number=="E")break;
cout<<"输入起止站点: ";
string from;
string to;
cin>>from>>to;
cout<<"输入所经站点数: ";
Train_number tt(number,from,to,0);
int num;
cin>>num;
int k;
cout<<"输入站点信息\n";
for(int i=0; i<num; i++)
{
Train_information in;
cin>>in;
tt.addTrain_information(in);
k=searchS(in.getStation());
if(k==-1)
{
cout<<"此站点不存在\n";
}
else
{
s[k].addTrain_information(in);
}
t.push_back(tt);
//在已有的站点再添加这个车次
} //可以同时添加站点
}
void AdminOp::deleteTrain()
{
cout<<"你想删除的车次为,输入车次序号E结束\n";
string number;
while(1)
{
cin>>number;
if(number=="E")break;
int i=searchT(number);
it2=t.begin()+i;
t.erase(it2);
cout<<"删除成功\n";
}
}
void AdminOp::displayTrain()
{
cout<<"This is all information about train\n";
for(it2=t.begin(); it2!=t.end(); it2++)
{
cout<<*it2;
}
}
void AdminOp::displayStation()
{
cout<<"This is all information about station\n";
for(it1=s.begin(); it1!=s.end(); it1++)
{
cout<<*it1;
}
}
void AdminOp::load1()
{
int i;
Train_number tt;
ifstream infile("e:\\train.txt",ios::in);
if(!infile)
return;
t.clear();
i=0;
while(infile>>tt)
{
t.push_back(tt);
//cout<<tt;
m2.insert(make_pair(tt.getNumber(),i));
i++;
tt.deleteInformation();
}
infile.close();
}
void AdminOp::load2()
{
int i;
Station ss;
ifstream infile("e:\\station.txt",ios::in);
if(!infile)
return;
s.clear();
i=0;
while(infile>>ss)
{
s.push_back(ss);
//cout<<ss;
m1.insert(make_pair(ss.getName(),i));
i++;
ss.deleteInformation();
}
infile.close();
}
void AdminOp::save1()
{
ofstream outfile("e:\\train.txt",ios::out);
if(!outfile)
return;
for(it2=t.begin(); it2!=t.end(); it2++)
{
outfile<<*it2;
}
outfile.close();
}
void AdminOp::save2()
{
ofstream outfile("e:\\station.txt",ios::out);
if(!outfile)
return;
for(it1=s.begin(); it1!=s.end(); it1++)
{
outfile<<*it1;
}
outfile.close();
}
class ClientOp
{
vector<Station>s;
vector<Station>::iterator it1;
multimap<string,int>m1;
multimap<string,int>::iterator m1p;
multimap<Time,int>m3;
multimap<Time,int>::iterator m3p,m4p,m5p;
vector<Train_number>t;
vector<Train_number>::iterator it2 ;
multimap<string,int>m2;
multimap<string,int>::iterator m2p;
public:
ClientOp()
{
load1();
load2();
}
~ClientOp()
{
//save1();
//save2();
}
void load1();
void load2();
void save1();
void save2();
void searchBase();
void searchTimeBase();
void searchStation();
void searchTrain_number();
int searchS(string where);
int searchT(string number);
void display();
};
void ClientOp::searchTimeBase()
{
cout<<"请输入起始站点\n";
string from;
string to;
cin>>from>>to;
int i=searchS(from);
int j=searchS(to);//找到两个站点s[i],s[j];
cout<<"请输入:1.发车时间限定查询;2.目的地到达时间限定查询\n";
int n;
cin>>n;
if(n==1)
{
cout<<"发车时间限定查询\n";//此时间后发出的车
Time tt;
cin>>tt;
for(int k=0; k<s[i].getNum()&&k<s[j].getNum(); k++)
{
for(int l=0; l<s[i].getNum()&&l<s[j].getNum(); l++)
{
if(s[i].search(k)==s[j].search(l))
{
int m=searchT(s[i].search(k));
if(tt<t[m].getTimeB())
{
cout<<t[m]<<endl;
}
}
}
}
}
else
{
cout<<"目的地到达时间限定查询\n";//此时间前到达的车
Time tt;
cin>>tt;
for(int k=0; k<s[i].getNum()&&k<s[j].getNum(); k++)
{
for(int l=0; l<s[i].getNum()&&l<s[j].getNum(); l++)
{
if(s[i].search(k)==s[j].search(l))
{
int m=searchT(s[i].search(k));
if(t[m].getTimeE()<tt)
{
cout<<t[m]<<endl;
}
}
}
}
}
}
void ClientOp::searchBase()
{
cout<<"请输入起始站点\n";
string from;
string to;
cin>>from>>to;
int i=searchS(from);
int j=searchS(to);//找到两个站点s[i],s[j];
for(int k=0; k<s[i].getNum()&&k<s[j].getNum(); k++)
{
for(int l=0; l<s[i].getNum()&&l<s[j].getNum(); l++)
{
if(s[i].search(k)==s[j].search(l))
{
int m=searchT(s[i].search(k));
cout<<t[m]<<endl;
}
}
}
}
int ClientOp::searchS(string where)
{
m1p=m1.find(where);
if(m1p!=m1.end())
{
int i=m1p->second;
return i;
}
else return -1;
}
int ClientOp::searchT(string number)
{
m2p=m2.find(number);
if(m2p!=m2.end())
{
int i=m2p->second;
return i;
}
else return -1;
}
void ClientOp::searchStation()
{
cout<<"您想查询的站点为\n";
string where;
cin>>where;
if(searchT(where)==-1)
cout<<"没找到\n";
else
{
cout<<s[searchS(where)];
}
}
void ClientOp::searchTrain_number()
{
cout<<"您想查询的车次为\n";
string number;
cin>>number;
if(searchS(number)==-1)
cout<<"没找到\n";
else
{
cout<<t[searchS(number)];
}
}
void ClientOp::display()
{
for(it2=t.begin(); it2!=t.end(); it2++)
{
cout<<*it2;
}
}
void ClientOp::load1()
{
int i;
Train_number tt;
ifstream infile("e:\\train.txt",ios::in);
if(!infile)
return;
t.clear();
i=0;
while(infile>>tt)
{
t.push_back(tt);
cout<<tt;
m2.insert(make_pair(tt.getNumber(),i));
i++;
tt.deleteInformation();
}
infile.close();
}
void ClientOp::load2()
{
int i;
Station ss;
ifstream infile("e:\\station.txt",ios::in);
if(!infile)
return;
s.clear();
i=0;
while(infile>>ss)
{
s.push_back(ss);
cout<<ss;
m1.insert(make_pair(ss.getName(),i));
i++;
ss.deleteInformation();
}
infile.close();
}
void ClientOp::save1()
{
ofstream outfile("e:\\train.txt",ios::out);
if(!outfile)
return;
for(it2=t.begin(); it2!=t.end(); it2++)
{
outfile<<*it2;
}
outfile.close();
}
void ClientOp::save2()
{
ofstream outfile("e:\\station.txt",ios::out);
if(!outfile)
return;
for(it1=s.begin(); it1!=s.end(); it1++)
{
outfile<<*it1;
}
outfile.close();
}
int main()
{
//ClientOp c;
//c.searchStation();
//c.searchTimeBase();
AdminOp a;
a.displayStation();
a.displayTrain();
//a.addTrain();
//a.addStation();
//a.deleteTrain();
//a.deleteStation();
a.changeStationTime();
}
using namespace std;
class Time
{
int hour;
int minute;
public:
Time(int v,int m ):hour(v),minute(m) {}
Time()
{
hour=0;
minute=0;
}
int getHour()
{
return hour;
};
int getMinute()
{
return minute;
};
bool operator<(const Time&d)const
{
return hour!=d.hour?hour<d.hour:minute<d.minute;
}
friend ostream&operator<<(ostream &os, const Time &d);
friend istream&operator>>(istream &in, Time &d);
};
ostream&operator<<(ostream &os,const Time &d)
{
os<<d.hour<<" "<<d.minute;
return os;
}
istream&operator>>(istream &in,Time &d)
{
in>>d.hour;
in>>d.minute;
return in;
}
class Train_information
{
string Train_number;
string Station;
Time from;
Time to;
public:
friend ostream&operator<<(ostream &os,Train_information &T);
friend istream&operator>>(istream &in,Train_information &T);
string getTrain_number()
{
return Train_number;
};
Time getTimeB()
{
return from;
};
Time getTimeE()
{
return to;
}
string getStation()
{
return Station;
};
void changeTime(Time t1,Time t2);
};
void Train_information::changeTime(Time t1,Time t2)
{
from=t1;
to=t2;
}
istream&operator>>(istream &in,Train_information &T)
{
in>>T.Train_number;
in>>T.Station;
in>>T.from;
in>>T.to;
return in;
}
ostream&operator<<(ostream &os,Train_information &T)
{
os<<T.Train_number<<" ";
os<<T.Station<<" ";
os<<T.from<<" ";
os<<T.to<<" ";
return os;
}
class Station
{
string name;
int num;//数目
vector<Train_information>T;
public:
Station()
{
num=0;
}
vector<Train_information>getTrain_information()
{
return T;
};
friend ostream&operator<<(ostream &os,Station &s);
friend istream&operator>>(istream &in,Station &s);
void deleteInformation()
{
T.clear();
};
Train_information getT(int i)
{
return T[i];
};
string getName()
{
return name;
};
string search(int i);
int searchNumber(string number);
int getNum()
{
return num;
};
Time search(Time t) {}
void changeTime();//按车次序号查找列车并修改对应时间
void addTrain_information(Train_information t)
{
++num;
T.push_back(t);
};
};
int Station::searchNumber(string number)
{
for(int i=0; i<T.size(); i++)
{
if(T[i].getTrain_number()==number)
{
return i;
break;
}
}
}
void Station::changeTime()
{
cout<<"请输入车号\n";
string number;
cin>>number;
int i=searchNumber(number);
cout<<"请输入时间\n";
Time t1,t2;
cin>>t1>>t2;
T[i].changeTime(t1,t2);
cout<<"修改成功\n";
cout<<T[i].getTimeB();
}
string Station::search(int i)
{
return T[i].getTrain_number();
}
istream&operator>>(istream &in,Station &s)
{
in>>s.name;
if(s.name=="E")return in;
in>>s.num;//这个站点被哪些车次经过
for(int i=0; i<s.num; i++)
{
Train_information TT;
in>>TT;
s.T.push_back(TT);
}
return in;
}
ostream&operator<<(ostream &os,Station &s)
{
os<<s.name<<" ";
os<<s.num;
os<<endl;
for(int i=0; i<s.num; i++)
{
os<<s.T[i];
os<<endl;
}
return os;
}
class Train_number//车次
{
string number;
string from;
string to;
int num;//站点数量
vector<Train_information>T;
public:
Train_number(string number,string from,string to,int num)
{
this->number=number;
this->from=from;
this->to=to;
this->num=num;
}
Train_number()
{
num=0;
}
friend ostream&operator<<(ostream &os,Train_number &t);
friend istream&operator>>(istream &in,Train_number &t);
void deleteInformation()
{
T.clear();
};
void setNum(int i)
{
num=i;
};
string getNumber()
{
return number;
};
Time getTimeB()
{
return T[0].getTimeB();
};
Time getTimeE()
{
return T[T.size()].getTimeE();
}
void addTrain_information(Train_information t)
{
++num;
T.push_back(t);
};
};
istream&operator>>(istream &in,Train_number &t)
{
in>>t.number;
if(t.number=="E")return in;
in>>t.from;
in>>t.to;
in>>t.num;
for(int i=0; i<t.num; i++)
{
Train_information TT;
in>>TT;
t.T.push_back(TT);
}
return in;
}
ostream&operator<<(ostream &os,Train_number &t)
{
os<<t.number<<" ";
os<<t.from<<" ";
os<<t.to<<" ";
os<<t.num;
os<<endl;
for(int i=0; i<t.num; i++)
{
os<<t.T[i];
os<<endl;
}
return os;
}
class AdminOp
{
vector<Station>s;
vector<Station>::iterator it1;
multimap<string,int>m1;
multimap<string,int>::iterator m1p;
multimap<Time,int>m3;
multimap<Time,int>::iterator m3p;
vector<Train_number>t;
vector<Train_number>::iterator it2 ;
multimap<string,int>m2;
multimap<string,int>::iterator m2p;
public:
AdminOp()
{
load1();
load2();
}
~AdminOp()
{
save1();
save2();
}
void load1();
void load2();
void save1();
void save2();
void displayTrain();
void displayStation();
void searchStation();
void searchTrain_number();
int searchS(string where);
int searchT(string number);
void addTrain();//增加车次
void deleteTrain();//删除车次
void addStation();//增加站点
void deleteStation();//删除站点
void changeStationTime();
};
void AdminOp::changeStationTime()/?????
{
cout<<"您想修改哪个站点,输入E结束\n";
string name;
while(cin>>name)
{
if(name=="E")break;
int i=searchS(name);//找到s[i],某个站点,站点下有各个车次经过的时间,对其修改.
cout<<"输入修改的车次及时间\n";
string number;
cin>>number;
cout<<s[i];
int k=s[searchS(name)].searchNumber(number);
if(k==-1)
{
cout<<"没找到\n";
}
else
{
Time t1,t2;
cin>>t1>>t2;
s[i].getTrain_information()[k].changeTime(t1,t2);
}
//s[i].changeTime();
//s[i].changeTime(number,t1,t2);
//cout<<s[i];
//int k=s[i].searchNumber(number);
//s[i].getT(s[i].searchNumber(number)).changeTime(t1,t2);
}
}
void AdminOp::searchStation()
{
cout<<"您想查询的站点为\n";
string where;
cin>>where;
if(searchT(where)==-1)
cout<<"没找到\n";
else
{
cout<<s[searchS(where)];
}
}
void AdminOp::searchTrain_number()
{
cout<<"您想查询的车次为\n";
string number;
cin>>number;
if(searchS(number)==-1)
cout<<"没找到\n";
else
{
cout<<t[searchS(number)];
}
}
int AdminOp::searchS(string where)
{
m1p=m1.find(where);
if(m1p!=m1.end())
{
int i=m1p->second;
return i;
}
else return -1;
}
int AdminOp::searchT(string number)
{
m2p=m2.find(number);
if(m2p!=m2.end())
{
int i=m2p->second;
return i;
}
else return -1;
}
void AdminOp::addStation()
{
cout<<"你想增加的站点信息为,输入车站名称E结束\n";
while(1)
{
Station ss;
cin>>ss;
if(ss.getName()=="E")
{
break;
}
s.push_back(ss);
cout<<"添加成功\n";
}//后来要改
}
void AdminOp::deleteStation()
{
cout<<"你想删除的站点信息为,输入车站名称E结束\n";
string name;
while(1)
{
cin>>name;
if(name=="E")break;
int i=searchS(name);
it1=s.begin()+i;
s.erase(it1);
cout<<"删除成功\n";
}
}
void AdminOp::addTrain()
{
cout<<"你想增加的车次信息为,输入车次序号E结束\n";
while(1)
{
string number;
cout<<"输入车号: ";
cin>>number;
if(number=="E")break;
cout<<"输入起止站点: ";
string from;
string to;
cin>>from>>to;
cout<<"输入所经站点数: ";
Train_number tt(number,from,to,0);
int num;
cin>>num;
int k;
cout<<"输入站点信息\n";
for(int i=0; i<num; i++)
{
Train_information in;
cin>>in;
tt.addTrain_information(in);
k=searchS(in.getStation());
if(k==-1)
{
cout<<"此站点不存在\n";
}
else
{
s[k].addTrain_information(in);
}
t.push_back(tt);
//在已有的站点再添加这个车次
} //可以同时添加站点
}
void AdminOp::deleteTrain()
{
cout<<"你想删除的车次为,输入车次序号E结束\n";
string number;
while(1)
{
cin>>number;
if(number=="E")break;
int i=searchT(number);
it2=t.begin()+i;
t.erase(it2);
cout<<"删除成功\n";
}
}
void AdminOp::displayTrain()
{
cout<<"This is all information about train\n";
for(it2=t.begin(); it2!=t.end(); it2++)
{
cout<<*it2;
}
}
void AdminOp::displayStation()
{
cout<<"This is all information about station\n";
for(it1=s.begin(); it1!=s.end(); it1++)
{
cout<<*it1;
}
}
void AdminOp::load1()
{
int i;
Train_number tt;
ifstream infile("e:\\train.txt",ios::in);
if(!infile)
return;
t.clear();
i=0;
while(infile>>tt)
{
t.push_back(tt);
//cout<<tt;
m2.insert(make_pair(tt.getNumber(),i));
i++;
tt.deleteInformation();
}
infile.close();
}
void AdminOp::load2()
{
int i;
Station ss;
ifstream infile("e:\\station.txt",ios::in);
if(!infile)
return;
s.clear();
i=0;
while(infile>>ss)
{
s.push_back(ss);
//cout<<ss;
m1.insert(make_pair(ss.getName(),i));
i++;
ss.deleteInformation();
}
infile.close();
}
void AdminOp::save1()
{
ofstream outfile("e:\\train.txt",ios::out);
if(!outfile)
return;
for(it2=t.begin(); it2!=t.end(); it2++)
{
outfile<<*it2;
}
outfile.close();
}
void AdminOp::save2()
{
ofstream outfile("e:\\station.txt",ios::out);
if(!outfile)
return;
for(it1=s.begin(); it1!=s.end(); it1++)
{
outfile<<*it1;
}
outfile.close();
}
class ClientOp
{
vector<Station>s;
vector<Station>::iterator it1;
multimap<string,int>m1;
multimap<string,int>::iterator m1p;
multimap<Time,int>m3;
multimap<Time,int>::iterator m3p,m4p,m5p;
vector<Train_number>t;
vector<Train_number>::iterator it2 ;
multimap<string,int>m2;
multimap<string,int>::iterator m2p;
public:
ClientOp()
{
load1();
load2();
}
~ClientOp()
{
//save1();
//save2();
}
void load1();
void load2();
void save1();
void save2();
void searchBase();
void searchTimeBase();
void searchStation();
void searchTrain_number();
int searchS(string where);
int searchT(string number);
void display();
};
void ClientOp::searchTimeBase()
{
cout<<"请输入起始站点\n";
string from;
string to;
cin>>from>>to;
int i=searchS(from);
int j=searchS(to);//找到两个站点s[i],s[j];
cout<<"请输入:1.发车时间限定查询;2.目的地到达时间限定查询\n";
int n;
cin>>n;
if(n==1)
{
cout<<"发车时间限定查询\n";//此时间后发出的车
Time tt;
cin>>tt;
for(int k=0; k<s[i].getNum()&&k<s[j].getNum(); k++)
{
for(int l=0; l<s[i].getNum()&&l<s[j].getNum(); l++)
{
if(s[i].search(k)==s[j].search(l))
{
int m=searchT(s[i].search(k));
if(tt<t[m].getTimeB())
{
cout<<t[m]<<endl;
}
}
}
}
}
else
{
cout<<"目的地到达时间限定查询\n";//此时间前到达的车
Time tt;
cin>>tt;
for(int k=0; k<s[i].getNum()&&k<s[j].getNum(); k++)
{
for(int l=0; l<s[i].getNum()&&l<s[j].getNum(); l++)
{
if(s[i].search(k)==s[j].search(l))
{
int m=searchT(s[i].search(k));
if(t[m].getTimeE()<tt)
{
cout<<t[m]<<endl;
}
}
}
}
}
}
void ClientOp::searchBase()
{
cout<<"请输入起始站点\n";
string from;
string to;
cin>>from>>to;
int i=searchS(from);
int j=searchS(to);//找到两个站点s[i],s[j];
for(int k=0; k<s[i].getNum()&&k<s[j].getNum(); k++)
{
for(int l=0; l<s[i].getNum()&&l<s[j].getNum(); l++)
{
if(s[i].search(k)==s[j].search(l))
{
int m=searchT(s[i].search(k));
cout<<t[m]<<endl;
}
}
}
}
int ClientOp::searchS(string where)
{
m1p=m1.find(where);
if(m1p!=m1.end())
{
int i=m1p->second;
return i;
}
else return -1;
}
int ClientOp::searchT(string number)
{
m2p=m2.find(number);
if(m2p!=m2.end())
{
int i=m2p->second;
return i;
}
else return -1;
}
void ClientOp::searchStation()
{
cout<<"您想查询的站点为\n";
string where;
cin>>where;
if(searchT(where)==-1)
cout<<"没找到\n";
else
{
cout<<s[searchS(where)];
}
}
void ClientOp::searchTrain_number()
{
cout<<"您想查询的车次为\n";
string number;
cin>>number;
if(searchS(number)==-1)
cout<<"没找到\n";
else
{
cout<<t[searchS(number)];
}
}
void ClientOp::display()
{
for(it2=t.begin(); it2!=t.end(); it2++)
{
cout<<*it2;
}
}
void ClientOp::load1()
{
int i;
Train_number tt;
ifstream infile("e:\\train.txt",ios::in);
if(!infile)
return;
t.clear();
i=0;
while(infile>>tt)
{
t.push_back(tt);
cout<<tt;
m2.insert(make_pair(tt.getNumber(),i));
i++;
tt.deleteInformation();
}
infile.close();
}
void ClientOp::load2()
{
int i;
Station ss;
ifstream infile("e:\\station.txt",ios::in);
if(!infile)
return;
s.clear();
i=0;
while(infile>>ss)
{
s.push_back(ss);
cout<<ss;
m1.insert(make_pair(ss.getName(),i));
i++;
ss.deleteInformation();
}
infile.close();
}
void ClientOp::save1()
{
ofstream outfile("e:\\train.txt",ios::out);
if(!outfile)
return;
for(it2=t.begin(); it2!=t.end(); it2++)
{
outfile<<*it2;
}
outfile.close();
}
void ClientOp::save2()
{
ofstream outfile("e:\\station.txt",ios::out);
if(!outfile)
return;
for(it1=s.begin(); it1!=s.end(); it1++)
{
outfile<<*it1;
}
outfile.close();
}
int main()
{
//ClientOp c;
//c.searchStation();
//c.searchTimeBase();
AdminOp a;
a.displayStation();
a.displayTrain();
//a.addTrain();
//a.addStation();
//a.deleteTrain();
//a.deleteStation();
a.changeStationTime();
}
using namespace std;
class Time
{
int hour;
int minute;
public:
Time(int v,int m ):hour(v),minute(m) {}
Time()
{
hour=0;
minute=0;
}
int getHour()
{
return hour;
};
int getMinute()
{
return minute;
};
bool operator<(const Time&d)const
{
return hour!=d.hour?hour<d.hour:minute<d.minute;
}
friend ostream&operator<<(ostream &os, const Time &d);
friend istream&operator>>(istream &in, Time &d);
};
ostream&operator<<(ostream &os,const Time &d)
{
os<<d.hour<<" "<<d.minute;
return os;
}
istream&operator>>(istream &in,Time &d)
{
in>>d.hour;
in>>d.minute;
return in;
}
class Train_information
{
string Train_number;
string Station;
Time from;
Time to;
public:
friend ostream&operator<<(ostream &os,Train_information &T);
friend istream&operator>>(istream &in,Train_information &T);
string getTrain_number()
{
return Train_number;
};
Time getTimeB()
{
return from;
};
Time getTimeE()
{
return to;
}
void changeTime(Time t1,Time t2);
};
void Train_information::changeTime(Time t1,Time t2)
{
from=t1;
to=t2;
}
istream&operator>>(istream &in,Train_information &T)
{
in>>T.Train_number;
in>>T.Station;
in>>T.from;
in>>T.to;
return in;
}
ostream&operator<<(ostream &os,Train_information &T)
{
os<<T.Train_number<<" ";
os<<T.Station<<" ";
os<<T.from<<" ";
os<<T.to<<" ";
return os;
}
class Station
{
string name;
int num;//数目
vector<Train_information>T;
public:
Station()
{
num=0;
}
friend ostream&operator<<(ostream &os,Station &s);
friend istream&operator>>(istream &in,Station &s);
void deleteInformation()
{
T.clear();
};
string getName()
{
return name;
};
string search(int i);
int searchNumber(string number);
int getNum()
{
return num;
};
Time search(Time t) {}
void changeTime(string number,Time t1,Time t2);//按车次序号查找列车并修改对应时间
};
int Station::searchNumber(string number)
{
for(int i=0;i<T.size();i++)
{
if(T[i].getTrain_number()==number)
{
return i;
break;
}
}
}
void Station::changeTime(string number,Time t1,Time t2)
{
int i=searchNumber(number);
T[i].changeTime(t1,t2);
cout<<"修改成功\n";
exit(0);
}
string Station::search(int i)
{
return T[i].getTrain_number();
}
istream&operator>>(istream &in,Station &s)
{
in>>s.name;
if(s.name=="E")return in;
in>>s.num;//这个站点被哪些车次经过
for(int i=0; i<s.num; i++)
{
Train_information TT;
in>>TT;
s.T.push_back(TT);
}
return in;
}
ostream&operator<<(ostream &os,Station &s)
{
os<<s.name<<" ";
os<<s.num;
os<<endl;
for(int i=0; i<s.num; i++)
{
os<<s.T[i];
os<<endl;
}
return os;
}
class Train_number//车次
{
string number;
string from;
string to;
int num;//站点数量
vector<Train_information>T;
public:
Train_number()
{
num=0;
}
friend ostream&operator<<(ostream &os,Train_number &t);
friend istream&operator>>(istream &in,Train_number &t);
void deleteInformation()
{
T.clear();
};
string getNumber()
{
return number;
};
Time getTimeB()
{
return T[0].getTimeB();
};
Time getTimeE()
{
return T[T.size()].getTimeE();
}
};
istream&operator>>(istream &in,Train_number &t)
{
in>>t.number;
if(t.number=="E")return in;
in>>t.from;
in>>t.to;
in>>t.num;
for(int i=0; i<t.num; i++)
{
Train_information TT;
in>>TT;
t.T.push_back(TT);
}
return in;
}
ostream&operator<<(ostream &os,Train_number &t)
{
os<<t.number<<" ";
os<<t.from<<" ";
os<<t.to<<" ";
os<<t.num;
os<<endl;
for(int i=0; i<t.num; i++)
{
os<<t.T[i];
os<<endl;
}
return os;
}
class AdminOp
{
vector<Station>s;
vector<Station>::iterator it1;
multimap<string,int>m1;
multimap<string,int>::iterator m1p;
multimap<Time,int>m3;
multimap<Time,int>::iterator m3p;
vector<Train_number>t;
vector<Train_number>::iterator it2 ;
multimap<string,int>m2;
multimap<string,int>::iterator m2p;
public:
AdminOp()
{
load1();
load2();
}
~AdminOp()
{
save1();
save2();
}
void load1();
void load2();
void save1();
void save2();
void displayTrain();
void displayStation();
void searchStation();
void searchTrain_number();
int searchS(string where);
int searchT(string number);
void addTrain();//增加车次
void deleteTrain();//删除车次
void addStation();//增加站点
void deleteStation();//删除站点
void changeStationTime();
};
void AdminOp::changeStationTime()
{
cout<<"您想修改哪个站点,输入E结束\n";
string name;
while(cin>>name)
{
if(name=="E")break;
int i=searchS(name);//找到s[i],某个站点,站点下有各个车次经过的时间,对其修改.
cout<<"输入修改的车次及时间\n";
string number;
cin>>number;
Time t1,t2;
cin>>t1>>t2;
s[i].changeTime(number,t1,t2);
}
}
void AdminOp::searchStation()
{
cout<<"您想查询的站点为\n";
string where;
cin>>where;
if(searchT(where)==-1)
cout<<"没找到\n";
else
{
cout<<s[searchS(where)];
}
}
void AdminOp::searchTrain_number()
{
cout<<"您想查询的车次为\n";
string number;
cin>>number;
if(searchS(number)==-1)
cout<<"没找到\n";
else
{
cout<<t[searchS(number)];
}
int AdminOp::searchS(string where)
{
m1p=m1.find(where);
if(m1p!=m1.end())
{
int i=m1p->second;
return i;
}
else return -1;
}
int AdminOp::searchT(string number)
{
m2p=m2.find(number);
if(m2p!=m2.end())
{
int i=m2p->second;
return i;
}
else return -1;
}
void AdminOp::addStation()
{
cout<<"你想增加的站点信息为,输入车站名称E结束\n";
while(1)
{
Station ss;
cin>>ss;
if(ss.getName()=="E")
{
break;
}
s.push_back(ss);
cout<<"添加成功\n";
}//后来要改
}
void AdminOp::deleteStation()
{
cout<<"你想删除的站点信息为,输入车站名称E结束\n";
string name;
while(1)
{
cin>>name;
if(name=="E")break;
int i=searchS(name);
it1=s.begin()+i;
s.erase(it1);
cout<<"删除成功\n";
}
}
void AdminOp::addTrain()
{
cout<<"你想增加的车次信息为,输入车次序号E结束\n";
while(1)
{
Train_number tt;
cin>>tt;
if(tt.getNumber()=="E")break;
t.push_back(tt);
cout<<"增加成功\n";
}//可以同时添加站点
}
void AdminOp::deleteTrain()
{
cout<<"你想删除的车次为,输入车次序号E结束\n";
string number;
while(1)
{
cin>>number;
if(number=="E")break;
int i=searchT(number);
it2=t.begin()+i;
t.erase(it2);
cout<<"删除成功\n";
}
}
void AdminOp::displayTrain()
{
cout<<"This is all information about train\n";
for(it1=s.begin(); it1!=s.end(); it1++)
{
cout<<*it1;
}
}
void AdminOp::displayStation()
{
cout<<"This is all information about station\n";
for(it2=t.begin(); it2!=t.end(); it2++)
{
cout<<*it2;
}
}
void AdminOp::load1()
{
int i;
Train_number tt;
ifstream infile("e:\\train.txt",ios::in);
if(!infile)
return;
t.clear();
i=0;
while(infile>>tt)
{
t.push_back(tt);
//cout<<tt;
m2.insert(make_pair(tt.getNumber(),i));
i++;
tt.deleteInformation();
}
infile.close();
}
void AdminOp::load2()
{
int i;
Station ss;
ifstream infile("e:\\station.txt",ios::in);
if(!infile)
return;
s.clear();
i=0;
while(infile>>ss)
{
s.push_back(ss);
//cout<<ss;
m1.insert(make_pair(ss.getName(),i));
i++;
ss.deleteInformation();
}
infile.close();
}
void AdminOp::save1()
{
ofstream outfile("e:\\train.txt",ios::out);
if(!outfile)
return;
for(it2=t.begin(); it2!=t.end(); it2++)
{
outfile<<*it2;
}
outfile.close();
}
void AdminOp::save2()
{
ofstream outfile("e:\\station.txt",ios::out);
if(!outfile)
return;
for(it1=s.begin(); it1!=s.end(); it1++)
{
outfile<<*it1;
}
outfile.close();
}
class ClientOp
{
vector<Station>s;
vector<Station>::iterator it1;
multimap<string,int>m1;
multimap<string,int>::iterator m1p;
multimap<Time,int>m3;
multimap<Time,int>::iterator m3p;
vector<Train_number>t;
vector<Train_number>::iterator it2 ;
multimap<string,int>m2;
multimap<string,int>::iterator m2p;
public:
ClientOp()
{
load1();
load2();
}
~ClientOp()
{
//save1();
//save2();
}
void load1();
void load2();
void save1();
void save2();
void searchBase();
void searchTimeBase();
void searchStation();
void searchTrain_number();
int searchS(string where);
int searchT(string number);
void display();
};
void ClientOp::searchTimeBase()
{
cout<<"请输入起始站点\n";
string from;
string to;
cin>>from>>to;
int i=searchS(from);
int j=searchS(to);//找到两个站点s[i],s[j];
cout<<"请输入:1.发车时间限定查询;2.目的地到达时间限定查询\n";
int n;
cin>>n;
if(n==1)
{
cout<<"发车时间限定查询\n";//此时间后发出的车
Time tt;
cin>>tt;
for(int k=0; k<s[i].getNum()&&k<s[j].getNum(); k++)
{
for(int l=0; l<s[i].getNum()&&l<s[j].getNum(); l++)
{
if(s[i].search(k)==s[j].search(l))
{
int m=searchT(s[i].search(k));
if(tt<t[m].getTimeB())
{
cout<<t[m]<<endl;
}
}
}
}
}
else
{
cout<<"目的地到达时间限定查询\n";//此时间前到达的车
Time tt;
cin>>tt;
for(int k=0; k<s[i].getNum()&&k<s[j].getNum(); k++)
{
for(int l=0; l<s[i].getNum()&&l<s[j].getNum(); l++)
{
if(s[i].search(k)==s[j].search(l))
{
int m=searchT(s[i].search(k));
if(t[m].getTimeE()<tt)
{
cout<<t[m]<<endl;
}
}
}
}
}
}
void ClientOp::searchBase()
{
cout<<"请输入起始站点\n";
string from;
string to;
cin>>from>>to;
int i=searchS(from);
int j=searchS(to);//找到两个站点s[i],s[j];
for(int k=0; k<s[i].getNum()&&k<s[j].getNum(); k++)
{
for(int l=0; l<s[i].getNum()&&l<s[j].getNum(); l++)
{
if(s[i].search(k)==s[j].search(l))
{
int m=searchT(s[i].search(k));
cout<<t[m]<<endl;
}
}
}
}
int ClientOp::searchS(string where)
{
m1p=m1.find(where);
if(m1p!=m1.end())
{
int i=m1p->second;
return i;
}
else return -1;
}
int ClientOp::searchT(string number)
{
m2p=m2.find(number);
if(m2p!=m2.end())
{
int i=m2p->second;
return i;
}
else return -1;
}
void ClientOp::searchStation()
{
cout<<"您想查询的站点为\n";
string where;
cin>>where;
if(searchT(where)==-1)
cout<<"没找到\n";
else
{
cout<<s[searchS(where)];
}
}
void ClientOp::searchTrain_number()
{
cout<<"您想查询的车次为\n";
string number;
cin>>number;
if(searchS(number)==-1)
cout<<"没找到\n";
else
{
cout<<t[searchS(number)];
}
}
void ClientOp::display()
{
for(it2=t.begin(); it2!=t.end(); it2++)
{
cout<<*it2;
}
}
void ClientOp::load1()
{
int i;
Train_number tt;
ifstream infile("e:\\train.txt",ios::in);
if(!infile)
return;
t.clear();
i=0;
while(infile>>tt)
{
t.push_back(tt);
cout<<tt;
m2.insert(make_pair(tt.getNumber(),i));
i++;
tt.deleteInformation();
}
infile.close();
}
void ClientOp::load2()
{
int i;
Station ss;
ifstream infile("e:\\station.txt",ios::in);
if(!infile)
return;
s.clear();
i=0;
while(infile>>ss)
{
s.push_back(ss);
cout<<ss;
m1.insert(make_pair(ss.getName(),i));
i++;
ss.deleteInformation();
}
infile.close();
}
void ClientOp::save1()
{
ofstream outfile("e:\\train.txt",ios::out);
if(!outfile)
return;
for(it2=t.begin(); it2!=t.end(); it2++)
{
outfile<<*it2;
}
outfile.close();
}
void ClientOp::save2()
{
ofstream outfile("e:\\station.txt",ios::out);
if(!outfile)
return;
for(it1=s.begin(); it1!=s.end(); it1++)
{
outfile<<*it1;
}
outfile.close();
}
int main()
{
//ClientOp c;
//c.searchStation();
//c.searchTimeBase();
AdminOp a;
a.displayStation();
a.displayTrain();
//a.addTrain();
//a.addStation();
//a.deleteTrain();
//a.deleteStation();
a.changeStationTime();
}
using namespace std;
class Time
{
int hour;
int minute;
public:
Time(int v,int m ):hour(v),minute(m) {}
Time()
{
hour=0;
minute=0;
}
int getHour()
{
return hour;
};
int getMinute()
{
return minute;
};
bool operator<(const Time&d)const
{
return hour!=d.hour?hour<d.hour:minute<d.minute;
}
friend ostream&operator<<(ostream &os, const Time &d);
friend istream&operator>>(istream &in, Time &d);
};
ostream&operator<<(ostream &os,const Time &d)
{
os<<d.hour<<" "<<d.minute;
return os;
}
istream&operator>>(istream &in,Time &d)
{
in>>d.hour;
in>>d.minute;
return in;
}
class Train_information
{
string Train_number;
string Station;
Time from;
Time to;
public:
friend ostream&operator<<(ostream &os,Train_information &T);
friend istream&operator>>(istream &in,Train_information &T);
string getTrain_number()
{
return Train_number;
};
Time getTimeB()
{
return from;
};
Time getTimeE()
{
return to;
}
};
istream&operator>>(istream &in,Train_information &T)
{
in>>T.Train_number;
in>>T.Station;
in>>T.from;
in>>T.to;
return in;
}
ostream&operator<<(ostream &os,Train_information &T)
{
os<<T.Train_number<<" ";
os<<T.Station<<" ";
os<<T.from<<" ";
os<<T.to<<" ";
return os;
}
class Station
{
string name;
int num;//数目
vector<Train_information>T;
public:
Station()
{
num=0;
}
friend ostream&operator<<(ostream &os,Station &s);
friend istream&operator>>(istream &in,Station &s);
void deleteInformation()
{
T.clear();
};
string getName()
{
return name;
};
string search(int i);
int getNum()
{
return num;
};
Time search(Time t) {}
};
string Station::search(int i)
{
return T[i].getTrain_number();
}
istream&operator>>(istream &in,Station &s)
{
in>>s.name;
if(s.name=="E")return in;
in>>s.num;//这个站点被哪些车次经过
for(int i=0; i<s.num; i++)
{
Train_information TT;
in>>TT;
s.T.push_back(TT);
}
return in;
}
ostream&operator<<(ostream &os,Station &s)
{
os<<s.name<<" ";
os<<s.num;
os<<endl;
for(int i=0; i<s.num; i++)
{
os<<s.T[i];
os<<endl;
}
return os;
}
class Train_number//车次
{
string number;
string from;
string to;
int num;//站点数量
vector<Train_information>T;
public:
Train_number()
{
num=0;
}
friend ostream&operator<<(ostream &os,Train_number &t);
friend istream&operator>>(istream &in,Train_number &t);
void deleteInformation()
{
T.clear();
};
string getNumber()
{
return number;
};
Time getTimeB()
{
return T[0].getTimeB();
};
Time getTimeE()
{
return T[T.size()].getTimeE();
}
};
istream&operator>>(istream &in,Train_number &t)
{
in>>t.number;
if(t.number=="E")return in;
in>>t.from;
in>>t.to;
in>>t.num;
for(int i=0; i<t.num; i++)
{
Train_information TT;
in>>TT;
t.T.push_back(TT);
}
return in;
}
ostream&operator<<(ostream &os,Train_number &t)
{
os<<t.number<<" ";
os<<t.from<<" ";
os<<t.to<<" ";
os<<t.num;
os<<endl;
for(int i=0; i<t.num; i++)
{
os<<t.T[i];
os<<endl;
}
return os;
}
class AdminOp
{
vector<Station>s;
vector<Station>::iterator it1;
multimap<string,int>m1;
multimap<string,int>::iterator m1p;
multimap<Time,int>m3;
multimap<Time,int>::iterator m3p;
vector<Train_number>t;
vector<Train_number>::iterator it2 ;
multimap<string,int>m2;
multimap<string,int>::iterator m2p;
public:
AdminOp()
{
load1();
load2();
}
~AdminOp()
{
save1();
save2();
}
void load1();
void load2();
void save1();
void save2();
void displayTrain();
void displayStation();
void searchStation();
void searchTrain_number();
int searchS(string where);
int searchT(string number);
void addTrain();//增加车次
void deleteTrain();//删除车次
void addStation();//增加站点
void deleteStation();//删除站点
};
int AdminOp::searchS(string where)
{
m1p=m1.find(where);
if(m1p!=m1.end())
{
int i=m1p->second;
return i;
}
else return -1;
}
int AdminOp::searchT(string number)
{
m2p=m2.find(number);
if(m2p!=m2.end())
{
int i=m2p->second;
return i;
}
else return -1;
}
void AdminOp::addStation()
{
cout<<"你想增加的站点信息为,输入车站名称E结束\n";
while(1)
{
Station ss;
cin>>ss;
if(ss.getName()=="E")
{
break;
}
s.push_back(ss);
cout<<"添加成功\n";
}//后来要改
}
void AdminOp::deleteStation()
{
cout<<"你想删除的站点信息为,输入车站名称E结束\n";
string name;
while(1)
{
cin>>name;
if(name=="E")break;
}
}
void AdminOp::addTrain()
{
cout<<"你想增加的车次信息为,输入车次序号E结束\n";
while(1)
{
Train_number tt;
cin>>tt;
if(tt.getNumber()=="E")break;
t.push_back(tt);
cout<<"增加成功\n";
}//可以同时添加站点
}
void AdminOp::deleteTrain()
{
cout<<"你想删除的车次为,输入车次序号E结束\n";
string number;
while(1)
{
cin>>number;
if(number=="E")break;
int i=searchT(number);
it2=t.begin()+i;
t.erase(it2);
cout<<"删除成功\n";
}
}
void AdminOp::displayTrain()
{
cout<<"This is all information about train\n";
for(it1=s.begin(); it1!=s.end(); it1++)
{
cout<<*it1;
}
}
void AdminOp::displayStation()
{
cout<<"This is all information about station\n";
for(it2=t.begin(); it2!=t.end(); it2++)
{
cout<<*it2;
}
}
void AdminOp::load1()
{
int i;
Train_number tt;
ifstream infile("e:\\train.txt",ios::in);
if(!infile)
return;
t.clear();
i=0;
while(infile>>tt)
{
t.push_back(tt);
//cout<<tt;
m2.insert(make_pair(tt.getNumber(),i));
i++;
tt.deleteInformation();
}
infile.close();
}
void AdminOp::load2()
{
int i;
Station ss;
ifstream infile("e:\\station.txt",ios::in);
if(!infile)
return;
s.clear();
i=0;
while(infile>>ss)
{
s.push_back(ss);
//cout<<ss;
m1.insert(make_pair(ss.getName(),i));
i++;
ss.deleteInformation();
}
infile.close();
}
void AdminOp::save1()
{
ofstream outfile("e:\\train.txt",ios::out);
if(!outfile)
return;
for(it2=t.begin(); it2!=t.end(); it2++)
{
outfile<<*it2;
}
outfile.close();
}
void AdminOp::save2()
{
ofstream outfile("e:\\station.txt",ios::out);
if(!outfile)
return;
for(it1=s.begin(); it1!=s.end(); it1++)
{
outfile<<*it1;
}
outfile.close();
}
class ClientOp
{
vector<Station>s;
vector<Station>::iterator it1;
multimap<string,int>m1;
multimap<string,int>::iterator m1p;
multimap<Time,int>m3;
multimap<Time,int>::iterator m3p;
vector<Train_number>t;
vector<Train_number>::iterator it2 ;
multimap<string,int>m2;
multimap<string,int>::iterator m2p;
public:
ClientOp()
{
load1();
load2();
}
~ClientOp()
{
//save1();
//save2();
}
void load1();
void load2();
void save1();
void save2();
void searchBase();
void searchTimeBase();
void searchStation();
void searchTrain_number();
int searchS(string where);
int searchT(string number);
void display();
};
void ClientOp::searchTimeBase()
{
cout<<"请输入起始站点\n";
string from;
string to;
cin>>from>>to;
int i=searchS(from);
int j=searchS(to);//找到两个站点s[i],s[j];
cout<<"请输入:1.发车时间限定查询;2.目的地到达时间限定查询\n";
int n;
cin>>n;
if(n==1)
{
cout<<"发车时间限定查询\n";//此时间后发出的车
Time tt;
cin>>tt;
for(int k=0; k<s[i].getNum()&&k<s[j].getNum(); k++)
{
for(int l=0; l<s[i].getNum()&&l<s[j].getNum(); l++)
{
if(s[i].search(k)==s[j].search(l))
{
int m=searchT(s[i].search(k));
if(tt<t[m].getTimeB())
{
cout<<t[m]<<endl;
}
}
}
}
}
else
{
cout<<"目的地到达时间限定查询\n";//此时间前到达的车
Time tt;
cin>>tt;
for(int k=0; k<s[i].getNum()&&k<s[j].getNum(); k++)
{
for(int l=0; l<s[i].getNum()&&l<s[j].getNum(); l++)
{
if(s[i].search(k)==s[j].search(l))
{
int m=searchT(s[i].search(k));
if(t[m].getTimeE()<tt)
{
cout<<t[m]<<endl;
}
}
}
}
}
}
void ClientOp::searchBase()
{
cout<<"请输入起始站点\n";
string from;
string to;
cin>>from>>to;
int i=searchS(from);
int j=searchS(to);//找到两个站点s[i],s[j];
for(int k=0; k<s[i].getNum()&&k<s[j].getNum(); k++)
{
for(int l=0; l<s[i].getNum()&&l<s[j].getNum(); l++)
{
if(s[i].search(k)==s[j].search(l))
{
int m=searchT(s[i].search(k));
cout<<t[m]<<endl;
}
}
}
}
int ClientOp::searchS(string where)
{
m1p=m1.find(where);
if(m1p!=m1.end())
{
int i=m1p->second;
return i;
}
else return -1;
}
int ClientOp::searchT(string number)
{
m2p=m2.find(number);
if(m2p!=m2.end())
{
int i=m2p->second;
return i;
}
else return -1;
}
void ClientOp::searchStation()
{
cout<<"您想查询的站点为\n";
string where;
cin>>where;
cout<<s[searchS(where)];
}
void ClientOp::searchTrain_number()
{
cout<<"您想查询的车次为\n";
string number;
cin>>number;
if(searchS(number)==-1)
cout<<"没找到\n";
else
{
cout<<t[searchS(number)];
}
}
void ClientOp::display()
{
for(it2=t.begin(); it2!=t.end(); it2++)
{
cout<<*it2;
}
}
void ClientOp::load1()
{
int i;
Train_number tt;
ifstream infile("e:\\train.txt",ios::in);
if(!infile)
return;
t.clear();
i=0;
while(infile>>tt)
{
t.push_back(tt);
cout<<tt;
m2.insert(make_pair(tt.getNumber(),i));
i++;
tt.deleteInformation();
}
infile.close();
}
void ClientOp::load2()
{
int i;
Station ss;
ifstream infile("e:\\station.txt",ios::in);
if(!infile)
return;
s.clear();
i=0;
while(infile>>ss)
{
s.push_back(ss);
cout<<ss;
m1.insert(make_pair(ss.getName(),i));
i++;
ss.deleteInformation();
}
infile.close();
}
void ClientOp::save1()
{
ofstream outfile("e:\\train.txt",ios::out);
if(!outfile)
return;
for(it2=t.begin(); it2!=t.end(); it2++)
{
outfile<<*it2;
}
outfile.close();
}
void ClientOp::save2()
{
ofstream outfile("e:\\station.txt",ios::out);
if(!outfile)
return;
for(it1=s.begin(); it1!=s.end(); it1++)
{
outfile<<*it1;
}
outfile.close();
}
int main()
{
//ClientOp c;
//c.searchStation();
//c.searchTimeBase();
AdminOp a;
a.displayStation();
a.displayTrain();
//a.addTrain();
//a.addTrain();
//a.deleteTrain();
using namespace std;
class Time
{
int hour;
int minute;
public:
Time(int v,int m ):hour(v),minute(m) {}
Time()
{
hour=0;
minute=0;
}
int getHour()
{
return hour;
};
int getMinute()
{
return minute;
};
bool operator<(const Time&d)const
{
return hour!=d.hour?hour<d.hour:minute<d.minute;
}
friend ostream&operator<<(ostream &os, const Time &d);
friend istream&operator>>(istream &in, Time &d);
};
ostream&operator<<(ostream &os,const Time &d)
{
os<<d.hour<<" "<<d.minute;
return os;
}
istream&operator>>(istream &in,Time &d)
{
in>>d.hour;
in>>d.minute;
return in;
}
class Train_information
{
string Train_number;
string Station;
Time from;
Time to;
public:
friend ostream&operator<<(ostream &os,Train_information &T);
friend istream&operator>>(istream &in,Train_information &T);
};
istream&operator>>(istream &in,Train_information &T)
{
in>>T.Train_number;
in>>T.Station;
in>>T.from;
in>>T.to;
return in;
}
ostream&operator<<(ostream &os,Train_information &T)
{
os<<T.Train_number<<" ";
os<<T.Station<<" ";
os<<T.from<<" ";
os<<T.to<<" ";
return os;
}
class Station
{
string name;
int num;//数目
vector<Train_information>T;
public:
Station()
{
num=0;
}
friend ostream&operator<<(ostream &os,Station &s);
friend istream&operator>>(istream &in,Station &s);
void deleteInformation(){T.clear();};
string getName(){return name;};
};
istream&operator>>(istream &in,Station &s)
{
in>>s.name;
in>>s.num;//这个站点被哪些车次经过
for(int i=0; i<s.num; i++)
{
Train_information TT;
in>>TT;
s.T.push_back(TT);
}
return in;
}
ostream&operator<<(ostream &os,Station &s)
{
os<<s.name<<" ";
os<<s.num;
os<<endl;
for(int i=0; i<s.num; i++)
{
os<<s.T[i];
os<<endl;
}
return os;
}
class Train_number//车次
{
string number;
string from;
string to;
int num;//站点数量
vector<Train_information>T;
public:
Train_number()
{
num=0;
}
friend ostream&operator<<(ostream &os,Train_number &t);
friend istream&operator>>(istream &in,Train_number &t);
void deleteInformation(){T.clear();};
string getNumber(){return number;};
};
istream&operator>>(istream &in,Train_number &t)
{
in>>t.number;
in>>t.from;
in>>t.to;
in>>t.num;
for(int i=0; i<t.num; i++)
{
Train_information TT;
in>>TT;
t.T.push_back(TT);
}
return in;
}
ostream&operator<<(ostream &os,Train_number &t)
{
os<<t.number<<" ";
os<<t.from<<" ";
os<<t.to<<" ";
os<<t.num;
os<<endl;
for(int i=0; i<t.num; i++)
{
os<<t.T[i];
os<<endl;
}
return os;
}
class AdminOp
{
vector<Station>s;
vector<Train_number>t;
public:
void searchStation();
void searchTrain_number();
};
class ClientOp
{
vector<Station>s;
vector<Station>::iterator it1;
multimap<string,int>m1;
multimap<string,int>::iterator m1p;
vector<Train_number>t;
vector<Train_number>::iterator it2 ;
multimap<string,int>m2;
multimap<string,int>::iterator m2p;
public:
ClientOp()
{
load1();
load2();
}
~ClientOp()
{
save1();
save2();
}
void load1();
void load2();
void save1();
void save2();
void searchBase();
void searchTime();
void searchStation();
void searchTrain_number();
int searchS(string where);
int searchT(string number);
void display();
};
int ClientOp::searchS(string where)
{
m1p=m1.find(where);
if(m1p!=m1.end())
{
int i=m1p->second;
return i;
}
else return -1;
}
int ClientOp::searchT(string number)
{
m2p=m2.find(number);
if(m2p!=m2.end())
{
int i=m2p->second;
return i;
}
else return -1;
}
void ClientOp::searchStation()
{
cout<<"您想查询的站点为\n";
string where;
cin>>where;
cout<<s[searchS(where)];
}
void ClientOp::searchTrain_number()
{
cout<<"您想查询的车次为\n";
string number;
cin>>number;
if(searchS(number)==-1)
cout<<"没找到\n";
else
{
cout<<t[searchS(number)];
}
}
void ClientOp::display()
{
for(it2=t.begin(); it2!=t.end(); it2++)
{
cout<<*it2;
}
}
void ClientOp::load1()
{
int i;
Train_number tt;
ifstream infile("e:\\train.txt",ios::in);
if(!infile)
return;
t.clear();
i=0;
while(infile>>tt)
{
t.push_back(tt);
cout<<tt;
m2.insert(make_pair(tt.getNumber(),i));
i++;
tt.deleteInformation();
}
infile.close();
}
void ClientOp::load2()
{
int i;
Station ss;
ifstream infile("e:\\station.txt",ios::in);
if(!infile)
return;
s.clear();
i=0;
while(infile>>ss)
{
s.push_back(ss);
cout<<ss;
m1.insert(make_pair(ss.getName(),i));
i++;
ss.deleteInformation();
}
infile.close();
}
void ClientOp::save1()
{
ofstream outfile("e:\\train.txt",ios::out);
if(!outfile)
return;
for(it2=t.begin(); it2!=t.end(); it2++)
{
outfile<<*it2;
}
outfile.close();
}
void ClientOp::save2()
{
ofstream outfile("e:\\station.txt",ios::out);
if(!outfile)
return;
for(it1=s.begin(); it1!=s.end(); it1++)
{
outfile<<*it1;
}
outfile.close();
}
int main()
{
ClientOp c;
c.searchStation();
using namespace std;
class Time
{
int hour;
int minute;
public:
Time(int v,int m ):hour(v),minute(m) {}
Time()
{
hour=0;
minute=0;
}
int getHour()
{
return hour;
};
int getMinute()
{
return minute;
};
bool operator<(const Time&d)const
{
return hour!=d.hour?hour<d.hour:minute<d.minute;
}
friend ostream&operator<<(ostream &os, const Time &d);
friend istream&operator>>(istream &in, Time &d);
};
ostream&operator<<(ostream &os,const Time &d)
{
os<<d.hour<<" "<<d.minute;
return os;
}
istream&operator>>(istream &in,Time &d)
{
in>>d.hour;
in>>d.minute;
return in;
}
class Train_information
{
string Train_number;
string Station;
Time from;
Time to;
public:
friend ostream&operator<<(ostream &os,Train_information &T);
friend istream&operator>>(istream &in,Train_information &T);
};
istream&operator>>(istream &in,Train_information &T)
{
in>>T.Train_number;
in>>T.Station;
in>>T.from;
in>>T.to;
return in;
}
ostream&operator<<(ostream &os,Train_information &T)
{
os<<T.Train_number<<" ";
os<<T.Station<<" ";
os<<T.from<<" ";
os<<T.to<<" ";
return os;
}
class Station
{
string name;
int num;//数目
vector<Train_information>T;
public:
Station()
{
num=0;
}
friend ostream&operator<<(ostream &os,Station &s);
friend istream&operator>>(istream &in,Station &s);
void deleteInformation(){T.clear();}
};
istream&operator>>(istream &in,Station &s)
{
in>>s.name;
in>>s.num;//这个站点被哪些车次经过
for(int i=0; i<s.num; i++)
{
Train_information TT;
in>>TT;
s.T.push_back(TT);
}
return in;
}
ostream&operator<<(ostream &os,Station &s)
{
os<<s.name<<" ";
os<<s.num;
os<<endl;
for(int i=0; i<s.num; i++)
{
os<<s.T[i];
os<<endl;
}
return os;
}
class Train_number//车次
{
string number;
string from;
string to;
int num;//站点数量
vector<Train_information>T;
public:
Train_number()
{
num=0;
}
friend ostream&operator<<(ostream &os,Train_number &t);
friend istream&operator>>(istream &in,Train_number &t);
void deleteInformation(){T.clear();}
};
istream&operator>>(istream &in,Train_number &t)
{
in>>t.number;
in>>t.from;
in>>t.to;
in>>t.num;
for(int i=0; i<t.num; i++)
{
Train_information TT;
in>>TT;
t.T.push_back(TT);
}
return in;
}
ostream&operator<<(ostream &os,Train_number &t)
{
os<<t.number<<" ";
os<<t.from<<" ";
os<<t.to<<" ";
os<<t.num;
os<<endl;
for(int i=0; i<t.num; i++)
{
os<<t.T[i];
os<<endl;
}
return os;
}
class AdminOp
{
vector<Station>s;
vector<Train_number>t;
public:
void searchStation();
void searchTrain_number();
};
class ClientOp
{
vector<Station>s;
vector<Station>::iterator it1;
multimap<string,int>m1;
multimap<string,int>::iterator m1p;
vector<Train_number>t;
vector<Train_number>::iterator it2 ;
multimap<string,int>m2;
multimap<string,int>::iterator m2p;
public:
ClientOp()
{
load1();
load2();
}
~ClientOp()
{
save1();
save2();
}
void load1();
void load2();
void save1();
void save2();
void searchBase();
void searchTime();
void searchStation();
void searchTrain_number();
int searchS(string where);
int searchT(string number);
void display();
};
int ClientOp::searchS(string where)
{
m1p=m1.find(where);
if(m1p!=m1.end())
{
int i=m1p->second;
return i;
}
else return -1;
}
void searchT()
{
void ClientOp::searchStation()
{
cout<<"您想查询的站点为\n";
string where;
cin>>where;
void ClientOp::display()
{
for(it2=t.begin(); it2!=t.end(); it2++)
{
cout<<*it2;
}
}
void ClientOp::load1()
{
int i;
Train_number tt;
ifstream infile("e:\\train.txt",ios::in);
if(!infile)
return;
t.clear();
i=0;
while(infile>>tt)
{
t.push_back(tt);
cout<<tt;
// t1.insert(make_pair(tt.getNo(),i));
i++;
//tt.deleteS();
}
infile.close();
}
void ClientOp::load2()
{
int i;
Station ss;
ifstream infile("e:\\station.txt",ios::in);
if(!infile)
return;
s.clear();
i=0;
while(infile>>ss)
{
s.push_back(ss);
cout<<ss;
m1.insert(make_pair(ss.getNo(),i));
i++;
ss.deleteInformation();
}
infile.close();
}
void ClientOp::save1()
{
ofstream outfile("e:\\train.txt",ios::out);
if(!outfile)
return;
for(it2=t.begin(); it2!=t.end(); it2++)
{
outfile<<*it2;
}
outfile.close();
}
void ClientOp::save2()
{
ofstream outfile("e:\\station.txt",ios::out);
if(!outfile)
return;
for(it1=s.begin(); it1!=s.end(); it1++)
{
outfile<<*it1;
}
outfile.close();
}
int main()
{
ClientOp c;
using namespace std;
class Time
{
int month;
int day;
int hour;
int minute;
public:
Time(int y,int z,int v,int m ):month(y),day(z),hour(v),minute(m){}
Time()
{
month=0;
day=0;
hour=0;
minute=0;
}
int getMonth(){return month;};
int getDay(){return day;};
int getHour(){return hour;};
int getMinute(){return minute;};
bool operator<(const Time&d)const
{
return month!=d.month?month<d.month:day!=d.day?day<d.day:hour!=d.hour?hour<d.hour:minute<d.minute;
}
bool operator==(const Time&d)const
{
return month==d.month&&day==d.day;
}
friend ostream&operator<<(ostream &os, const Time &d);
friend istream&operator>>(istream &in, Time &d);
};
ostream&operator<<(ostream &os,const Time &d)
{
os<<d.month<<" "<<d.day<<" "<<d.hour<<" "<<d.minute;
return os;
}
istream&operator>>(istream &in,Time &d)
{
in>>d.month;
in>>d.day;
in>>d.hour;
in>>d.minute;
return in;
}
class Station//站点信息
{
string here;
string ends1;
Time ends;
string begins1;
Time begins;
public:
Station(string here,string ends1,Time ends,string begins1,Time begins)
{
this->here=here;
this->ends1=ends1;
this->ends=ends;
this->begins=begins;
this->begins=begins;
}
Station(string here,string ends1,Time ends,string begins1)//缺省构造函数,为最后一步做准备
{
this->here=here;
this->ends1=ends1;
this->ends=ends;
this->begins1=begins1;
}
Station(){}
friend istream&operator>>(istream&in,Station&s);
friend ostream&operator<<(ostream&os,const Station&s);
string getHere(){return here;}
};
istream&operator>>(istream&in,Station&s)
{
in>>s.here;
if(s.here=="E")return in;
in>>s.ends1>>s.ends>>s.begins1;
/*
当最后一个站点时,没有发出时间不必输入
*/
in>>s.begins;
return in;
}
ostream&operator<<(ostream&os,const Station&s)
{
os<<s.here<<" "<<s.ends1<<" "<<s.ends<<" "<<s.begins1<<" "<<s.begins;
return os;
}
class Train//车次信息,包含站点信息
{
string no;
string from;
string to;
string type;
int num;//途经站点数目
Time begins;
Time ends;
vector<Station>s;//途经哪些站点+站点信息;要及时清空一下动态数组
vector<Station>::iterator it;
multimap<string,int>m;
multimap<string,int>::iterator m1;
public:
Train(string no1,string from1,string to1,string type1,Time t1,Time t2):no(no1),from(from1),to(to1),type(type1),begins(t1),ends(t2)
{
num=0;
int i=0;
for(it=s.begin();it!=s.end();it++)
{
m.insert(make_pair((*it).getHere(),i));
i++;
}
}
Train(){num=0;}
~Train(){s.clear();m.clear();}
friend ostream&operator<<(ostream &os,Train&c);
friend istream&operator>>(istream &in,Train&c);
string getNo(){return no;}
void deleteStation();
void addStation();
void deleteS(){s.clear();}
Time getBegins(){return begins;};//出发时间
Time getEnds(){return ends;};//到达时间
};
void Train::deleteStation()
{
cout<<"您想删除的站点名称及位置为,输入地点为E终止\n";
string where;
while(cin>>where)
{
if(where=="E")break;
m1=m.find(where);
s.erase(m1->second+s.begin());
}
}
void Train::addStation()
{
cout<<"您想增加的站点名称及位置为,输入地点为E终止\n";
Station where;//站点
int i;//站点信息;
cin>>i>>where;
//在s内的某位置插入某站点,并设定时间及此站点后的时间信息
s.insert(i+s.begin(),where);/
cout<<"成功添加\n";
}
istream&operator>>(istream &in,Train&c)
{
in>>c.no;
if(c.no=="E")return in;
in>>c.from>>c.to>>c.begins>>c.ends>>c.type;
in>>c.num;
for(int i=0;i<c.num;i++)
{
Station ss;
in>>ss;
c.s.push_back(ss);
}
return in;
}
ostream&operator<<(ostream &os,Train&c)
{
os<<c.no<<" "<<c.from<<" "<<c.to<<" "<<c.begins<<" "<<c.ends<<" "<<c.type<<endl;
os<<c.num<<endl;
for(int i=0;i<c.num;i++)
{
os<<c.s[i]<<endl;
}
c.s.clear();
return os;
}
class Adm
{
vector<Train>t;
vector<Train>::iterator it,it1;
multimap<string,int>t1;
multimap<string,int>::iterator t1p;
public:
Adm()
{
load1();
//load2();
}
~Adm()
{
save1();
//save2();
}
void load1();
void load2();
void save1();
void save2();
int searchNo(string no);
void addTrain();//增加车次
void deleteTrain();//删除车次
void addStation();//增加站点
void deleteStation();//删除站点
};
int Adm::searchNo(string no)
{
t1p=t1.find(no);
if(t1p!=t1.end())
{
int i=t1p->second;
return i;
}
else return -1;
}
void Adm::load1()
{
int i;
Train tt;
ifstream infile("e:\\Train.txt",ios::in);
if(!infile)
return;
t.clear();
i=0;
while(infile>>tt)
{
t.push_back(tt);
cout<<tt;
t1.insert(make_pair(tt.getNo(),i));
i++;
tt.deleteS();
}
infile.close();
}
void Adm::save1()
{
t1.clear();
ofstream outfile("e:\\Train.txt",ios::out);
if(!outfile)
return;
for(it=t.begin();it!=t.end();it++)
{
outfile<<*it;
}
outfile.close();
}
void Adm::addStation()
{
cout<<"您想在哪个车次增加及增加的站点信息为,输入车次为E终止\n";
string n;
while(1)
{
cin>>n;
if(n=="E")break;
int i=searchNo(n);//先找到这个车次
t[i].addStation();
}
}
void Adm::deleteStation()
{
cout<<"您想在哪个车次删除及删除的站点名称为,输入地点为E终止\n";
}
void Adm::addTrain()
{
cout<<"你想增加的车次信息为,输入车次序号为E终止\n";
Train tt;
while(1)
{
cin>>tt;
if(tt.getNo()=="E")break;
t.push_back(tt);
}
}
void Adm::deleteTrain()
{
cout<<"你想删除的车次信息为,输入车次序号为E终止\n";
string no;
while(1)
{
cin>>no;
if(no=="E")break;
int i=searchNo(no);
it1=t.begin()+i;
t.erase(it1);
}
}
class Client//按时间站点查询
{
vector<Train>t;//Train中包含了时间段
vector<Train>::iterator it;
public:
Client();
void display();
void searchTime();
void searchStation();
};
/*
找寻此要发出天的车次
*/
void Client::searchTime()
{
cout<<"您想查询的时间为\n";
int month;
int day;
cin>>month>>day;
Time tt(month,day,0,0);
for(it=t.begin();it!=t.end();it++)
{
if((*it).getEnds()==tt)
{
cout<<*it;
}
}//初级遍历法,需要提高效率;
}
void Client::searchStation()
{
cout<<"您想查询的站点为\n";
string where;
cin>>where;
}
void Client::display()
{
cout<<"There is all information\n";
for(it=t.begin();it!=t.end();it++)
{
cout<<*it;
}
}
Client::Client()
{
int i;
Train tt;
ifstream infile("e:\\Train.txt",ios::in);
if(!infile)
return;
t.clear();
i=0;
while(infile>>tt)
{
t.push_back(tt);
cout<<tt;
//u1.insert(make_pair(uu.getId(),i));
//u2.insert(make_pair(uu.getName(),i));
i++;
}
infile.close();
}
int main()
{
/*Time t(1,2,3,4);
cout<<t<<endl;
cin>>t;
cout<<t;
Station s;
cin>>s;
cout<<s;
Train tt;
cin>>tt;
cout<<tt;*/
Client c;
//c.display();
c.searchTime();
//Adm a;
//a.addTrain();
//a.deleteTrain();
//a.addStation();
}
using namespace std;
class Time
{
int month;
int day;
int hour;
int minute;
public:
Time(int y,int z,int v,int m ):month(y),day(z),hour(v),minute(m){}
Time()
{
month=0;
day=0;
hour=0;
minute=0;
}
int getMonth(){return month;};
int getDay(){return day;};
int getHour(){return hour;};
int getMinute(){return minute;};
bool operator<(const Time&d)const
{
return month!=d.month?month<d.month:day!=d.day?day<d.day:hour!=d.hour?hour<d.hour:minute<d.minute;
}
bool operator==(const Time&d)const
{
return month==d.month&&day==d.day;
}
friend ostream&operator<<(ostream &os, const Time &d);
friend istream&operator>>(istream &in, Time &d);
};
ostream&operator<<(ostream &os,const Time &d)
{
os<<d.month<<" "<<d.day<<" "<<d.hour<<" "<<d.minute;
return os;
}
istream&operator>>(istream &in,Time &d)
{
in>>d.month;
in>>d.day;
in>>d.hour;
in>>d.minute;
return in;
}
class Station//站点信息
{
string here;
string ends1;
Time ends;
string begins1;
Time begins;
public:
Station(string here,string ends1,Time ends,string begins1,Time begins)
{
this->here=here;
this->ends1=ends1;
this->ends=ends;
this->begins=begins;
this->begins=begins;
}
Station(string here,string ends1,Time ends,string begins1)//缺省构造函数,为最后一步做准备
{
this->here=here;
this->ends1=ends1;
this->ends=ends;
this->begins1=begins1;
}
Station(){}
friend istream&operator>>(istream&in,Station&s);
friend ostream&operator<<(ostream&os,const Station&s);
string getHere(){return here;}
};
istream&operator>>(istream&in,Station&s)
{
in>>s.here;
if(s.here=="E")return in;
in>>s.ends1>>s.ends>>s.begins1;
/*
当最后一个站点时,没有发出时间不必输入
*/
in>>s.begins;
return in;
}
ostream&operator<<(ostream&os,const Station&s)
{
os<<s.here<<" "<<s.ends1<<" "<<s.ends<<" "<<s.begins1<<" "<<s.begins;
return os;
}
class Train//车次信息,包含站点信息
{
string no;
string from;
string to;
string type;
int num;//途经站点数目
Time begins;
Time ends;
vector<Station>s;//途经哪些站点+站点信息;要及时清空一下动态数组
vector<Station>::iterator it;
multimap<string,int>m;
multimap<string,int>::iterator m1;
public:
Train(string no1,string from1,string to1,string type1,Time t1,Time t2):no(no1),from(from1),to(to1),type(type1),begins(t1),ends(t2)
{
num=0;
int i=0;
for(it=s.begin();it!=s.end();it++)
{
m.insert(make_pair((*it).getHere(),i));
i++;
}
}
Train(){num=0;}
~Train(){s.clear();m.clear();}
friend ostream&operator<<(ostream &os,Train&c);
friend istream&operator>>(istream &in,Train&c);
string getNo(){return no;}
void deleteStation();
void addStation();
void deleteS(){s.clear();}
Time getBegins(){return begins;};//出发时间
Time getEnds(){return ends;};//到达时间
};
void Train::deleteStation()
{
cout<<"您想删除的站点名称及位置为,输入地点为E终止\n";
string where;
while(cin>>where)
{
if(where=="E")break;
m1=m.find(where);
s.erase(m1->second+s.begin());
}
}
void Train::addStation()
{
cout<<"您想增加的站点名称及位置为,输入地点为E终止\n";
Station where;//站点
int i;//站点信息;
cin>>i>>where;
//在s内的某位置插入某站点,并设定时间及此站点后的时间信息
s.insert(i+s.begin(),where);/
cout<<"成功添加\n";
}
istream&operator>>(istream &in,Train&c)
{
in>>c.no;
if(c.no=="E")return in;
in>>c.from>>c.to>>c.begins>>c.ends>>c.type;
in>>c.num;
for(int i=0;i<c.num;i++)
{
Station ss;
in>>ss;
c.s.push_back(ss);
}
return in;
}
ostream&operator<<(ostream &os,Train&c)
{
os<<c.no<<" "<<c.from<<" "<<c.to<<" "<<c.begins<<" "<<c.ends<<" "<<c.type<<endl;
os<<c.num<<endl;
for(int i=0;i<c.num;i++)
{
os<<c.s[i]<<endl;
}
c.s.clear();
return os;
}
class Adm
{
vector<Train>t;
vector<Train>::iterator it,it1;
multimap<string,int>t1;
multimap<string,int>::iterator t1p;
public:
Adm()
{
load1();
//load2();
}
~Adm()
{
save1();
//save2();
}
void load1();
void load2();
void save1();
void save2();
int searchNo(string no);
void addTrain();//增加车次
void deleteTrain();//删除车次
void addStation();//增加站点
void deleteStation();//删除站点
};
int Adm::searchNo(string no)
{
t1p=t1.find(no);
if(t1p!=t1.end())
{
int i=t1p->second;
return i;
}
else return -1;
}
void Adm::load1()
{
int i;
Train tt;
ifstream infile("e:\\Train.txt",ios::in);
if(!infile)
return;
t.clear();
i=0;
while(infile>>tt)
{
t.push_back(tt);
cout<<tt;
t1.insert(make_pair(tt.getNo(),i));
i++;
tt.deleteS();
}
infile.close();
}
void Adm::save1()
{
t1.clear();
ofstream outfile("e:\\Train.txt",ios::out);
if(!outfile)
return;
for(it=t.begin();it!=t.end();it++)
{
outfile<<*it;
}
outfile.close();
}
void Adm::addStation()
{
cout<<"您想在哪个车次增加及增加的站点信息为,输入车次为E终止\n";
string n;
while(1)
{
cin>>n;
if(n=="E")break;
int i=searchNo(n);//先找到这个车次
t[i].addStation();
}
}
void Adm::deleteStation()
{
cout<<"您想在哪个车次删除及删除的站点名称为,输入地点为E终止\n";
}
void Adm::addTrain()
{
cout<<"你想增加的车次信息为,输入车次序号为E终止\n";
Train tt;
while(1)
{
cin>>tt;
if(tt.getNo()=="E")break;
t.push_back(tt);
}
}
void Adm::deleteTrain()
{
cout<<"你想删除的车次信息为,输入车次序号为E终止\n";
string no;
while(1)
{
cin>>no;
if(no=="E")break;
int i=searchNo(no);
it1=t.begin()+i;
t.erase(it1);
}
}
class Client//按时间站点查询
{
vector<Train>t;//Train中包含了时间段
vector<Train>::iterator it;
public:
Client();
void display();
void searchTime();
void searchStation();
};
/*
找寻此要发出天的车次
*/
void Client::searchTime()
{
cout<<"您想查询的时间为\n";
int month;
int day;
cin>>month>>day;
Time tt(month,day,0,0);
for(it=t.begin();it!=t.end();it++)
{
if((*it).getEnds()==tt)
{
cout<<*it;
}
}//初级遍历法,需要提高效率;
}
void Client::searchStation()
{
cout<<"您想查询的站点为\n";
string where;
cin>>where;
}
void Client::display()
{
cout<<"There is all information\n";
for(it=t.begin();it!=t.end();it++)
{
cout<<*it;
}
}
Client::Client()
{
int i;
Train tt;
ifstream infile("e:\\Train.txt",ios::in);
if(!infile)
return;
t.clear();
i=0;
while(infile>>tt)
{
t.push_back(tt);
cout<<tt;
//u1.insert(make_pair(uu.getId(),i));
//u2.insert(make_pair(uu.getName(),i));
i++;
}
infile.close();
}
int main()
{
/*Time t(1,2,3,4);
cout<<t<<endl;
cin>>t;
cout<<t;
Station s;
cin>>s;
cout<<s;
Train tt;
cin>>tt;
cout<<tt;*/
Client c;
//c.display();
c.searchTime();
//Adm a;
//a.addTrain();
//a.deleteTrain();
//a.addStation();
}
#include<bits/stdc++.h>
using namespace std;
class Time
{
int month;
int day;
int hour;
int minute;
public:
Time(int y,int z,int v,int m ):month(y),day(z),hour(v),minute(m){}
Time(){}
int getMonth(){return month;};
int getDay(){return day;};
int getHour(){return hour;};
int getMinute(){return minute;};
bool operator<(const Time&d)const
{
return month!=d.month?month<d.month:day!=d.day?day<d.day:hour!=d.hour?hour<d.hour:minute<d.minute;
}
friend ostream&operator<<(ostream &os, const Time &d);
friend istream&operator>>(istream &in, Time &d);
};
ostream&operator<<(ostream &os,const Time &d)
{
os<<d.month<<" "<<d.day<<" "<<d.hour<<" "<<d.minute;
return os;
}
istream&operator>>(istream &in,Time &d)
{
in>>d.month;
in>>d.day;
in>>d.hour;
in>>d.minute;
return in;
}
class Station//站点信息
{
Time ends;
Time begins;
string ends1;
string begins1;
string here;
public:
Station(Time ends1,Time begins1,string here1):ends(ends1),begins(begins1),here(here1){}
Station(){}
friend istream&operator>>(istream&in,Station&s);
friend ostream&operator<<(ostream&os,const Station&s);
string getHere(){return here;}
};
istream&operator>>(istream&in,Station&s)
{
in>>s.here;
if(s.here=="E")return in;
in>>s.ends1>>s.ends>>s.begins1>>s.begins;
return in;
}
ostream&operator<<(ostream&os,const Station&s)
{
os<<s.here<<" "<<s.ends1<<" "<<s.ends<<" "<<s.begins1<<" "<<s.begins;
return os;
}
class Train//车次信息
{
string no;
string from;
string to;
string type;
int num;//途经站点数目
Time begins;
Time ends;
vector<Station>s;//途经哪些站点+站点信息;
vector<Station>::iterator it;
multimap<string,int>m;
multimap<string,int>::iterator m1;
public:
Train(string no1,string from1,string to1,string type1,Time t1,Time t2):no(no1),from(from1),to(to1),type(type1),begins(t1),ends(t2)
{
num=0;
int i=0;
for(it=s.begin();it!=s.end();it++)
{
m.insert(make_pair((*it).getHere(),i));
i++;
}
}
Train(){num=0;}
~Train(){s.clear();}
friend ostream&operator<<(ostream &os,Train&c);
friend istream&operator>>(istream &in,Train&c);
string getNo(){return no;}
void deleteStation();
void addStation();
};
void Train::deleteStation()
{
cout<<"您想删除的站点名称及位置为,输入地点为E终止\n";
string where;
while(cin>>where)
{
if(where=="E")break;
m1=m.find(where);
s.erase(m1->second+s.begin());
}
}
void Train::addStation()
{
cout<<"您想增加的站点名称及位置为,输入地点为E终止\n";
string where;
}
istream&operator>>(istream &in,Train&c)
{
in>>c.no;
if(c.no=="E")return in;
in>>c.from>>c.to>>c.begins>>c.ends>>c.type;
in>>c.num;
for(int i=0;i<c.num;i++)
{
Station ss;
in>>ss;
c.s.push_back(ss);
}
return in;
}
ostream&operator<<(ostream &os,Train&c)
{
os<<c.no<<" "<<c.from<<" "<<c.to<<" "<<c.begins<<" "<<c.ends<<" "<<c.type<<endl;
os<<c.num<<endl;
for(int i=0;i<c.num;i++)
{
os<<c.s[i]<<endl;
}
c.s.clear();
return os;
}
class Adm
{
vector<Train>t;
vector<Train>::iterator it,it1;
multimap<string,int>t1;
multimap<string,int>::iterator t1p;
public:
Adm()
{
load1();
//load2();
}
~Adm()
{
save1();
//save2();
}
void load1();
void load2();
void save1();
void save2();
int searchNo(string no);
void addTrain();//增加车次
void deleteTrain();//删除车次
void addStation();//增加站点
void deleteStation();//删除站点
};
int Adm::searchNo(string no)
{
t1p=t1.find(no);
if(t1p!=t1.end())
{
int i=t1p->second;
return i;
}
else return -1;
}
void Adm::load1()
{
int i;
Train tt;
ifstream infile("e:\\Train.txt",ios::in);
if(!infile)
return;
t.clear();
i=0;
while(infile>>tt)
{
t.push_back(tt);
t1.insert(make_pair(tt.getNo(),i));
i++;
}
infile.close();
}
void Adm::save1()
{
t1.clear();
ofstream outfile("e:\\Train.txt",ios::out);
if(!outfile)
return;
for(it=t.begin();it!=t.end();it++)
{
outfile<<*it;
}
outfile.close();
}
void Adm::addStation()
{
cout<<"您想在哪个车次增加及增加的站点名称为,输入地点为E终止\n";
Station s;
while(1)
{
cin>>s;
if(s.getHere()=="E")break;
}
}
void Adm::deleteStation()
{
cout<<"您想在哪个车次删除及删除的站点名称为,输入地点为E终止\n";
}
void Adm::addTrain()
{
cout<<"你想增加的车次信息为,输入车次序号为E终止\n";
Train tt;
while(1)
{
cin>>tt;
if(tt.getNo()=="E")break;
t.push_back(tt);
}
}
void Adm::deleteTrain()
{
cout<<"你想删除的车次信息为,输入车次序号为E终止\n";
string no;
while(1)
{
cin>>no;
if(no=="E")break;
int i=searchNo(no);
it1=t.begin()+i;
t.erase(it1);
}
}
class Client
{
vector<Train>t;
vector<Train>::iterator it;
public:
Client();
void display();
};
void Client::display()
{
cout<<"There is all information\n";
for(it=t.begin();it!=t.end();it++)
{
cout<<*it;
}
}
Client::Client()
{
int i;
Train tt;
ifstream infile("e:\\Train.txt",ios::in);
if(!infile)
return;
t.clear();
i=0;
while(infile>>tt)
{
t.push_back(tt);
//u1.insert(make_pair(uu.getId(),i));
//u2.insert(make_pair(uu.getName(),i));
i++;
}
infile.close();
}
int main()
{
/*Time t(1,2,3,4);
cout<<t<<endl;
cin>>t;
cout<<t;
Station s;
cin>>s;
cout<<s;
Train tt;
cin>>tt;
cout<<tt;
Client c;
c.display();
*/
Adm a;
//a.addTrain();
a.deleteTrain();
}
#include<bits/stdc++.h>
using namespace std;class Time
{
int month;
int day;
int hour;
int minute;
public:
Time(int y,int z,int v,int m ):month(y),day(z),hour(v),minute(m){}
Time(){}
int getMonth(){return month;};
int getDay(){return day;};
int getHour(){return hour;};
int getMinute(){return minute;};
bool operator<(const Time&d)const
{
return month!=d.month?month<d.month:day!=d.day?day<d.day:hour!=d.hour?hour<d.hour:minute<d.minute;
}
friend ostream&operator<<(ostream &os, const Time &d);
friend istream&operator>>(istream &in, Time &d);
};
ostream&operator<<(ostream &os,const Time &d)
{
os<<d.month<<" "<<d.day<<" "<<d.hour<<" "<<d.minute;
return os;
}
istream&operator>>(istream &in,Time &d)
{
in>>d.month;
in>>d.day;
in>>d.hour;
in>>d.minute;
return in;
}
class Station//站点信息
{
Time ends;
Time begins;
string ends1;
string begins1;
string here;
public:
Station(Time ends1,Time begins1,string here1):ends(ends1),begins(begins1),here(here1){}
Station(){}
friend istream&operator>>(istream&in,Station&s);
friend ostream&operator<<(ostream&os,const Station&s);
string getW(){return here;}
};
istream&operator>>(istream&in,Station&s)
{
in>>s.here>>s.ends1>>s.ends>>s.begins1>>s.begins;
return in;
}
ostream&operator<<(ostream&os,const Station&s)
{
os<<s.here<<" "<<s.ends1<<" "<<s.ends<<" "<<s.begins1<<" "<<s.begins;
return os;
}
class Train//车次信息
{
string no;
string from;
string to;
string type;
int num;//途经站点数目
Time begins;
Time ends;
vector<Station>s;//途经哪些站点+站点信息;
public:
Train(string no1,string from1,string to1,string type1,Time t1,Time t2):no(no1),from(from1),to(to1),type(type1),begins(t1),ends(t2){num=0;}
Train(){num=0;}
~Train(){s.clear();}
friend ostream&operator<<(ostream &os,Train&c);
friend istream&operator>>(istream &in,Train&c);
string getNo(){return no;}
void deleteStation();
};
void Train::deleteStation()
{
cout<<"您想增加的站点名称及位置为,输入地点为E终止\n";
Station where;
int i;
while(cin>>where)
{
cin>>i;
if(where.getW()=="E")break;
s.insert(i,where);
}
}
istream&operator>>(istream &in,Train&c)
{
in>>c.no;
if(c.no=="E")return in;
in>>c.from>>c.to>>c.begins>>c.ends>>c.type;
in>>c.num;
for(int i=0;i<c.num;i++)
{
Station ss;
in>>ss;
c.s.push_back(ss);
}
return in;
}
ostream&operator<<(ostream &os,Train&c)
{
os<<c.no<<" "<<c.from<<" "<<c.to<<" "<<c.begins<<" "<<c.ends<<" "<<c.type<<endl;
os<<c.num<<endl;
for(int i=0;i<c.num;i++)
{
os<<c.s[i]<<endl;
}
c.s.clear();
return os;
}
class Adm
{
vector<Train>t;
vector<Train>::iterator it,it1;
multimap<string,int>t1;
multimap<string,int>::iterator t1p;
public:
Adm()
{
load1();
//load2();
}
~Adm()
{
save1();
//save2();
}
void load1();
void load2();
void save1();
void save2();
int searchNo(string no);
void addTrain();//增加车次
void deleteTrain();//删除车次
void addStation();//增加站点
void deleteStation();//删除站点
};
int Adm::searchNo(string no)
{
t1p=t1.find(no);
if(t1p!=t1.end())
{
int i=t1p->second;
return i;
}
else return -1;
}
void Adm::load1()
{
int i;
Train tt;
ifstream infile("e:\\Train.txt",ios::in);
if(!infile)
return;
t.clear();
i=0;
while(infile>>tt)
{
t.push_back(tt);
t1.insert(make_pair(tt.getNo(),i));
i++;
}
infile.close();
}
void Adm::save1()
{
t1.clear();
ofstream outfile("e:\\Train.txt",ios::out);
if(!outfile)
return;
for(it=t.begin();it!=t.end();it++)
{
outfile<<*it;
}
outfile.close();
}
void Adm::addStation()
{
cout<<"您想增加的站点名称为,输入地点为E终止\n";
}
void Adm::deleteStation()
{
cout<<"您想删除的站点名称为,输入地点为E终止\n";
}
void Adm::addTrain()
{
cout<<"你想增加的车次信息为,输入车次序号为E终止\n";
Train tt;
while(1)
{
cin>>tt;
if(tt.getNo()=="E")break;
t.push_back(tt);
}
}
void Adm::deleteTrain()
{
cout<<"你想删除的车次信息为,输入车次序号为E终止\n";
string no;
while(1)
{
cin>>no;
if(no=="E")break;
int i=searchNo(no);
it1=t.begin()+i;
t.erase(it1);
}
}
class Client
{
vector<Train>t;
vector<Train>::iterator it;
public:
Client();
void display();
};
void Client::display()
{
cout<<"There is all information\n";
for(it=t.begin();it!=t.end();it++)
{
cout<<*it;
}
}
Client::Client()
{
int i;
Train tt;
ifstream infile("e:\\Train.txt",ios::in);
if(!infile)
return;
t.clear();
i=0;
while(infile>>tt)
{
t.push_back(tt);
//u1.insert(make_pair(uu.getId(),i));
//u2.insert(make_pair(uu.getName(),i));
i++;
}
infile.close();
}
int main()
{
/*Time t(1,2,3,4);
cout<<t<<endl;
cin>>t;
cout<<t;
Station s;
cin>>s;
cout<<s;
Train tt;
cin>>tt;
cout<<tt;
Client c;
c.display();
*/
Adm a;
//a.addTrain();
a.deleteTrain();
}