#include <iostream>
#include <cstring>
#include <algorithm>
using namespace std;
//航班号 起点站 终点站 航班期 起飞时间 到达时间 机型 票价
class Flight{
public:
char Pname[20];
char Start[20];
char End[20];
char Period[20];
int Stime;
int Atime;
char Pstyle[20];
int Price;
friend istream& operator>>(istream& in,Flight& obj){
cout<<"航班号:";
in>>obj.Pname;
cout<<"起点站:";
in>>obj.Start;
cout<<"终点站:";
in>>obj.End;
cout<<"航班期:";
in>>obj.Period;
cout<<"起飞时间:";
in>>obj.Stime;
cout<<"到达时间:";
in>>obj.Atime;
cout<<"机型 :";
in>>obj.Pstyle;
cout<<"票价:";
in>>obj.Price;
}
friend ostream& operator<<(ostream& out,Flight& obj) {
out<<"航班号:"<<obj.Pname<<endl;
out<<"起点站:"<<obj.Start<<endl;
out<<"终点站:"<<obj.End<<endl;
out<<"航班期:"<<obj.Period<<endl;
out<<"起飞时间:"<<obj.Stime<<endl;
if(obj.Stime>obj.Atime)
out<<"到达时间:"<<obj.Atime<<"+1"<<endl;
else out<<"到达时间:"<<obj.Atime<<endl;
out<<"机型 :"<<obj.Pstyle<<endl;
out<<"票价:"<<obj.Price<<endl;
}
};
class Plane{
private:
Flight f[1000];
int sum;//当前航班总数
int maxsize;//飞机场航班最大数量
public:
Plane(){
maxsize=1000;
sum=0;
}
bool Insert();
bool Find();
bool Sort();
bool Modify();
};
bool Plane::Insert(){
if(sum>=maxsize){
cout<<"已满,无法安排新航班\n";
return false;
}
else{
Flight fnew;
cin>>fnew;
f[sum++]=fnew;
return true;
}
}
bool Plane::Find(){
char s[20],e[20];
cout<<"起点:";cin>>s;
cout<<"终点:";cin>>e;
for(int i=0;i<sum;i++){
if(strcmp(s,f[i].Start)==0&&strcmp(e,f[i].End)==0){
cout<<f[i];
}
}
return true;
}
int cmp(Flight a,Flight b){
return a.Stime<b.Stime;
}
bool Plane::Sort(){
sort(f,f+sum,cmp);
return true;
}
bool Plane::Modify(){
char no[20];
cout<<"输入航班号:";
Flight fnew;
cin>>fnew;
for(int i=0;i<sum;i++){
if(strcmp(no,f[i].Pname)==0){
f[i]=fnew;
return true;
}
}
cout<<"不能找到该航班"<<endl;
return false;
}
int main(){
Plane q;
int n;//选择选项 n=0 退出
printf("菜单内容:\n\
1、 航班信息录入\n\
2、 航班信息查询\n\
3、 航班信息修改\n\
4、 航班信息排序\n\
5、 结束程序\n");
cout<<"请输入选项:";
cin>>n;
while(n!=6) {
switch(n) {
case 1:
int sn;
cout<<"输入插入的航班数:";
cin>>sn;
while(sn--)q.Insert();
break;
case 2:
q.Find();
break;
case 3:
q.Modify();
break;
case 4:
q.Sort();
break;
case 6:
cout<<"成功退出"<<endl;
return 0;
default:
cout<<"输入选项错误,请核对后输入\n";
}
cout<<"本功能已完成,请继续输入:";
cin>>n;
}
return 0;
}