c++航班管理系统课设
## c++航班管理系统课设
提示:文章写完后,目录可以自动生成,如何生成可参考右边的帮助文档
前言
大二上学期,数据结构的课设,航班管理系统。用链表写的,抽到的题目还算简单如下相比其他的类型,链表还是很基础的:
13、 航班订票系统
任务:通过此系统可以实现如下功能:
1)、录入:
可以录入航班情况(数据可以存储在一个数据文件中,数据结构、具体数据自定)
2)、查询:
可以查询某个航线的情况(如,输入航班号,查询起降时间,起飞抵达城市,航班票价,票价折扣,确定航班是否满仓);可以输入起飞抵达城市,查询飞机航班情况;
3)、订票:(订票情况可以存在一个数据文件中,结构自己设定)可以订票,如果该航班已经无票,可以提供相关可选择航班;
4)、退票: 可退票,退票后修改相关数据文件;
客户资料有姓名,证件号,订票数量及航班情况,订单要有编号。
5)、修改航班信息:
当航班信息改变可以修改航班数据文件要求:根据以上功能说明,设计航班信息,订票信息的存储结构,设计程序完成功能;界面要求:有合理的提示,每个功能可以设立菜单,根据提示,可以完成相关的功能要求。存储结构:学生自己根据系统功能要求自己设计。请在最后的上交资料中指明你用到的存储结构;测试数据:要求使用1、全部合法数据;2、整体非法数据;3、局部非法数据。进行程序测试,以保证程序的稳定。测试数据及测试结果请在上交的资料中写明;
提示:以下是本篇文章正文内容,下面案例可供参考,我在网上找了一点代码,然后自己修改了很多,因为找到的很多功能不符,有些数据也没,但是大致结构框架相似就拿过来改了,加了很多代码,也加了很多注解。
代码思路:设计了一个航班类,一个乘客类,一个票类,是采用链表的结构写的。乘客和航班各自一文件记录数据。本来想设计成,航班类的成员变量中有乘客类,表示的意思是,每一趟航班对应一个乘客链表,这比较符合实际情况,但由于我对文件读写操作还不熟悉就简单写成了两个文件。剩下的就是对链表增删改查,加上了文件的读,文件的写。
画面设计,菜单选择是绿色字体,输出是红色。
代码如下(示例):
#include"iostream"
#include"string" //string类使用
#include"iomanip" //格式设置 setw();
#include"fstream" //文件读写
#include "random" //随机数生成
#include"ctime"
#include<windows.h> //改变颜色
using namespace std;
//链表结构
typedef class flightnode //定义数据结构航班信息
{
public:
string flight_num; //航班号
string time; //起飞时间
int date; //起飞日期
string start_place; //出发地
string end_place; //目的地
float discount; //折扣
int left; //余票
float price; //价格
flightnode* next;
}*flightlist; //为flightnode取别名fightlist
class ticket //机票类
{
public:
string flight_num; //航班号
string time; //起飞时间
string start_place; //出发地
string end_place; //目的地
float price; //价格
int date; //起飞日期
string order_num; //订单编号
};
typedef class passengernode//定义数据结构乘客信息
{
public:
string name; //名字
string ID_num; //证件号
ticket ticket; //票
int full = 0; //预约标志 1表示预约状态
passengernode* next;
}*passengerlist; //为passengernode取别名passengerlist
//函数声明************************************************
//航班类信息
void Init_flight(flightlist&h);//初始化航班
void Load_flight(flightlist&h);//载入航班
void Add_flight(flightlist&h);//添加航班
void Check_flight(flightlist&h);//查找航班
void Check_flightnum(flightlist&h);//航班号查找
void Check_seplace(flightlist&h);//起始地查找
void Check_all(flightlist&h);//浏览全部航班
void Revise_flight(flightlist&h);//修改航班信息
void Delete_flight(flightlist&h);//删除航班
void Revise_time(flightlist&h);//修改起飞抵达时间
void Revise_price(flightlist&h);//修改价格
void Save_flight(flightlist&h);//保存航班信息
//用户信息
void Init_passenger(passengerlist&c);//初始化用户
void Load_passenger(passengerlist&c);//载入用户信息
void Book(flightlist&h, passengerlist&c);//定票
void Qbook(flightlist&h, passengerlist&c);//退票
void Check_book(passengerlist&c);//查询订单
void Save_passenger(passengerlist&c);//保存用户信息
//管理操作
void massage(flightlist& flight, passengerlist& passenger);//管理
void password();//密码管理
//主函数
int main()
{
flightlist flight;
passengerlist passenger;
password(); //封装密码管理
Init_passenger(passenger); //初始用户信息
Load_passenger(passenger); //载入用户信息
Init_flight(flight); //初始化航班
Load_flight(flight); //载入航班
massage(flight,passenger); //封装管理函数
return 0;
}
/*******************
* 功能描述:密码管理
* 输入参数: 无
* 输出参数: 无
* 返回值: void
* 其它说明:进入系统前的准备工作
********************/
void password()
{
cout << " ┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅ " << endl;
cout << " ┇ ≡ 欢迎进入系统 ≡ ┇ " << endl;
cout << " ┇ ┇ " << endl;
cout << " ┇ 1.登入 ┇ " << endl;
cout << " ┇ ┇ " << endl;
cout << " ┇ 0.退出 ┇ " << endl;
cout << " ┇ ┇ " << endl;
cout << " ┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅ " << endl;
string pass="123456";//系统默认密码
int select;
cout << " 请输入选择:";
cin >> select;
string password; //密码
int count = 1; //计数
switch (select)
{
case 1:
cout << " 请输入航班管理系统密码:";
cin >> password; //输入密码
while (password != pass && count != 3)
{
cout << " 密码错误! 还有" << 3 - count << "次机会,请重新输入:" ;
cin >> password;
count++;
}
if (password != pass && count == 3)
{
system("pause");
exit(0);
break;
case 0:
exit(0);
default:
break;
}
}
//system("pause");
//system("cls");
}
/*******************
* 功能描述:航班管理
* 输入参数: 无
* 输出参数: 无
* 返回值: void
* 其它说明:无
********************/
void massage(flightlist &flight,passengerlist &passenger)
{
while (1)
{
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), FOREGROUND_INTENSITY |FOREGROUND_GREEN); //菜单改成绿色
cout << endl;
cout << " ********************* 飞 机 订 票 系 统******************* " << endl << endl;
cout << " ╔┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅╗ " << endl;
cout << " ┇ ┇ " << endl;
cout << " ┇ ≡ 主菜单 ≡ ┇ " << endl;
cout << " ┇ ┇ " << endl;
cout << " ┇ 1.录入航班信息 ┇ " << endl;
cout << " ┇ ┇ " << endl;
cout << " ┇ 2.查询航班 ┇ " << endl;
cout << " ┇ ┇ " << endl;
cout << " ┇ 3.订票 4.退票 ┇ " << endl;
cout << " ┇ ┇ " << endl;
cout << " ┇ 5.查询订单 ┇ " << endl;
cout << " ┇ ┇ " << endl;
cout << " ┇ 6.修改航班信息 ┇ " << endl;
cout << " ┇ ┇ " << endl;
cout << " ┇ 0.退出系统 ┇ " << endl;
cout << " ┇ ┇ " << endl;
cout << " ╚┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅╝ " << endl;
cout << " 请输入您想要进行的功能:";
int i;
cin >> i;
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), FOREGROUND_INTENSITY | FOREGROUND_RED); //红色
if (i == 1)
{
Add_flight(flight);//添加航班
Save_flight(flight);//保存航班信息
}
else if (i == 2)
Check_flight(flight);//查找航班
else if (i == 3)
{
Book(flight, passenger);//定票
Save_flight(flight);//保存航班信息
Save_passenger(passenger);//保存用户信息
}
else if (i == 4)
{
Qbook(flight, passenger);//退票
Save_flight(flight);//保存航班信息
Save_passenger(passenger);//保存用户信息
}
else if (i == 5)
Check_book(passenger);//查询订单
else if (i == 6)
{
Revise_flight(flight);//修改航班信息
Save_flight(flight);//保存航班信息
}
else if (i == 0)
break;
else
{
cout << " 无效数字,请重新输入!";
system("pause");
system("cls"); //清屏
}
}
}
/*******************
* 功能描述:航班排序
* 输入参数: 无
* 输出参数: 无
* 返回值: void
* 其它说明:按照日期号将航班进行排序
********************/
void Sort_flight(flightlist& h)
{
flightlist p = h->next; //指向第一个结点
while (p!=NULL) //选择排序法
{
flightlist q = h->next; //指向p后一个结点
while(q)
{
if(q->date > p->date) //日期比较
{
flightnode temp = *p; //临时保存指针交换
temp.next = q->next;
q->next = p->next;
*p = *q;
*q = temp;
}
q = q->next; //指针移动
}
p = p->next; //指针移动
}
}
/*******************
* 功能描述:初始化航班
* 输入参数: 无
* 输出参数: 无
* 返回值: void
* 其它说明:无
********************/
void Init_flight(flightlist& h)//初始化航班
{
h = new flightnode; //头指针
h->next = NULL;
}
/*******************
* 功能描述:载入航班信息读取到链表
* 输入参数: 载入FlightList.dat信息到链表
* 输出参数: 无
* 返回值: void
* 其它说明:无
********************/
void Load_flight(flightlist& h)//载入航班
{
flightlist f = h;
flightlist newp= new flightnode;
ifstream infile("d:\\FlightList.dat", ios::in);//以输入的方式打开文件
if (!infile)//文件没打开
{
cout << " 信息错误!"; //提示用户
return;
}
while (1)
{
infile >> newp->flight_num >> newp->date>> newp->time >> newp->start_place >> newp->end_place >> newp->price >> newp->discount>> newp->left;
if (!infile.eof()) //未到文件尾
{
f->next = newp;
f = f->next;
newp = new flightnode;
}
else
break;
}
f->next = NULL;
delete newp;
}
/*******************
* 功能描述:添加航班
* 输入参数: 航班的相关信息
* 输出参数: 添加成功或者选择继续添加
* 返回值: void
* 其它说明:无
********************/
void Add_flight(flightlist& h)//添加航班
{
char mark = 'y';
flightlist s, rear;
for (rear=h;rear->next != NULL; rear = rear->next) {} // rear移动结点尾
while (mark == 'y'||mark=='Y')
{
s = new flightnode;
cout << " 请输入航班号:";
cin >> s->flight_num;
cout << " 请输入起飞日期:";
cin >> s->date;
cout << " 请输入起飞时间:";
cin >> s->time;
cout << " 请输入出发地:";
cin >> s->start_place;
cout << " 请输入目的地:";
cin >> s->end_place;
cout << " 请输入价格:";
cin >> s->price;
cout << " 请输入折扣:";
cin >> s->discount;
cout << " 请输入余票:";
cin >> s->left;
rear->next = s; //尾部链接
rear = s;
cout << " 添加成功!" << endl;
cout << " 是否继续添加?(是“y”/否“n”):";
cin >> mark;
}
rear->next = NULL;
}
/*******************
* 功能描述:查找航班
* 输入参数: 选择查找方式
* 输出参数: 进入相关函数进行查找功能
* 返回值: void
* 其它说明:无
********************/
void Check_flight(flightlist& h)//查找航班
{
//system("cls");
int i;
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), FOREGROUND_INTENSITY | FOREGROUND_GREEN);//菜单绿色
cout << " ┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅ " << endl;
cout << " ┇ ≡ 查找方式 ≡ ┇ " << endl;
cout << " ┇ ┇ " << endl;
cout << " ┇ 1.航班查找 ┇ " << endl;
cout << " ┇ ┇ " << endl;
cout << " ┇ 2.起始地查找 ┇ " << endl;
cout << " ┇ ┇ " << endl;
cout << " ┇ 3.浏览全部航班 ┇ " << endl;
cout << " ┇ ┇ " << endl;
cout << " ┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅ " << endl;
cout << " 请输入查找方式:";
cin >> i;
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), FOREGROUND_INTENSITY | FOREGROUND_RED); //红色
if (i == 1)
Check_flightnum(h); //航班号查找
else if (i == 2)
Check_seplace(h); //起始地查找
else if (i == 3)
Check_all(h); //浏览全部航班
}
/*******************
* 功能描述:航班号查找
* 输入参数: 航班号
* 输出参数: 航班的相关信息
* 返回值: void
* 其它说明:无
********************/
void Check_flightnum(flightlist& h)//航班号查找
{
string flightnum;
flightlist p = h->next;
cout << setw(32) << "请输入航班号:";
cin >> flightnum;
cout << setw(25) << "航班号" << setw(17) << "起飞日期"<<setw(15) << "起飞时间" << setw(15) << "出发地" << setw(15) << "目的地" << setw(15) << "价格" << setw(15) << "折扣" << setw(15) << "余票" << endl;
while (p != NULL)
{
if (p->flight_num== flightnum) //航班号比较
{
cout << setw(25) << p->flight_num << setw(15) << p->date<<"日" << setw(15) << p->time << setw(15) << p->start_place << setw(15) << p->end_place << setw(15) << p->price << setw(15) << p->discount << setw(15) << p->left << endl;
cout << " ";
system("pause");
return;
}
else
p = p->next;
}
cout << setw(32) << "未查到任何信息。";
system("pause");
}
/*******************
* 功能描述:起始地查找
* 输入参数: 起始地
* 输出参数: 航班的相关信息
* 返回值: void
* 其它说明:无
********************/
void Check_seplace(flightlist& h)//起始地查找
{
string start_place, end_place;
cout << " 请输入出发地:";
cin >> start_place;
cout << " 请输入目的地:";
cin >> end_place;
flightlist p = h->next;
cout << setw(25) << "航班号" << setw(17) << "起飞日期" << setw(15) << "起飞时间" << setw(15) << "出发地" << setw(15) << "目的地" << setw(15) << "价格" << setw(15) << "折扣" << setw(15) << "余票" << endl;
while (p != NULL)
{
if (p->start_place==start_place && p->end_place==end_place) //匹配
{
cout << setw(25) << p->flight_num << setw(15) << p->date <<"号"
## 2.读入数据
# 总结
<font color=#999AAA >提示:这里对文章进行总结:
例如:以上就是今天要讲的内容,本文仅仅简单介绍了pandas的使用,而pandas提供了大量能使我们快速便捷地处理数据的函数和方法。<< setw(15) << p->time << setw(15) << p->start_place << setw(15) << p->end_place << setw(15) << p->price << setw(15) << p->discount << setw(15) << p->left << endl;
cout << setw(32);
system("pause");
return;
}
p = p->next; //移动
}
cout << setw(32) << "未查到任何信息";
system("pause");
}
/*******************
* 功能描述:浏览全部航班
* 输入参数:
* 输出参数: 航班的相关信息
* 返回值: void
* 其它说明:无
********************/
void Check_all(flightlist& h)//浏览全部航班
{
Sort_flight(h); //日期排序
flightlist p = h->next;
cout << setw(25) << "航班号" << setw(17) << "起飞日期" << setw(15) << "起飞时间" << setw(15) << "出发地" << setw(15) << "目的地" << setw(15) << "价格" << setw(15) << "折扣" << setw(15) << "余票" << endl;
while (p != NULL)
{
cout << setw(25) << p->flight_num << setw(15) << p->date <<"号"<< setw(15) << p->time << setw(15) << p->start_place << setw(15) << p->end_place << setw(15) << p->price << setw(15) << p->discount << setw(15) << p->left << endl;
p = p->next; //移动
}
}
/*******************
* 功能描述:修改航班信息
* 输入参数:选择修改方式
* 输出参数: 调用相关函数进行实现
* 返回值: void
* 其它说明:无
********************/
void Revise_flight(flightlist& h)//修改航班信息
{
flightlist f = h->next;
int i;
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), FOREGROUND_INTENSITY |FOREGROUND_GREEN); //菜单绿色
cout << " ┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅ " << endl;
cout << " ┇ ≡ 修改方式 ≡ ┇ " << endl;
cout << " ┇ ┇ " << endl;
cout << " ┇ 1.删除航班 ┇ " << endl;
cout << " ┇ ┇ " << endl;
cout << " ┇ 2.修改起飞时间 ┇ " << endl;
cout << " ┇ ┇ " << endl;
cout << " ┇ 3.修改航班价格 ┇ " << endl;
cout << " ┇ ┇ " << endl;
cout << " ┇ 4.返回 ┇ " << endl;
cout << " ┇ ┇ " << endl;
cout << " ┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅ " << endl;
cout << " 请输入查找方式:";
cin >> i;
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), FOREGROUND_INTENSITY | FOREGROUND_RED); //红色
Check_all(h); //浏览全部
if (i == 1)
Delete_flight(h); //删除航班
else if (i == 2)
Revise_time(h); //修改起飞时间
else if (i == 3)
Revise_price(h); //修改航班价格
else if (i == 4)
return;
}
/*******************
* 功能描述:删除航班
* 输入参数:航班号
* 输出参数: 删除成功
* 返回值: void
* 其它说明:无
********************/
void Delete_flight(flightlist& h)//删除航班
{
flightlist p = h->next, q = h; //q是p的前驱
string flightnum;
cout << " 请输入您想要修改的航班号:";
cin >> flightnum;
while (p != NULL)
{
if (p->flight_num== flightnum) //航班号匹配
{
q->next = p->next; //p是要删除的结点,q是前一个结点
delete p;
cout << " 删除成功!";
return;
}
q = q->next; //移动
p = q->next;
}
cout << " 未查找到相关航班!";
}
/*******************
* 功能描述:修改起飞抵达时间
* 输入参数:航班号,新的航班号
* 输出参数: 修改成功
* 返回值: void
* 其它说明:无
********************/
void Revise_time(flightlist& h)//修改起飞抵达时间
{
string flightnum;
flightlist p = h->next;
cout << " 请输入您想要修改的航班号:";
cin >> flightnum;
while (p != NULL)
{
if (p->flight_num==flightnum)
{
cout << " 请输入新的起飞日期:";
cin >> p->date;
cout << " 请输入新的起飞时间:";
cin >> p->time;
cout << " 修改成功!";
return;
}
p = p->next;
}
cout << " 没有您想要修改的航班号!";
system("pause");
}
/*******************
* 功能描述:修改价格
* 输入参数:航班号,新的价格和折扣
* 输出参数: 修改成功
* 返回值: void
* 其它说明:无
********************/
void Revise_price(flightlist& h)//修改价格
{
string flightnum;
flightlist p = h->next;
cout << " 请输入您想要修改的航班号:";
cin >> flightnum;
while (p != NULL)
{
if (p->flight_num==flightnum)
{
cout << " 请输入新的价格:";
cin >> p->price;
cout << " 请输入新的折扣:";
cin >> p->discount;
cout << " 修改成功! ";
return;
}
p = p->next;
}
cout << " 没有您想要修改的航班号!";
system("pause");
}
/*******************
* 功能描述:保存航班信息
* 输入参数:无
* 输出参数:用户的信息到文件FlightList.dat
* 返回值: void
* 其它说明:
********************/
void Save_flight(flightlist& h)//保存航班信息
{
flightlist f = h->next;
Sort_flight(h);
ofstream outfile("d:\\FlightList.dat", ios::trunc);
if (!outfile)
{
cout << " 存储失败!";
return;
}
while (f != NULL)
{
outfile << f->flight_num << " " << f->date << " " << f->time << " " << f->start_place << " " << f->end_place << " " << f->price << " " << f->discount << " " << f->left << endl;
f = f->next;
}
outfile.close(); //关闭文件
}
/*******************
* 功能描述:初始化用户
* 输入参数: 无
* 输出参数: 无
* 返回值: void
* 其它说明:无
********************/
void Init_passenger(passengerlist& c)//初始化用户
{
c = new passengernode; //头结点
c->next = NULL;
}
/*******************
* 功能描述:载入用户信息
* 输入参数: 载入PassengerList.dat信息到链表
* 输出参数: 无
* 返回值: void
* 其它说明:无
********************/
void Load_passenger(passengerlist& c)//载入用户信息
{
passengerlist p = c;
passengerlist newp= new passengernode;
ifstream infile("d:\\PassengerList.dat", ios::in);//以输入的方式打开文件
if (!infile)
{
cout << " 信息错误。";
return;
}
while (1)
{
infile >> newp->name >> newp->ID_num >> newp->ticket.flight_num >> newp->ticket.date >> newp->ticket.time >> newp->ticket.start_place >> newp->ticket.end_place >> newp->ticket.price>> newp->ticket.order_num;
if (!infile.eof())
{
p->next = newp;
p = p->next;
newp = new passengernode;
}
else
break;
}
p->next = NULL;
delete newp;
}
/*******************
* 功能描述:航班信息
* 输入参数:passenger的相关信息
flight的相关信息
* 输出参数: 购票成功 or 失败
* 返回值: void
* 其它说明:如果余票不足还可以预定,如果有多余的票即可瞬间购买
********************/
void Book(flightlist& h, passengerlist& c)//订票
{
string start_place, end_place, flightnum;
int date;//航班信息
flightlist p = h->next, q = h->next;
passengerlist s, r = c;
char mark, check = '1';
char mark02 = '1'; //标志
for (; r->next != NULL; r = r->next) {} //r移动到结点尾
s = new passengernode;
cout << " 请输入乘客的姓名:";
cin >> s->name;
cout << " 请输入乘客的证件号:";
cin >> s->ID_num;
cout << " 请输入出发地:";
cin >> start_place;
cout << " 请输入目的地:";
cin >> end_place;
cout << " 请选择出发日期:";
cin >> date;
cout << setw(25) << "航班号" << setw(17) << "起飞日期" << setw(15) << "起飞时间" << setw(15) << "出发地" << setw(15) << "目的地" << setw(15) << "价格" << setw(15) << "折扣" << setw(15) << "余票" << endl;
while (p != NULL)
{
if (p->start_place==start_place && p->end_place==end_place&&p->date==date)//匹配日期相符的航班
{
cout << setw(25) << p->flight_num << setw(15) << p->date <<"号"<< setw(15) << p->time << setw(15) << p->start_place << setw(15) << p->end_place << setw(15) << p->price << setw(15) << p->discount << setw(15) << p->left << endl;
check = '0'; //找到
}
p = p->next;
}
if (check == '1') //未匹配到日期相符的航班
{
p = h->next;
cout << setw(25) << "无" << setw(15) << "无" << setw(17) << "无" << setw(15) <<"无" << setw(15) << "无" << setw(15) << "无" << setw(15) << "无" << setw(15) <<"无" << endl;
cout << endl;
cout << endl;
cout << " 该天没相关的航班.....以下是为您推荐的隔天航班:"<<endl;
cout << endl;
cout << setw(25) << "航班号" << setw(17) << "起飞日期" << setw(15) << "起飞时间" << setw(15) << "出发地" << setw(15) << "目的地" << setw(15) << "价格" << setw(15) << "折扣" << setw(15) << "余票" << endl;
while (p != NULL)
{
if (p->start_place == start_place && p->end_place == end_place ) //匹配起始地,到达地相同的航班
{
mark02 = '0'; //找到
cout << setw(25) << p->flight_num << setw(15) << p->date <<"号"<< setw(15) << p->time << setw(15) << p->start_place << setw(15) << p->end_place << setw(15) << p->price << setw(15) << p->discount << setw(15) << p->left << endl;
}
p = p->next;
}
if (mark02=='1') //没找到起始地,到达地相同的航班
{
return;//结束
}
}
cout << " 是否进行购买?(Y/N)" ;
cin >> mark;
if (mark=='y'||mark=='Y')
{
cout << " 请输入您想要购买的航班号:";
cin >> flightnum;
while (q != NULL)
{
if (q->flight_num==flightnum && q->start_place==start_place&& q->end_place==end_place)//匹配
{
if (q->left == 0)//余票为零
{
cout << " 余票不足,请选择是否预约(是“y”/否“n”)";
cin >> mark;
if (mark == 'y'||mark=='Y')
{
s->full = 1; //修改预约标志
s->ticket.flight_num= flightnum;
s->ticket.start_place = start_place;
s->ticket.end_place = end_place;
s->ticket.time = "预约";
s->ticket.price = 000;
s->ticket.date = date;
s->ticket.order_num= "预约";
cout << " 预约成功,等待短信提醒!";
r->next = s;
r = s;
r->next = NULL;
system("pause");
return;
}
else
return; //不预约直接结束
}
s->ticket.flight_num=flightnum;
s->ticket.start_place=start_place;
s->ticket.end_place= end_place;
s->ticket.time= q->time;
s->ticket.price = q->price;
s->ticket.date = q->date;
srand(time(0));
s->ticket.order_num = q->flight_num + to_string(rand())+ to_string(rand());//订单编号
r->next = s;
r = s;
r->next = NULL;
//购票成功
cout << " 购票成功!"<<"订单号为" + s->ticket.order_num << endl;
q->left--;//机票数更新
cout << " ";
system("pause");
return;
}
else
q = q->next;
}
cout << " 航班号填入错误!" << endl;
cout << " ";
system("pause");
}
else
{
return ;//不进行购买直接结束
}
}
/*******************
* 功能描述:退票
* 输入参数:passenger的相关信息
* 输出参数: 退票成功 or 失败
* 返回值: void
* 其它说明:
********************/
void Qbook(flightlist& h, passengerlist& c)//退票
{
string name,ID_num;
char mark = '0';
flightlist f = h->next;
passengerlist p = c->next, q = c, t = c->next;
cout << " 请输入乘客的姓名:";
cin >> name;
cout << " 请输入乘客的证件号:";
cin >> ID_num;
while (p != NULL)//乘客扫描
{
if (p->name==name&& p->ID_num==ID_num) //匹配
{
mark = '1'; //找到乘客
while (f != NULL)//航班扫描
{
if (p->ticket.flight_num==f->flight_num) //查到相关航班
{
f->left++; //票数更新
while (t != NULL) //乘客扫描
{
if (t->ticket.flight_num== p->ticket.flight_num && t->full == 1)//查看是否有预约的
{
t->ticket.start_place= p->ticket.start_place;
t->ticket.end_place=p->ticket.end_place;
t->ticket.time= p->ticket.time;
t->ticket.price = p->ticket.price;
t->ticket.date = p->ticket.date;
srand(time(0));
t->ticket.order_num = p->ticket.flight_num.c_str()+ to_string(rand())+ to_string(rand());
f->left--;
break;
}
t = t->next;
}
break;
}
f = f->next;
}
q->next = p->next;
delete p;
cout << " 退票成功!";
return;
}
q = q->next;
p = q->next;
}
if(mark=='0') //没找到
{
cout << " 未找到相关乘客的订单";
system("pause");
}
}
/*******************
* 功能描述:查询订票
* 输入参数:passenger的相关信息
* 输出参数: 所查用户订票的信息
* 返回值: void
* 其它说明:
********************/
void Check_book(passengerlist& c)//查询订票
{
string name, ID_num;
passengerlist p = c->next;
cout << " 请输入乘客的姓名:";
cin >> name;
cout << " 请输入乘客的证件号:";
cin >> ID_num;
cout << setw(25) << "姓名" << setw(15) << "航班号" << setw(17) << "起飞日期" << setw(15) << "起飞时间" << setw(15) << "出发地" << setw(15) << "目的地" << setw(15) << "价格" << setw(18) << "订单编号" << endl;
while (p != NULL)
{
if (p->name==name && p->ID_num==ID_num)//匹配
{
cout << setw(25) << p->name << setw(15) << p->ticket.flight_num << setw(15) << p->ticket.date <<"号"<< setw(15) << p->ticket.time << setw(15) << p->ticket.start_place << setw(15) << p->ticket.end_place << setw(15) << p->ticket.price << setw(18) << p->ticket.order_num << endl;
cout << " ";
system("pause");
return;
}
else
p = p->next;
}
cout << setw(32) << "未查到任何信息。";
system("pause");
}
/*******************
* 功能描述:保存用户信息
* 输入参数:无
* 输出参数:用户的信息到文件d:\\PassengerList.dat
* 返回值: void
* 其它说明:
********************/
void Save_passenger(passengerlist& c)//保存用户信息
{
passengerlist p = c->next;
ofstream outfile("d:\\PassengerList.dat", ios::trunc); //ios::trunc清空再重写
if (!outfile)
{
cout << " 存储失败!";
return;
}
while (p != NULL)
{
outfile << p->name << " " << p->ID_num << " " << p->ticket.flight_num << " " << p->ticket.date << " " << p->ticket.time << " " << p->ticket.start_place << " " << p->ticket.end_place << " " << p->ticket.price<< " " << p->ticket.order_num << endl;
p = p->next;
}
outfile.close();//关闭文件
}
还有很多功能就不一一截图了,有时间再测试。
总结
第一次写博客,不太熟练。先这样子,记录一下自己的学习。代码也还有很多不足之处。