1.已知一个航空管理员操作类的数据成员如下:
Class Flightlnfo
{
stringNo ; 航班号
stringStartCity ;起飞地点
stringEndCity ;降落地点
stringStartDate ;日期
stringStartTime ; 起飞时间
stringEndTime ;降落时间
intFirstTicket ;头等舱剩余票数
intFirstPrice ;头等舱价格
intSecondTicket ;经济舱剩余票数
intSecondPrice ;经济价格
public :...
}
编程要求:
(1)完成这个类的定义,要求:
a .具有两个参数的构造函数,参数分别为航班号和日期,实现航空管理员对
航班的新建、修改、删除等操作;
b .设置航班起飞的日期和时间、头等舱/经济舱的价格和剩余票数、出发地
和目的地、航班号。
(2)定义一个 FlightManager 类用来管理航班信息,实现增加、编辑、删除航班的供能。
2022.3.10
#include<iostream>
#include<string>
using namespace std;
class FlightInfo //航班的各种信息
{
string No;
string StartCity;
string EndCity;
string StartDate;
string StartTime;
string EndTime;
int FirstTicket;
int FirstPrice;
int SecondTicket;
int SecondPrice;
public:
FlightInfo(string no,string startdate);
void setNo(string a) {No=a;}
string getNo() {return No;}
void setStartCity(string b) {StartCity=b;}
string getStartCity() {return StartCity;}
void setEndCity(string c) {EndCity=c;}
string getEndCity() {return EndCity;}
void setStartDate(string d) {StartDate=d;}
string getStartDate() {return StartDate;}
void setStartTime(string e) {StartTime=e;}
string getStartTime() {return StartTime;}
void setEndTime(string f) {EndTime=f;}
string getEndTime() {return EndTime;}
void setFirstTicket(int g) {FirstTicket=g;}
int getFirstTicket() {return FirstTicket;}
void setFirstPrice(int h) {FirstPrice=h;}
int getFirstPrice() {return FirstPrice;}
void setSecondTicket(int i) {SecondTicket=i;}
int getSecondTicket() {return SecondTicket;}
void setSecondPrice(int j) {SecondPrice=j;}
int getSecondPrice() {return SecondPrice;}
}*flight[1000];
class FlightManager//管理航班的类
{
public:
void addFlight();
void deleteFlight();
void changeFlight();
};
FlightInfo::FlightInfo(string no,string startdate)//具有两个参数(航班号和日期)的构造函数
{
No=no;
StartDate=startdate;
cout<<"请输入起飞的时间:";
cin>>StartTime;
cout<<"请输入降落的时间:";
cin>>EndTime;
cout<<"请输入出发地:";
cin>>StartCity;
cout<<"请输入目的地:";
cin>>EndCity;
cout<<"请输入头等舱剩余票数:";
cin>>FirstTicket;
cout<<"请输入头等舱价格:";
cin>>FirstPrice;
cout<<"请输入经济舱剩余票数:";
cin>>SecondTicket;
cout<<"请输入经济舱价格:";
cin>>SecondPrice;
}
int i=0;
void FlightManager::addFlight()//添加航班
{
string m,n;
cout<<"请输入航班号和日期:";
cin>>m;
cin.ignore();
cin>>n;
flight[i]=new FlightInfo(m,n);
i++;
cout<<"添加成功!"<<endl;
}
void FlightManager::changeFlight()//编辑航班
{
int j;
string NO;
string no;
string startCity;
string endCity;
string startDate;
string startTime;
string endTime;
int firstTicket;
int firstPrice;
int secondTicket;
int secondPrice;
cout<<"请输入要更改的航班号:";
cin>>NO;
for(j=0;j<i;j++)
{
if(NO==flight[j]->getNo())
{
cout<<"请输入新的航班号:";
cin>>no;
flight[j]->setNo(no);
cout<<"请输入新的日期:";
cin>>startDate;
flight[j]->setStartDate(startDate);
cout<<"请输入起飞的时间:";
cin>>startTime;
flight[j]->setStartTime(startTime);
cout<<"请输入降落的时间:";
cin>>endTime;
flight[j]->setEndTime(endTime);
cout<<"请输入出发地:";
cin>>startCity;
flight[j]->setStartCity(startCity);
cout<<"请输入目的地:";
cin>>endCity;
flight[j]->setEndCity(endCity);
cout<<"请输入头等舱剩余票数:";
cin>>firstTicket;
flight[j]->setFirstTicket(firstTicket);
cout<<"请输入头等舱价格:";
cin>>firstPrice;
flight[j]->setFirstPrice(firstPrice);
cout<<"请输入经济舱剩余票数:";
cin>>secondTicket;
flight[j]->setSecondTicket(secondTicket);
cout<<"请输入经济舱价格:";
cin>>secondPrice;
flight[j]->setSecondPrice(secondPrice);
cout<<"修改成功!"<<endl;
break;
}
}
if(j==i)
{
cout<<"没有该航班!"<<endl;
}
}
void FlightManager::deleteFlight()//删除航班
{
int j,m;
string no;
cout<<"请输入要删除的航班号:";
cin>>no;
for(j=0;j<i;j++)
{
if(no==flight[j]->getNo())
{
cout<<"删除成功!"<<endl;
for(m=j;m<i;m++)//将m之后的向前替换,删除最后一个
{
flight[m]=flight[m+1];
}
delete flight[i];
break;
}
}
if(j==i)
{
cout<<"没有该航班!"<<endl;
}
i--;
}
void menu(FlightManager &t) //菜单
{
int ch;
while(1)
{
cout<<"请选择:"<<endl;
cout<<"1:添加航班"<<endl;
cout<<"2.删除航班"<<endl;
cout<<"3.修改航班"<<endl;
cout<<"4.退出系统"<<endl;
cin>>ch;
if((ch<=4) && (ch>=1))
{
switch(ch)
{
case 1:t.addFlight();break;
case 2:t.deleteFlight();break;
case 3:t.changeFlight();break;
case 4:exit(0);break;
}
}
else
{
cout<<"输入错误";
}
}
}
int main()
{
FlightManager t;
while(1)
{
menu(t);
}
return 0;
}