提示:文章写完后,目录可以自动生成,如何生成可参考右边的帮助文档
前言
编写程序模拟航空订票系统,要求实现以下功能:
① 允许增、删、改航班信息,包括“航班号 / 机型 / 起降城市 / 起降时间 / 座位数 / 票价等”(所有航班信息存储在本地文本文件中,格式自定义)。
②允许以“航班号 / 起降城市” 等条件模糊查询航班信息。
③订票:无票时应能提供相关可选择的航班以继续操作(订票数据存储在本地文本文件中,格式自定义)。
④退票:退票后应修改相关数据文件。
一、功能演示
二、代码
代码如下:
#define _CRT_SECURE_NO_WARNINGS
#include<iostream>
#include <cstring>
#include<fstream>
#include<stdio.h>
#include<cstring>
using namespace std;
struct client
{//客户
char name[20]; //姓名
int ordering_number; //订票量
int grade; //舱位等级
client* next;
};
class airline
{ //航班信息
private:
char air_num[10]; //航班号
char plane_num[10]; //机型
char start_station[20]; //始发站
char end_station[20]; //终点站
char dayup[7]; //出发时间
char daydown[7]; //到达时间
int people_quota; //乘员定额
double price; //票价
int more_ticket; //余票量
char passenger_list[50]; //乘客名单
char waiting_list[50]; //等候替补的客户名单
static int number; //航班总数
public:
//打印航班信息
void print()
{
cout << "* *\n";
cout << "* " << air_num << "\t " << plane_num << "\t " << start_station << "\t "
<< end_station << "\t " << dayup << "\t " << daydown << "\t " << people_quota
<< "\t " << price << "\t " << more_ticket << "\t *\n";
cout << "* *\n";
}
friend client* get_passenger(airline); //读取某航班乘客信息
friend client* get_wait(airline); //读取某航班等候替补名单
friend airline* get_airline(); //读取文件中的航班信息
friend void put_passenger(airline, client*); //输出乘客信息到文件
friend void put_wait(airline, client*); //输出等候替补名单
friend void put_airline(airline*); //输出修改后的航班信息
friend void search(); //查询操作(用户操作)
friend void booking(); //订票操作(用户操作)
friend void refund(); //退票操作(用户操作)
friend void print_airline(); //打印所有航班信息(管理员操作)
friend void client_list(); //乘客链表名单(管理员操作)
friend void add_airline(); //添加航班 (管理员操作)
friend int change_airline(); //修改航班信息(管理员操作)
/*八个航班修改操作*/
friend void modify_air_num(); //修改航班号(管理员操作)
friend void modify_upstation(); //修改起飞城市(管理员操作)
friend void modify_downstation(); //修改降落城市(管理员操作)
friend void modify_plane_num(); //修改机型(管理员操作)
friend void modify_time(); //修改起降时间(管理员操作)
friend void re_price(); //修改某航班的票价(管理员操作)
friend void modify_more_ticket(); //修改某航班余票量(管理员操作)
friend void del_airline(); //删除某航班(管理员操作)
};
int airline::number = 0;
char Name[20] = ""; //用于用户登录的姓名
airline* L; //全局变量,航线指针
//增加乘客
void app_client(client* c, client* q)
{
client* p = c;
while (p->next) p = p->next;
p->next = q;
q->next = NULL;
}
//登录
int login()
{
int f;
char password[20]; const char* p = "0000";const char* q = "1111"; //密码管理
cout << "\t**********************************************************\n";
cout << "\t* @ @ @@@@ @ @@@ @@@ @@@@@ @@@@ *\n";
cout << "\t* @ @ @ @ @@@@ @ @ @ @ @ @ @ @ @@@@ *\n";
cout << "\t* @ @ @ @ @ @ @ @ @ @ @ @ *\n";
cout << "\t* @@ @@ @@@@ @@@ @@@ @@@ @ @ @ @@@@ *\n";
cout << "\t* *\n";
cout << "\t* @@@@@@ @ @ @ @ @@@@@ @@@@@ *\n";
cout << "\t* @ @ @ @ @ @ @ *\n";
cout << "\t* @ @ @ @ @@@@@ @@@@@ *\n";
cout << "\t* @ @ @ @ @ @ @ @ *\n";
cout << "\t* @@@ @ @ @@@@ @ @@@@@ *\n";
cout << "\t* *\n";
cout << "\t* Air reservation ststem *\n";
cout << "\t* *\n";
cout << "\t***************************登录***************************\n";
cout << "\t* *\n";
cout << "\t* *\n";
cout << "\t* 1.乘客登录 2.管理员登录 *\n";
cout << "\t* *\n";
cout << "\t* 请选择用户身份:";
fflush(stdin); //刷新输入流缓冲区
while (cin >> f)
{
if (f == 1)
{
cout << "\t* *\n";
cout << "\t* 姓名:";
cin >> Name;
cout << "\t* *\n";
cout << "\t* 输入账户密码(提示4个1):";
fflush(stdin);
while (cin >> password)
{
if (!strcmp(password, q))
{
cout << "\t* *\n";
cout << "\t* 登录成功!! *\n";
cout << "\t* *\n";
cout << "\t* *\n";
cout << "\t**********************************************************\n\n\t";
return 1;
}
else
{
cout << "\t* *\n";
cout << "\t* 密码错误!! 请重新输入! *\n";
cout << "\t* *\n";
cout << "\t* 输入账户密码(提示4个1):";
}
}
}
else if (f == 2)
{
cout << "\t* *\n";
cout << "\t* 输入管理员密码(提示4个0):";
fflush(stdin);
while (cin >> password)
{
if (!strcmp(password, p))
{
cout << "\t* *\n";
cout << "\t* 登录成功!! *\n";
cout << "\t* *\n";
cout << "\t* *\n";
cout << "\t**********************************************************\n\n\t";
return 2;
}
else
{
cout << "\t* *\n";
cout << "\t* 密码错误!! 请重新输入! *\n";
cout << "\t* *\n";
cout << "\t* 输入管理员密码(提示4个0):";
}
}
}
else
{
cout << "\t* *\n";
cout << "\t* 输入错误!! 请重新输入 !! *\n";
cout << "\t* *\n";
cout << "\t* 请选择用户身份:";
}
}
}
//乘客用户界面
int form1()
{
int s;
cout << "\t*************************用户界面*************************\n";
cout << "\t* *\n";
cout << "\t* *\n";
cout << "\t* 1.查询航班\t 2.退票 3.订票 0.退出登录 *\n";
cout << "\t* *\n";
cout << "\t* 选择操作:";
fflush(stdin);
while (cin >> s)
{
if (s >= 0 && s <= 3)
{
cout << "\t* *\n";
cout << "\t* *\n";
cout << "\t**********************************************************\n";
return s;
}
else
{
cout << "\t* *\n";
cout << "\t* 输入错误!!! *\n";
cout << "\t* *\n";
cout << "\t* 请重新选择操作:";
}
}
}
//管理员界面
int form2()
{
int s;
cout << "\t*******************************管理员界面*********************************\n";
cout << "\t* *\n";
cout << "\t* 1.航班信息 2.乘客名单 3.添加航班 4.修改航班信息 0.退出登录 *\n";
cout << "\t* *\n";
cout << "\t* *\n";
cout << "\t* 选择操作:";
fflush(stdin);
while (cin >> s)
{
if (s >= 0 && s <= 4)
{
cout << "\t* *\n";
cout << "\t**************************************************************************\n\t";
return s;
}
else
{
cout << "\t* *\n";
cout << "\t* 输入错误!!! *\n";
cout << "\t* *\n";
cout << "\t* 请重新选择操作:";
}
}
}
//读取文件中的航班信息
airline* get_airline()
{
fstream f;int i = 0;
airline* line = new airline[100];
f.open("航班信息.txt", ios::in);
while (f >> line[i].air_num >> line[i].plane_num >> line[i].start_station >> line[i].end_station >>
line[i].dayup >> line[i].daydown >> line[i].people_quota >> line[i].price >> line[i].more_ticket >>
line[i].passenger_list >> line[i].waiting_list)
i++;
line->number = i;
f.close();
return line;
}
//输出修改后的航班信息
void put_airline(airline* L)
{
fstream f;int i;
f.open("航班信息.txt", ios::out);
for (i = 0;i < L->number;i++) f << L[i].air_num << " " << L[i].plane_num << " " << L[i].start_station << " " <<
L[i].end_station << " " << L[i].dayup << " " << L[i].daydown << " " << L[i].people_quota << " " << L[i].price
<< " " << L[i].more_ticket << " " << L[i].passenger_list << " " << L[i].waiting_list << '\n';
f.close();
}
//读取某航班乘客信息
client* get_passenger(airline L)
{
fstream f;int i = 0;
client* c = new client, * p = new client, * q = c;
f.open(L.passenger_list, ios::in);
while (f >> p->name >> p->ordering_number >> p->grade)
{
q->next = p;
p = new client;
q = q->next;
}
q->next = NULL;
f.close();
return c;
}
//输出乘客信息到文件
void put_passenger(airline l, client* c)
{
fstream f;
client* p = c->next;
f.open(l.passenger_list, ios::out | ios::trunc);
while (p)
{
f << p->name << " " << p->ordering_number << " " << p->grade << '\n';
p = p->next;
}
f.close();
}
//输出等候替补名单
void put_wait(airline l, client* c)
{
fstream f;
client* p = c->next;
f.open(l.waiting_list, ios::out | ios::trunc);
while (p)
{
f << p->name << " " << p->ordering_number << " " << p->grade << '\n';
p = p->next;
}
f.close();
}
//读取某航班等候替补名单
client* get_wait(airline l)
{
fstream f;int i = 0;
client* c = new client, * p = new client, * q = c;
f.open(l.waiting_list, ios::in);
while (f >> p->name >> p->ordering_number >> p->grade)
{
q->next = p;
p = new client;
q = q->next;
}
q->next = NULL;
f.close();
return c;
}
//查询操作 (用户操作)1
void search()
{
char s[20];
int i = 0, j = 0;
cout << "*******************************************************查询*********************************************************\n";
cout << "* *\n";
cout << "* *\n";
cout << "* 模糊搜索(航班号 / 起降城市):";
cin >> s;
cout << "* *\n";
cout << "* 航班号" << " 机型" << "\t始发站" << "\t 终点站" << "\t 出发时间" << "\t 到达时间" << "\t 乘员定额" <<
"\t票价" << "\t 余票量" << " *\n";
cout << "* *\n";
cout << "* *\n";
for (i = 0;i < L->number;i++)
{
while (i < L->number && strcmp(s, L[i].end_station) && strcmp(s, L[i].start_station) && strcmp(s, L[i].air_num)) i++;
if (i < L->number)
{
L[i].print();
j = 1;
}
}
if (j == 0)
{
system("cls");
cout << "*******************************************************查询*********************************************************\n";
cout << "* *\n";
cout << "* *\n";
cout << "* 无此航班信息! *\n";
cout << "* *\n";
cout << "* *\n";
}
cout << "********************************************************************************************************************\n\n";
}
//退票操作 (用户操作)2
void refund()
{
char s[20];
int i = 0, n;
cout << "*******************************************************退票*********************************************************\n";
cout << "* *\n";
cout << "* *\n";
cout << "* 航班号:";
cin >> s;
cout << "* *\n";
while (i < L->number && strcmp(s, L[i].air_num)) i++; //按航班号匹配
if (i < L->number)
{//找到此航班
client* c1 = get_passenger(L[i]), * c2 = get_wait(L[i]), * p = c1, * q, * r;
//获得次航班的乘客和候补乘客链表
while (p->next && strcmp(Name, p->next->name)) p = p->next; //姓名查找
if (p->next)
{//找到该用户姓名
cout << "* 您在" << L[i].air_num << "航班(终点站:"
<< L[i].end_station << ")订了" << p->next->ordering_number << "张票 *\n";
cout << "* *\n";
cout << "* 请输入退票数量:";
do
{//输入退票数
cin >> n;
if (n > 0 && n <= p->next->ordering_number) break;
else
{
cout << "* *\n";
cout << "* 输入错误!!请重新输入!! *\n";
cout << "* *\n";
cout << "* 请重新输入:";
}
} while (1);
if (n == p->next->ordering_number)
{//全部退票
r = p->next;
q = r->next;
p->next = q;
delete r;
cout << "* *\n";
cout << "* 退票完成! *\n";
cout << "* *\n";
}
else if (n < p->next->ordering_number)
{//退部分票
p->next->ordering_number -= n;
cout << "* *\n";
cout << "* 退票完成! *\n";
cout << "* *\n";
}
L[i].more_ticket += n; //余票增加
int f = 1;
while (L[i].more_ticket && f)
{//有余票且未访问完所有候补乘客
p = c2;
while (p->next && L[i].more_ticket < p->next->ordering_number) p = p->next;
if (p->next)
{//找到需求票数满足的
L[i].more_ticket -= p->next->ordering_number;
r = p->next;
q = r->next;
p->next = q;
app_client(c1, r);
}
else f = 0; //访问完
}
put_passenger(L[i], c1); //刷新乘客名单
put_wait(L[i], c2); //刷新候选名单
}
else
{
cout << "* *\n";
cout << "* 退票错误!! 您没有在此航班订票! *\n";
cout << "* *\n";
}
}
else
{
cout << "* 无此航班信息! *\n";
cout << "* *\n";
cout << "* *\n";
cout << "* *\n";
}
/*cout << "\n 退票操作完成!\n";*/
cout << "********************************************************************************************************************\n\n";
put_airline(L);
}
//订票操作 (用户操作)3
void booking()
{
char s[20], a[20];
int i = 0, j = 0, n, x, g;
cout << "*******************************************************订票*********************************************************\n";
cout << "* *\n";
cout << "* *\n";
cout << "* (航班号/起降城市):";
air_:
cin >> s;
cout << "* *\n";
for (i = 0;i < L->number;i++)
{
while (i < L->number && strcmp(s, L[i].end_station) && strcmp(s, L[i].start_station) && strcmp(s, L[i].air_num)) i++;
if (i < L->number)
{
j = 1;
/*L[i].print();*/
}
}
if (j == 1)
{
cout << "* 航班号" << " 机型" << "\t始发站" << "\t 终点站" << "\t 出发时间" << "\t 到达时间" << "\t 乘员定额" <<
"\t票价" << "\t 余票量" << " *\n";
cout << "* *\n";
for (i = 0;i < L->number;i++)
{
while (i < L->number && strcmp(s, L[i].end_station) && strcmp(s, L[i].start_station) && strcmp(s, L[i].air_num)) i++;
if (i < L->number) L[i].print();
}
}
if (j == 1)
{
cout << "* *\n";
cout << "* 请输入您所需要订购的航班号:";
air_num:
cin >> a;
for (i = 0;i < L->number;i++)
{
while (i < L->number && strcmp(a, L[i].air_num)) i++;
if (i < L->number)
{
cout << endl;
for (i = 0;i < L->number;i++)
{
while (i < L->number && strcmp(a, L[i].air_num)) i++;
if (i < L->number)
{
L[i].print();
client* c1 = get_passenger(L[i]);
client* c2 = get_wait(L[i]);
g:
cout << "* *\n";
cout << "* 舱位等级(1:头等舱 ,2:普通舱,3:经济舱):";cin >> g;
cout << "* *\n";
if (0 < g && g <= 3) cout << "* 购买票数:";
else
{
cout << "* *\n";
cout << "* 输入错误!!请重新输入舱位等级! *\n";
goto g;
}
do
{
cin >> n;
if (n > 0 && n <= L[i].people_quota) break;
else
cout << "* *\n";
cout << "* 购票失败!!不能超过票数限制(" << "0" << "-" << L[i].people_quota << "),重新输入:";
} while (1);
if (L[i].more_ticket)
{/*有余票*/
if (n <= L[i].more_ticket && L[i].more_ticket > 0)
{
client* p = new client;
strcpy(p->name, Name);
p->ordering_number = n;
L[i].more_ticket -= n;
p->grade = g;
app_client(c1, p); /*!!!注意!!!*/
cout << "* *\n";
cout << "* 购票完成! *\n";
cout << "* *\n";
cout << "********************************************************************************************************************\n\n";
}
else if (n > L[i].more_ticket && L[i].more_ticket > 0)
{//余票小于购买数
int x;
client* p1 = new client, * p2 = new client;
//询问用户
cout << "* *\n";
cout << "*\t\t (1:只买" << L[i].more_ticket << "张 2:买" << L[i].more_ticket << "张,"
<< n - L[i].more_ticket << "张等候 3:不买)" << " *\n";
cout << "* *\n";
cout << "* 余票不足" << n << "张 *\n";
cout << "* *\n";
cout << "* 选择是否继续购买?:";
cin >> x;
if (x >= 1 && x <= 3)
{
switch (x)
{
case 1:
strcpy(p1->name, Name);
p1->ordering_number = L[i].more_ticket;
L[i].more_ticket = 0;
p1->grade = g;
app_client(c1, p1);
cout << "* *\n";
cout << "* 购票完成! *\n";
cout << "* *\n";
cout << "********************************************************************************************************************\n\n";
break;
case 2:
strcpy(p1->name, Name);
p1->ordering_number = L[i].more_ticket;
p1->grade = g;
app_client(c1, p1);
strcpy(p2->name, Name);
p2->ordering_number = n - L[i].more_ticket;
L[i].more_ticket = 0;
p2->grade = g;
app_client(c2, p2);
cout << "* *\n";
cout << "* 购票完成! *\n";
cout << "* *\n";
cout << "********************************************************************************************************************\n\n";
break;
case 3:
cout << "* *\n";
cout << "********************************************************************************************************************\n\n";
break;
}
}
else
{
cout << "* 输入错误!返回上一页! *\n";
cout << "* *\n";
cout << "********************************************************************************************************************\n\n";
}
}
}
else
{//无余票
cout << "* *\n";
cout << "* 无余票! 是否排队等候票?(1:是 0:否);";cin >> x;
if (x)
{//进入等候名单
client* p = new client;
strcpy(p->name, Name);
p->ordering_number = n;
p->grade = g;
app_client(c2, p);
cout << "* *\n";
cout << "* 购票操作完成! 正在排队等候票! *\n";
cout << "* *\n";
cout << "* *\n";
cout << "********************************************************************************************************************\n\n";
}
else
{
cout << "* *\n";
cout << "********************************************************************************************************************\n\n";
}
}
put_passenger(L[i], c1); //刷新乘客名单
put_wait(L[i], c2);
}
put_airline(L);
}
}
else
{
cout << "* 航班号输入错误!请重新输入:";
goto air_num;
}
}
}
if (j == 0)
{
cout << "* *\n";
cout << "* 暂无相关航班信息! *\n";
cout << "* *\n";
cout << "********************************************************************************************************************\n\n";
}
}
//打印所有航班信息 (管理员操作)1
void print_airline()
{
L = get_airline();
int i = 0;
cout << "*****************************************************航班信息*******************************************************\n";
cout << "* *\n";
cout << "* 航班号" << " 机型" << "\t始发站" << "\t 终点站" << "\t 出发时间" << "\t 到达时间" << "\t 乘员定额" <<
"\t票价" << "\t 余票量" << " *\n";
cout << "* *\n";
cout << "* *\n";
for (int i = 0;i < L->number;i++)
L[i].print();
cout << "********************************************************************************************************************\n\n";
}
//查看某航班乘客名单(管理员操作)2
void client_list()
{
int i = 0;char s[20], * g = "";
cout << "\t********************************乘客名单**********************************\n";
cout << "\t* *\n";
cout << "\t* *\n";
cout << "\t* 航班号:";
cin >> s;
while (i < L->number && strcmp(s, L[i].air_num)) i++;
if (i < L->number)
{
client c;
fstream f;
f.open(L[i].passenger_list, ios::in);
cout << "\t* *\n";
cout << "\t* 已购票乘客名单 *\n";
cout << "\t* *\n";
while (f >> c.name >> c.ordering_number >> c.grade)
{
switch (c.grade)
{
case 1:g = "头等舱";break;
case 2:g = "普通舱";break;
case 3:g = "经济舱";
}
cout << "\t* *\n";
cout << "\t*\t姓名:" << c.name << "\t 舱位等级:" << g << " \t购票数:" << c.ordering_number << " *\n";
}
f.close();
f.open(L[i].waiting_list, ios::in);
cout << "\t* *\n";
cout << "\t* 候补订票乘客名单 *\n";
cout << "\t* *\n";
while (f >> c.name >> c.ordering_number >> c.grade)
{
switch (c.grade)
{
case 1:g = "头等舱";break;
case 2:g = "普通舱";break;
case 3:g = "经济舱";
}
cout << "\t* *\n";
cout << "\t*\t姓名:" << c.name << "\t 舱位等级:" << g << " \t预订票数:" << c.ordering_number << " *\n";
}
f.close();
}
else
{
cout << "\t* *\n";
cout << "\t* 无此航班信息! *\n";
cout << "\t* *\n";
}
cout << "\t* *\n";
cout << "\t**************************************************************************\n\n\t";
}
//添加航班 (管理员操作)3
void add_airline()
{
int i = 0;
airline air1;
cout << "*****************************************************添加航班*******************************************************\n";
cout << "* *\n";
cout << "* *\n";
cout << "* 请输入航班号:";
air1_air_num:
cin >> air1.air_num;
while (i < L->number && strcmp(air1.air_num, L[i].air_num)) i++;
if (i < L->number)
{
cout << "* *\n";
cout << "* 已存在此航班号 *\n";
cout << "* *\n";
cout << "* 请重新输入航班号:";
goto air1_air_num;
}
cout << "* *\n";
cout << "* 请输入机型:";cin >> air1.plane_num;
cout << "* *\n";
cout << "* 请输入起飞城市:";cin >> air1.start_station;
cout << "* *\n";
cout << "* 请输入降落城市:";cin >> air1.end_station;
cout << "* *\n";
cout << "* 请输入出发时间:";cin >> air1.dayup;
cout << "* *\n";
cout << "* 请输入到达时间:";cin >> air1.daydown;
cout << "* *\n";
cout << "* 请输入乘员定额:";
air1_people_quota:
cin >> air1.people_quota;
if (air1.people_quota <= 0)
{
cout << "\n 乘员定额输入错误\t 请重新输入乘员定额:";
goto air1_people_quota;
}
cout << "* *\n";
cout << "* 请输入票价:";
air1_price:
cin >> air1.price;
if (air1.price <= 0)
{
cout << "\n 票价输入错误\t 请重新输入票价:";
goto air1_price;
}
cout << "* *\n";
cout << "* 请输入余票数:";
air1_more_ticket:
cin >> air1.more_ticket;
if (air1.more_ticket <= 0)
{
cout << "\n 余票数输入错误\t 请重新输入余票数:";
goto air1_more_ticket;
}
cout << "* *\n";
cout << "* 输入(建立乘员名单文档名_eg:007a):";cin >> air1.passenger_list;
cout << "* *\n";
cout << "* 输入(等候名单文档名_eg:007b):";cin >> air1.waiting_list;
cout << "* *\n";
ofstream outfile("航班信息.txt", ios::app);
outfile << air1.air_num << " " << air1.plane_num << " " << air1.start_station << " " << air1.end_station << " "
<< air1.dayup << " " << air1.daydown << " " << air1.people_quota << " " << air1.price << " " << air1.more_ticket << " "
<< air1.passenger_list << " " << air1.waiting_list << "\n";
outfile.close();
cout << "* *\n";
cout << "* 添加航班完成! *\n";
cout << "* *\n";
cout << "********************************************************************************************************************\n\n";
}
//修改航班信息 (管理员操作)4
int change_airline()
{
int s;
cout << "\t****************************修改航班信息界面******************************\n";
cout << "\t* *\n";
cout << "\t* 1.修改航班号 2.修改机型 3.修改航班起飞城市 4.修改航班降落城市 *\n";
cout << "\t* *\n";
cout << "\t* 5.修改起降时间 6.修改机票价格 7.修改剩余座位 8.删除航班信息 *\n";
cout << "\t* *\n";
cout << "\t* 0.返回上级菜单 *\n";
cout << "\t* *\n";
cout << "\t* 选择操作:";
fflush(stdin);
while (cin >> s)
{
if (s >= 0 && s <= 8)
{
cout << "\t* *\n";
cout << "\t**************************************************************************\n\n\t";
return s;
}
else
{
cout << "\t* *\n";
cout << "\t* 输入错误!!! *\n";
cout << "\t* *\n";
cout << "\t* 请重新选择操作:";
}
}
}
//修改航班号 (管理员操作1)
void modify_air_num()
{
int i = 0;char s[10];char* p = new char[10];
cout << "****************************************************修改航班号******************************************************\n";
cout << "* *\n";
cout << "* *\n";
cout << "* 请输入航班号:";
cin >> s;
while (i < L->number && strcmp(s, L[i].air_num)) i++;
if (i < L->number)
{
cout << "* *\n";
cout << "* 航班号" << " 机型" << "\t始发站" << "\t 终点站" << "\t 出发时间" << "\t 到达时间" << "\t 乘员定额" <<
"\t票价" << "\t 余票量" << " *\n";
cout << "* *\n";
cout << "* *\n";
L[i].print();
cout << "* 新航班号:";
cin >> p;
strcpy(L[i].air_num, p); //将p中字符串复制到L[i].air_num
cout << "* *\n";
cout << "* 修改航班号完成! *\n";
cout << "* *\n";
}
else
{
cout << "* *\n";
cout << "* 无此航班信息! *\n";
cout << "* *\n";
cout << "* *\n";
}
put_airline(L);
cout << "********************************************************************************************************************\n\n";
}
//修改机型 (管理员操作2)
void modify_plane_num()
{
int i = 0;char s[10];char* p = new char[10];
cout << "*****************************************************修改机型*******************************************************\n";
cout << "* *\n";
cout << "* *\n";
cout << "* 请输入航班号:";
cin >> s;
while (i < L->number && strcmp(s, L[i].air_num)) i++;
if (i < L->number)
{
cout << "* *\n";
cout << "* 航班号" << " 机型" << "\t始发站" << "\t 终点站" << "\t 出发时间" << "\t 到达时间" << "\t 乘员定额" <<
"\t票价" << "\t 余票量" << " *\n";
cout << "* *\n";
cout << "* *\n";
L[i].print();
cout << "* 新机型:";
cin >> p;
strcpy(L[i].plane_num, p); //将p中字符串复制到L[i].plane_num
cout << "* *\n";
cout << "* 修改机型完成! *\n";
cout << "* *\n";
}
else
{
cout << "* *\n";
cout << "* 无此航班信息! *\n";
cout << "* *\n";
cout << "* *\n";
}
put_airline(L);
cout << "********************************************************************************************************************\n\n";
}
//修改起飞城市 (管理员操作3)
void modify_upstation()
{
int i = 0;char s[10];char* p = new char[10];
cout << "***************************************************修改起飞城市*****************************************************\n";
cout << "* *\n";
cout << "* *\n";
cout << "* 请输入航班号:";
cin >> s;
while (i < L->number && strcmp(s, L[i].air_num)) i++;
if (i < L->number)
{
cout << "* *\n";
cout << "* 航班号" << " 机型" << "\t始发站" << "\t 终点站" << "\t 出发时间" << "\t 到达时间" << "\t 乘员定额" <<
"\t票价" << "\t 余票量" << " *\n";
cout << "* *\n";
cout << "* *\n";
L[i].print();
cout << "* 新起飞城市:";
cin >> p;
strcpy(L[i].start_station, p); //将p中字符串复制到L[i].start_station
cout << "* *\n";
cout << "* 修改起飞城市完成! *\n";
cout << "* *\n";
}
else
{
cout << "* *\n";
cout << "* 无此航班信息! *\n";
cout << "* *\n";
cout << "* *\n";
}
put_airline(L);
cout << "********************************************************************************************************************\n\n";
}
//修改降落城市 (管理员操作4)
void modify_downstation()
{
int i = 0;char s[10];char* p = new char[10];
cout << "***************************************************修改降落城市*****************************************************\n";
cout << "* *\n";
cout << "* *\n";
cout << "* 请输入航班号:";
cin >> s;
while (i < L->number && strcmp(s, L[i].air_num)) i++;
if (i < L->number)
{
cout << "* *\n";
cout << "* 航班号" << " 机型" << "\t始发站" << "\t 终点站" << "\t 出发时间" << "\t 到达时间" << "\t 乘员定额" <<
"\t票价" << "\t 余票量" << " *\n";
cout << "* *\n";
cout << "* *\n";
L[i].print();
cout << "* 新降落城市:";
cin >> p;
strcpy(L[i].end_station, p); //将p中字符串复制到L[i].end_station
cout << "* *\n";
cout << "* 修改降落城市完成! *\n";
cout << "* *\n";
}
else
{
cout << "* *\n";
cout << "* 无此航班信息! *\n";
cout << "* *\n";
cout << "* *\n";
}
put_airline(L);
cout << "********************************************************************************************************************\n\n";
}
//修改起降时间 (管理员操作5)
void modify_time()
{
int i = 0;char s[10];char* p = new char[10];char* q = new char[10];
cout << "***************************************************修改起降时间*****************************************************\n";
cout << "* *\n";
cout << "* *\n";
cout << "* 请输入航班号:";
cin >> s;
while (i < L->number && strcmp(s, L[i].air_num)) i++;
if (i < L->number)
{
cout << "* *\n";
cout << "* 航班号" << " 机型" << "\t始发站" << "\t 终点站" << "\t 出发时间" << "\t 到达时间" << "\t 乘员定额" <<
"\t票价" << "\t 余票量" << " *\n";
cout << "* *\n";
cout << "* *\n";
L[i].print();
cout << "* 新出发时间:";
cin >> p;
cout << "* *\n";
cout << "* 新到达时间:";
cin >> q;
strcpy(L[i].dayup, p); //将p中字符串复制到L[i].dayup
strcpy(L[i].daydown, q); //将q中字符串复制到L[i].daydown
cout << "* *\n";
cout << "* 修改起降时间完成! *\n";
cout << "* *\n";
}
else
{
cout << "* *\n";
cout << "* 无此航班信息! *\n";
cout << "* *\n";
cout << "* *\n";
}
put_airline(L);
cout << "********************************************************************************************************************\n\n";
}
//修改某航班票价 (管理员操作6)
void re_price()
{
int i = 0, p;char s[20];
cout << "****************************************************修改票价间******************************************************\n";
cout << "* *\n";
cout << "* *\n";
cout << "* 请输入航班号:";
cin >> s;
while (i < L->number && strcmp(s, L[i].air_num)) i++;
if (i < L->number)
{
cout << "* *\n";
cout << "* 航班号" << " 机型" << "\t始发站" << "\t 终点站" << "\t 出发时间" << "\t 到达时间" << "\t 乘员定额" <<
"\t票价" << "\t 余票量" << " *\n";
cout << "* *\n";
cout << "* *\n";
L[i].print();
cout << "* 新票价:";
cin >> p;
L[i].price = p;
cout << "* *\n";
cout << "* 修改票价完成! *\n";
cout << "* *\n";
}
else
{
cout << "* *\n";
cout << "* 无此航班信息! *\n";
cout << "* *\n";
cout << "* *\n";
}
put_airline(L);
cout << "********************************************************************************************************************\n\n";
}
//修改某航班余票量 (管理员操作7)
void modify_more_ticket()
{
int i = 0, p;char s[20];
cout << "***************************************************修改余票数量*****************************************************\n";
cout << "* *\n";
cout << "* *\n";
cout << "* 请输入航班号:";
cin >> s;
while (i < L->number && strcmp(s, L[i].air_num)) i++;
if (i < L->number)
{
cout << "* *\n";
cout << "* 航班号" << " 机型" << "\t始发站" << "\t 终点站" << "\t 出发时间" << "\t 到达时间" << "\t 乘员定额" <<
"\t票价" << "\t 余票量" << " *\n";
cout << "* *\n";
cout << "* *\n";
L[i].print();
cout << "* 新的余票数:";
cin >> p;
L[i].more_ticket = p;
cout << "* *\n";
cout << "* 修改余票数完成! *\n";
cout << "* *\n";
}
else
{
cout << "* *\n";
cout << "* 无此航班信息! *\n";
cout << "* *\n";
cout << "* *\n";
}
put_airline(L);
cout << "********************************************************************************************************************\n\n";
}
//删除某航班 (管理员操作8)
void del_airline()
{
int i = 0, j = 0;char s[20];char p[50] = "\0";
cout << "*****************************************************删除航班*******************************************************\n";
cout << "* *\n";
cout << "* *\n";
cout << "* 请输入航班号:";
cin >> s;
while (i < L->number && strcmp(s, L[i].air_num)) i++;
if (i < L->number)
{
cout << "* *\n";
cout << "* 航班号" << " 机型" << "\t始发站" << "\t 终点站" << "\t 出发时间" << "\t 到达时间" << "\t 乘员定额" <<
"\t票价" << "\t 余票量" << " *\n";
cout << "* *\n";
cout << "* *\n";
L[i].print();
for (i;i < L->number;i++)
{
L[i] = L[i + 1];
}
L->number -= 1;
cout << "* *\n";
cout << "* 删除航班完成! *\n";
cout << "* *\n";
}
else
{
cout << "* *\n";
cout << "* 无此航班信息! *\n";
cout << "* *\n";
cout << "* *\n";
}
put_airline(L);
cout << "********************************************************************************************************************\n\n";
}
int main()
{
L=get_airline();
do
{
int f=1;
switch(login())//登录界面
{
case 1://乘客界面
system("pause");
system("cls");
do
{
switch(form1())
{
case 1://调用查询函数
system("cls");
search();
system("pause");
system("cls");
break;
case 2://退票
system("cls");
refund();
system("pause");
system("cls");
break;
case 3://订票
system("cls");
booking();
system("pause");
system("cls");
break;
case 0://退出登录,返回上一层
f=0;
system("cls");
}
}while(f);
break;
case 2://管理员界面
system("pause");
system("cls");
do
{
switch(form2())
{
case 1://查看所有航班信息
system("cls");
print_airline();
system("pause");
system("cls");
break;
case 2://查看乘客名单
system("cls");
client_list();
system("pause");
system("cls");
break;
case 3://添加航班
system("cls");
add_airline();
system("pause");
system("cls");
break;
case 4://修改航班
system("cls");
change_airline();
system("pause");
system("cls");
break;
case 0://退出登录,返回上一层
f=0;
system("cls");
}
}while(f);
}
}while(1);
}
总结
希望该文章对你有帮助。