c++航班管理系统
发布时间
阅读量:
阅读量
c++航班管理系统
本文为转载,仅供学习参考!
#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <malloc.h>
#include <iostream>
#include <fstream>
#include <stdio.h>
#include<stdlib.h>
#include<string.h>
using namespace std;
#define MaxSize 200
typedef struct plane //飞机结构体
{
char plane_number[10]; //航班号
char beplace[10]; //飞机起飞地点
char enplace[10]; //飞机降落地点
char date[15]; //飞机起飞时间
char timearrival[15]; //飞机到达时间
int price; //飞机票价
double discount; //折扣
int vacancy; //空位
struct plane *next;
}plane;
typedef struct individual //人的结构体
{
char name[30];
char in_id[30];
char plane_number[20];//航班号
int seat;//座位号
struct individual *next;
}individual;
typedef struct plane_head //定义飞机的头结点
{
int count;
plane *next;
}plane_head;
typedef struct in_head //定义人的头结点
{
int count;
individual *next;
}in_head;
plane_head *import(int n, plane_head *pheadline)//录入航班
{
plane *temp = new plane;
temp->next = NULL;
pheadline->next = temp;
pheadline->count = n;
for (int i = 0; i < n; i++)
{
cout << "请输入第" << i + 1 << "个航班的航班号: ";
cin >> temp->plane_number;
cout << "请输入第" << i + 1 << "个航班的起飞地: ";
cin >> temp->beplace;
cout << "请输入第" << i + 1 << "个航班的将落地: ";
cin >> temp->enplace;
cout << "请输入第" << i + 1 << "个航班的起飞时间: ";
cin >> temp->date;
cout << "请输入第" << i + 1 << "个航班的降落时间: ";
cin >> temp->timearrival;
cout << "请输入第" << i + 1 << "个航班的票价: ";
cin >> temp->price;
cout << "请输入第" << i + 1 << "个航班的折扣: ";
cin >> temp->discount;
cout << "请输入第" << i + 1 << "个航班的空位数: ";
cin >> temp->vacancy;
cout << "第" << i + 1 << "个航班成功录入。" << endl;
if (i < n - 1)
{
temp->next = new plane;
while (i > 1)
{
if (temp->plane_number == temp->next->plane_number)
{
cout << "分配失败。" << endl;
exit(1);
}
}
temp->next->next = NULL;
temp = temp->next;
}
}
return pheadline;
}
plane *query(plane_head *phead) //查询航班
{
int s;
plane *find = NULL;
plane *temp;
cout << "****************************************************************" << endl;
cout << "*** 1、按航班号查询航班。 ***" << endl;
cout << "*** 2、按起飞地查询航班。 ***" << endl;
cout << "****************************************************************" << endl;
cout << "请选择:";
cin >> s;
cout << endl;
switch (s)
{
case 1:
{
cout << "请输入航班号:";
char plane_number[20];
cin >> plane_number;
temp = phead->next;
while (temp)
{
if (strcmp(temp->plane_number, plane_number) == 0)
{
find = temp;
return temp;
break;
}
else
{
temp = temp->next;
}
}
if (!temp)
{
cout << "没有找到该航班信息。" << endl;
return NULL;
}
break;
}
case 2:
{
char beplace[10];
char enplace[10];
cout << "请输入起飞地点:";
cin >> beplace;
cout << "请输入降落地点:";
cin >> enplace;
temp = phead->next;
while (temp)
{
if (strcmp(temp->beplace, beplace) == 0 && strcmp(temp->enplace, enplace) == 0)
{
find = temp;
break;
}
temp = temp->next;
}
if (!temp)
{
cout << "没有找到该航班信息。" << endl;
return NULL;
}
break;
}
return find;
}
}
void display_plane(plane *node) //打印一个航班信息
{
if (node == NULL)
{
cout << "输入失败。" << endl;
return;
}
cout << endl;
cout << "航班号\t\t 起飞地\t\t 目的地\t\t 起飞时间\t 到达时间\t 票价\t\t 折扣\t\t 空位\t" << endl;
cout << node->plane_number << "\t\t" << node->beplace << "\t\t" << node->enplace << "\t\t" << node->date << "\t\t" << node->timearrival << "\t\t" << node->price << "\t\t" << node->discount << "\t\t" << node->vacancy << "\t\t" << endl;
}
void all_display_plane(plane_head *headline) //打印所有航班信息
{
cout << endl;
plane *node;
node = headline->next;
if (!node)
{
cout << "当前没有航班信息。" << endl;
return;
}
cout << "航班数目 " << headline->count << endl;
while (node)
{
display_plane(node);
node = node->next;
}
}
void display_in(individual *node) //打印一个客户信息
{
if (node == NULL)
{
cout << "输出失败。" << endl;
return;
}
cout << endl;
cout << "姓名\t\t" << "证件号\t\t" << "航班号\t\t" << "座号\t\t" << endl << endl;
cout << node->name << "\t\t" << node->in_id << "\t\t" << node->plane_number << "\t\t" << node->seat << "\t\t" << endl;
}
void all_display_in(in_head *headline) //打印所有客户信息
{
individual *node = headline->next;
if (!node)
{
cout << "当前没有客户信息。" << endl;
return;
}
while (node)
{
display_in(node);
node = node->next;
}
}
int buyticket(plane_head *headline, in_head *headclient) //订票
{
cout << "请输入航班号 ";
char plane_number[10];
cin >> plane_number;
plane *temp;
temp = headline->next;
while (temp)
{
if (strcmp(temp->plane_number, plane_number) == 0)
{
break;
}
temp = temp->next;
}
if (!temp)
{
cout << "未找到该航班。" << endl;
return 0;
}
if (temp->vacancy == 0)
{
cout << "对不起,该航班票已售完。" << endl;
cout << "请选择其他航班。" << endl;
cout << "按任意键返回主菜单。" << endl;
int n;
cin >> n;
}
individual *custom = new individual;
cout << "请输入您的证件号码 ";
cin >> custom->in_id;
cout << "请输入您的姓名 ";
cin >> custom->name;
cout << endl;
custom->seat = temp->vacancy - temp->vacancy + 1;
custom->next = NULL;
strcpy(custom->plane_number, plane_number);
temp->vacancy--;
headclient->count++;
custom->next = headclient->next;
headclient->next = custom;
cout << "订票成功。" << endl << endl;
return 1;
}
int returnticket(plane_head *headline, in_head *headclient) //退票
{
cout << "请输入您的姓名 " << endl;
char name[30];
cin >> name;
cout << "请输入您的证件号码 " << endl;
char in_id[30];
cin >> in_id;
cout << "请输入您的航班号 " << endl;
int number;
cin >> number;
plane *airlinetemp = headline->next;
individual *clienttemp = headclient->next;
if (NULL == airlinetemp)
{
cout << "当前没有航班信息。" << endl;
return 0;
}
char plane_number[10];
individual *deInext;
if (strcmp(clienttemp->next->in_id, in_id) == 0) //要删除的节点为第一个时
{
strcpy(plane_number, clienttemp->plane_number);
headclient->next = clienttemp->next;
delete clienttemp;
while (airlinetemp) //修改退票客户所对应的航班售票信息
{
if (strcmp(plane_number, airlinetemp->plane_number) == 0)
{
airlinetemp->vacancy++;
break;
}
airlinetemp = airlinetemp->next;
}
cout << "退票成功。" << endl << endl;
return 1;
}
while (clienttemp->next) //要删除的节点不是第一个时
{
if (strcmp(clienttemp->next->in_id, in_id) == 0)
{
strcpy(plane_number, clienttemp->next->plane_number);
deInext = clienttemp->next->next;
delete clienttemp->next;
clienttemp->next = deInext;
while (airlinetemp) //修改退票客户所对应的航班售票信息
{
if (strcpy(plane_number, airlinetemp->plane_number) == 0)
{
airlinetemp->vacancy++;
break;
}
airlinetemp = airlinetemp->next;
}
cout << "退票成功。" << endl << endl;
return 1;
break;
}
clienttemp = clienttemp->next;
}
cout << "未找到该客户信息。" << endl;
return 0;
}
int savemessage(plane_head *headline, in_head *headclient) //保存航班和客户信息到相应的文件中
{
ofstream outline("airline.txt", ios::out); //文件写操作 内存写入存储设备
if (!outline)
{
cout << "航班信息打开失败。" << endl;
return 0;
}
cout << "正在保存航班信息..." << endl;
outline << headline->count << endl;
plane *linetemp = headline->next;
while (linetemp)
{
outline << linetemp->plane_number << " " << linetemp->beplace << " " << linetemp->enplace << " " << linetemp->date << " " << linetemp->timearrival << " " << linetemp->price << " " << linetemp->discount << " " << linetemp->vacancy << " " << endl;
linetemp = linetemp->next;
}
outline.close();
cout << "航班信息保存成功。" << endl;
ofstream outclient("client.txt", ios::app);
if (!outclient)
{
cout << "客户信息文件打开失败。" << endl;
return 0;
}
cout << "正在保存客户信息..." << endl;
outclient << headclient->count << endl;
individual *clienttemp = headclient->next;
while (clienttemp)
{
outclient << clienttemp->name << " " << clienttemp->in_id << " " << clienttemp->plane_number << " " << clienttemp->seat << " " << endl;
clienttemp = clienttemp->next;
}
outclient.close();
cout << "客户信息保存成功。" << endl;
return 1;
}
int change_plane(plane_head *headline) //修改航班信息
{
cout << "当前所有航班信息为 " << endl;
plane *temp;
temp = headline->next;
plane *t = headline->next;
while (t)
{
display_plane(t);
t = t->next;
}
cout << endl;
cout << "请选择您要进行的操作 " << endl;
cout << "1、增加航班。" << endl;
cout << "2、删除航班。" << endl;
cout << "3、修改当前航班信息。" << endl;
int select;
cin >> select;
cout << endl;
if (select > 3 || select < 1)
{
cout << "输入错误。" << endl;
return 0;
}
switch (select)
{
case 1:
{
plane *tem = new plane;
cout << "请输入要增加的航班号 ";
cin >> tem->plane_number;
cout << "请输入航班的起飞地点 ";
cin >> tem->beplace;
cout << "请输入航班的到达地点 ";
cin >> tem->enplace;
cout << "请输入航班的起飞时间 ";
cin >> tem->date;
cout << "请输入航班的到达时间 ";
cin >> tem->timearrival;
cout << "请输入航班的票价 ";
cin >> tem->price;
cout << "请输入航班的折扣 ";
cin >> tem->discount;
cout << "请输入航班的空位数 ";
cin >> tem->vacancy;
cout << "增加成功。" << endl;
if (temp == NULL)
tem = headline->next;
else
{
tem->next = temp->next; //将结点tem插入到temp之后
temp->next = tem;
}
break;
}
case 2:
{
cout << "请输入您要删除的航班号 ";
char plane_number[10];
cin >> plane_number;
plane *delline = new plane;
delline = headline->next;
while (delline)
{
if (strcmp(delline->plane_number, plane_number) == 0)
{
plane *plink;
plink = delline->next;
delete delline;
headline->next = plink;
headline->count--;
cout << "删除成功。" << endl;
}
delline = delline->next;
}
break;
}
case 3:
{
cout << "请输入您要修改的航班号 ";
char plane_number3[20];
cin >> plane_number3;
temp = headline->next;
while (temp)
{
if (strcmp(temp->plane_number, plane_number3) == 0)
{
cout << "请选择您要修改的内容 " << endl;
cout << "1、空位数。--" << endl;
cout << "2、起飞地点。--" << endl;
cout << "3、降落地点。--" << endl;
cout << "4、起飞时间。--" << endl;
cout << "5、降落时间。--" << endl;
cout << "6、票价。--" << endl;
cout << "7、折扣。--" << endl;
int p;
cin >> p;
switch (p)
{
case(1):
{
cout << "请输入您要修改的空位数为 ";
int a;
cin >> a;
temp->vacancy = a;
cout << "修改成功。" << endl;
break;
}
case(2):
{
cout << "请输入您要修改的起飞地点为 ";
char s[20];
cin >> s;
strcpy(temp->beplace, s);
cout << "修改成功。" << endl;
break;
}
case(3):
{
cout << "请输入您要修改的降落地点为 ";
char d[20];
cin >> d;
strcpy(temp->enplace, d);
cout << "修改成功。" << endl;
break;
}
case(4):
{
cout << "请输入您要修改的起飞时间为 ";
char e[10];
cin >> e;
strcpy(temp->date, e);
cout << "修改成功。" << endl;
break;
}
case(5):
{
cout << "请输入您要修改的降落时间为 ";
char f[10];
cin >> f;
strcpy(temp->timearrival, f);
cout << "修改成功。" << endl;
break;
}
case(6):
{
cout << "请输入您要修改的票价为 ";
int b;
cin >> b;
temp->price = b;
cout << "修改成功。" << endl;
break;
}
case(7):
{
cout << "请输入您要修改的折扣为 ";
double c;
cin >> c;
temp->discount = c;
cout << "修改成功。" << endl;
break;
}
}
}
temp = temp->next;
break;
}
}
return 1;
}
}
void main_menu() //目录
{
cout << "********************欢迎使用飞机售票系统******************" << endl;
cout << "*** 1----录入航班信息。 ***" << endl << endl;
cout << "*** 2----修改航班信息。 ***" << endl << endl;
cout << "*** 3----查询航线信息。 ***" << endl << endl;
cout << "*** 4----客户订票。 ***" << endl << endl;
cout << "*** 5----客户退票。 ***" << endl << endl;
cout << "*** 6----保存操作。 ***" << endl << endl;
cout << "*** 7----输出所有航班信息。 ***" << endl << endl;
cout << "*** 8----输出所有顾客信息。 ***" << endl << endl;
cout << "*** 0----退出系统 。 ***" << endl << endl;
cout << "****************************************************************" << endl << endl;
}
int main()
{
plane_head *headline = new plane_head;
headline->count = 0;
headline->next = NULL;
in_head *headclient = new in_head;
headclient->count = 0;
headclient->next = NULL;
while (1)
{
main_menu();
int n;
cout << "请选择您要进行的操作:";
cin >> n;
cout << endl;
switch (n)
{
case 1:
int num;
cout << "请选择您要录入的航班数目 ";
cin >> num;
cout << endl;
import(num, headline);
cout << endl;
cout << "航班信息成功录入。";
cout << endl << endl;
break;
case 2:
change_plane(headline);
break;
case 3:
plane *find;
find = query(headline);
if (find)
{
display_plane(find);
}
break;
case 4:
buyticket(headline, headclient);
break;
case 5:
returnticket(headline, headclient);
break;
case 6:
savemessage(headline, headclient);
break;
case 7:
all_display_plane(headline);
break;
case 8:
all_display_in(headclient);
break;
case 0:
exit(1);
break;
}
}
return 0;
}

全部评论 (0)
还没有任何评论哟~
