一、基本功能要求: |
1)假设该民航有若干航班,要求实现增加航班和取消某个航班的,修改航 班功能。 2)查询:根据用户提出的终点站查询航班号、售票情况等航班信息;也可 根据航班号,列出该航班已订票的乘客名单。 3)订票:根据航班号为客户订票,如该航班有余票,则为客户订票;如该 航班已满员,则显示相应信息。 4)退票:按乘客要求退出已预定的机票。 5)飞行时刻查询:显示航班的起飞降落时间。 |
提示: |
航班信息:航班号、到达港、总座位数、余票额、乘客名单; 乘客信息:乘客姓名、证件号码、座位号。 |
技术要求: |
1、使用类; 2、使用向量 3、数据存储在文件中。 4、DOS 版 / WINDOWS 版 |
/文件名称:Time.h
/功能介绍:定义了时间类
时间信息:时,分,秒;
作者:lonely
///
#include<iostream>
using namespace std;
class Time
{
protected:
int hour;//0~23
int minute;//0~59
int second;//0~59
public:
int getHour(){return hour;}
int getminute(){return minute;}
int getsecond(){return second;}
friend ostream &operator<<(ostream& output,Time &p);//重载函数《
friend istream &operator>>(istream& input,Time &p);//重载函数>>
Time():hour(0),minute(0),second(0){}//构造函数
Time(int h,int m,int s):hour(h),minute(m),second(s){}//构造函数
Time &operator=(const Time &p);//重载函数=
bool operator>(const Time&)const;//重载函数>
};
/文件名称:Time.cpp
/功能介绍:实现了时间类成员
作者:lonely
///
#include"Time.h"
#include<iostream>
using namespace std;
重载函数:<<//
ostream &operator<<(ostream &output,Time &p)
{
output<<p.hour<<":"<<p.minute<<":"<<p.second;
return output;
}
//重载函数:>>//
istream &operator>>(istream &input,Time &p)
{
input>>p.hour>>p.minute>>p.second;
while(p.second<0||p.second>60)
{
cout<<"输入的秒数有误,请重新输入:";
input>>p.second;
}
if(p.second==60)
{
p.second=0;
p.minute++;
}
while(p.minute<0||p.minute>60)
{
cout<<"输入的分钟有误,请重新输入:";
input>>p.minute;
}
if(p.minute==60)
{
p.minute=0;
p.hour++;
}
while(p.hour<0||p.hour>24)
{
cout<<"输入的分钟有误,请重新输入:";
input>>p.hour;
}
if(p.hour==24)
p.hour=0;
return input;
}
//重载函数:=//
Time &Time::operator=(const Time &p)
{
hour=p.hour;
minute=p.minute;
second=p.second;
return *this;
}
//重载函数:>//
bool Time::operator>(const Time &right)const
{
if(hour>right.hour)
return true;
else if(hour==right.hour&&minute>right.minute)
return true;
else if(hour==right.hour&&minute==right.minute&&second>right.second)
return true;
return false;
}
/文件名称:Cnode.h
/功能介绍:定义了乘客类
乘客信息:乘客姓名、证件号码、座位号。
作者:lonely
///
#pragma once
#include<string>
using namespace std;
class Cnode
{
public:
Cnode();//构造函数
Cnode(string n,string id,int seat);//构造函数
//friend ostream &operator<<(ostream& output,Cnode &p);//重载函数:<<
//friend istream &operator>>(istream& input,Cnode &p);//重载函数:>>
string getName(){return name;}
int getSeat(){return seatno;}
string getIDcard(){return idcard;}
private:
string name;//乘客姓名
string idcard;//证件号码
int seatno;//座位号
};
/文件名称:Cnode.cpp
/功能介绍:实现了乘客类成员
作者:lonely
///
#include"Cnode.h"
#include<iostream>
using namespace std;
Cnode::Cnode()//构造函数
{
name="\n";
idcard="\n";
seatno=0;
}
Cnode::Cnode(string n,string id,int seat)//构造函数
{
name=n;
idcard=id;
seatno=seat;
}
/*ostream &operator<<(ostream &output,Cnode &p)//重载函数:<<
{
cout<<"乘客姓名:"<<p.name<<endl;
cout<<"证件号码:"<<p.idcard<<endl;
cout<<"座位号:"<<p.seatno<<endl;
return output;
}*/
/*istream &operator>>(istream &input,Cnode &p)//重载函数:>>
{
cin>>p.name;
cin>>p.idcard;
cin>>p.seatno;
return input;
}*/
/文件名称:Pnode.h
/功能介绍:定义了航班类
航班基本信息:航班号、到达港、总座位数、余票额、乘客名单;
作者:lonely
///
#pragma once
#include"Cnode.h"
#include"Time.h"
#include<string>
#include<vector>
#include<iostream>
using namespace std;
class Flight:public Time//航班类,公有继承时间类
{
private:
int no;//航班编号
string destin;//到达港
int limit,rest;//总座位数,余票额
vector<Cnode> cname;//乘客名单向量
Time fly;//起飞时间
Time reach;//到达时间
public:
Flight();//公有函数
Flight(int n,string s,int l,Time f,Time r);//公有函数
Flight(int n,string s,int l,int rt,Time f,Time r);//公有函数
int getNo(){return no;}
void setNO(int n){no=n;}
string getDestin(){return destin;}
void setDestin(string de){destin=de;}
int getLimit(){return limit;}
void setLimit(int l){limit=l;}
int getRest(){return rest;}
void setRest(int r){rest=r;}