大家好,又见面了,我是你们的朋友全栈君。
1. 题目
本课程设计的题目为:飞机订票系统。
2. 项目描述
基于目前人们外出远行频繁,为方便乘客提前买票及优化飞机航空订票服务,需要开发一个飞机订票系统,此程序就是要实现航班情况的录入,查询,订票,退票以及航班的查询和修改等基本功能。
3. 数据及其逻辑结构分析
(1)航班的信息:航班的情况存储结构采用单链表,每个元素表示一个航班的情况,包括航班号、起飞时间、降落时间、起飞城市、抵达城市、航班票价、票价折扣、确定航班是否满仓和空座数九个数据项:
航班号 |
起飞 时间 |
降落 时间 |
起飞 城市 |
抵达 城市 |
航班 是否满仓 |
空座数 |
票价 |
票价 折扣 |
字符串 |
字符串 |
字符串 |
字符串 |
字符串 |
整数 (int) |
整数 (int) |
浮点数 (float) |
浮点数 (float) |
每个结点包括数据域和指针域:
数据域 |
指针域 |
C语言描述如下:
typedef struct flightnode{
char flight_num[10];//航班号
char start_time[10];//起飞时间
char end_time[10];//抵达时间
char start_place[20];//起飞城市
char end_place[20]; //抵达城市
int left; //空座数
float price; //票价
float price_discount;//票价折扣
int isFull; //航班是否满仓
struct flightnode *next;//指向下一个结点
}flightnode;//航班结点
(2)客户的资料:为了便于插入、删除和修改,其采用单链表存储结构,每个数据元素包括姓名、证件号、航班号、订票数量和订单号五个数据项:
姓名 |
证件号 |
航班号 |
订票数量 |
订单号 |
字符串 |
字符串 |
字符串 |
整数(int) |
整数(int) |
每个结点包括数据域和指针域:
数据域 |
指针域 |
C语言描述如下:
typedef struct passengernode{//定义客户资料结点
char name[20]; //姓名
char ID_num[20]; //证件号
char flight_num[10];//航班号
int order_num; //订单号
int ticket_num; //订票数量
struct passengernode *next;//指向下一个结点
}passengernode;/客户结点
(3)客户链表:每个数据元素包括头指针和尾指针两个数据项:
每个结点包括两个指针域:
头指针域 |
尾指针域 |
C语言描述如下:
typedef struct passengerList{
passengernode *head;
passengernode *rear;
}passengerList;
4. 数据的存储结构设计
程序运行时会从文件中将航班数据调入内存,并且以单链表的存储方式进行存储。每个链表结点的数据域有一个用户自定义结构体组成,结构体内包含有详细的航班有关信息。
5. 系统模块组成
1 录入航班信息模块
void add_flight(flightnode *&h)调用void insert_flight(flightnode *&h,char* flight_num,char* start_place,char* end_place,char* start_time,char* end_time,int left,float price,float price_discount,int isFull)函数,将新航班结点插入航班链表中。
2 客户订票模块
int book(flightnode *&h,passengerList *&PList)函数调用int insert_passenger(passengernode *&h,char *name,char *ID_num,char *flight_num,int ticket_num,int order_num)函数,将新客户结点插入客户链表中。
3 客户退票模块
void cancel(passengerList *&PList,flightnode *&h)函数调用int delete_passenger(passengerList *&PList,flightnode *&h,char *name,char *ID_num)函数,将相应的顾客结点删除,并修改相应的航班信息。
4 查询航班模块
void flight_check(flightnode *h)调用void check_all_flight(flightnode *h)函数进行所有航班信息浏览,调用int place_check(flightnode *h,char *start_place,char *end_place)函数按起飞抵达城市对航班进行查询,调用int flight_num_check(flightnode *h,char *flight_num)按航班号对航班进行查询。
5 查询订单模块
void passenger_check(passengerList *PList)调用void check_all_passenger(passengerList *PList)函数进行所有订单信息浏览,调用int order_num_check(passengerList *PList,int order_num)函数按订单号对订单进行查询,调用int ID_name_check(passengerList *PList,char *name,char *ID_num)按客户姓名和证件号对订单进行查询。
6 修改航班模块
增加航班时,void modify_flight(flightnode *&h,passengerList *&PList)函数调用void add_flight(flightnode *&h)函数,将新航班信息结点插入航班链表中。
删除航班时,void modify_flight(flightnode *&h,passengerList *&PList)函数调用void delete_flight(flightnode *&h,passengerList *&PList)函数将相应的航班信息删除,并删除相应的订单信息。
修改航班时间时,void modify_flight(flightnode *&h,passengerList *&PList)函数修改指定航班的起飞抵达时间。
项目实现结果
(1) 编译链接后显示菜单
(2) 输入菜单号“1”,开始航班信息的录入
(3) 输入菜单号“2”,进入订票模块
(4) 输入菜单号“3”,进入退票模块
(5) 输入菜单号“4”,查询航班信息
a. 输入菜单号“1”,按航班号查询航班信息
b. 输入菜单号“2”,按起飞抵达城市查询航班信息
(6) 输入菜单号“5”,查询订单信息
a. 输入菜单号“1”,按客户姓名和证件号查询订单信息
b. 输入菜单号“2”,按订单号查询订单信息
(7) 输入菜单号“6”,进入航班修改模块
a. 输入菜单号“1”,增加航班
b. 输入菜单号“2”,删除航班
c. 输入菜单号“3”,修改航班时间
(8)管理员模式显示全部订单
(9) 输入菜单号“0”,退出本系统
课程设计总结
经过这几天的数据结构课程设计,我收获很大,在实现系统功能的过程中,也遇到很多问题,及时的向周围的同学请教,寻求帮助,设计修改,编写调试,每一步都渗透着沟通和分析,每一次沟通之后,都会对系统功能有更深层次的理解和阐述,这也促使我一步步完成了整个系统,并使之可以运行。时间太短暂了,我没有办法把全部学到的知识运用到具体的系统实现中,深深感受到数据结构这门课程的重要性,以及它在实际应用中的广泛性。这个飞机订票系统由于种种原因仍然存在需要改进,需要完善的地方,我对于这个系统的认识和对数据结构这门课程的理解已经更加深入了。在实现系统的过程中,我感受到自己的知识的薄弱零散,经过这次做系统,我觉得自己的知识得到巩固和整合,知识体系更加系统化。我也深深体会到实践检验真理,只有实践中,才能出真知。我懂得了学习不只是纸上谈兵,更重要的是实践,就比如平常我们在学习中经常会遇到一些问题,看似无关紧要跳过去,不求甚解,在得知答案的时候,总是感觉心领神会,久而久之,对于的知识点就模棱两可,形成知识漏洞。但这次课程设计所要编写的程序很长,涉及的知识点也很多,选择此题目的时候我心里面还底气十足,自认为没什么问题,对于程序的步骤仿佛了然于胸,但在实际操作中才发现并非如此,在编写程序的过程中,我不断地上网查阅相关资料进行学习,积极地思考该怎样实现系统的每一个功能。
通过这次数据结构的课程设计,我巩固和加深对数据结构基本知识的理解,锻炼了综合运用课本知识的能力,自己也真正地完整而系统地设计并编写了一个程序,使得自己的编程能力大为提高。通过对我所选择飞机订票系统的设计和编写,我初步掌握简单软件的分析方法和设计方法,第一次体会到了数据结构编程知识在实际生活中的重要性和应用的广泛性,最后,我要感谢老师和同学们,正是因为他们的热心帮助,我才能正确的完成这次课程设计。在今后的学习和工作中,会更加深入地把知识和思想体会更广泛地应用到其他学科的学习中。
源代码:
# include <stdio.h>
# include <string.h>
# include <malloc.h>
# include <windows.h>
# include <fstream>
# include <iostream>
using namespace std;
typedef struct flightnode{
char flight_num[10]; //航班号
char start_time[10]; //起飞时间
char end_time[10]; //抵达时间
char start_place[20];//起飞城市
char end_place[20]; //抵达城市
int left; //空座数
float price; //票价
float price_discount;//票价折扣
int isFull; //航班是否满仓
struct flightnode *next;//指向下一个结点
}flightnode;//航班结点
typedef struct passengernode{
char name[20]; //姓名
char ID_num[20]; //证件号
char flight_num[10];//航班号
int order_num; //订单号
int ticket_num; //订票数量
struct passengernode *next;//指向下一个结点
}passengernode;//客户结点
typedef struct passengerList
{
passengernode *head;
passengernode *rear;
}passengerList;
void init_flight(flightnode *&h)//目的是要建立一个以h为头结点的空链表,录入航班信息和增加航班后将航班结点插入该链表
{
h=(flightnode *)malloc(sizeof(flightnode));//申请头结点的空间
if(h==NULL) exit(0);
h->next=NULL;//将头结点h的指针域置为空
}
void init_passengerList(passengerList *&pList)
{
pList=(passengerList *)malloc(sizeof(passengerList));
pList->head=(passengernode *)malloc(sizeof(passengernode));//创建头结点
pList->rear=pList->head;
pList->rear->order_num=0;//订单号从0开始计数
pList->head->next=NULL;
}
void insert_flight(flightnode *&h,char* flight_num,char* start_place,char* end_place,char* start_time,char* end_time,int left,float price,float price_discount,int isFull)
//在录入航班情况或增加新的航班后,将新的航班结点插入到航线链表中
{
flightnode *q;//定义q为新增加的航班结点的指针的形参
flightnode *p=h;
q=(flightnode *)malloc(sizeof(flightnode));//为q结点申请空间
strcpy(q->flight_num,flight_num);
strcpy(q->start_place,start_place);
strcpy(q->end_place,end_place);
strcpy(q->start_time,start_time);
strcpy(q->end_time,end_time);
q->left=left;
q->price=price;
q->price_discount=price_discount;
q->isFull=isFull;
//以上是用strcpy函数将新增加航班的各种信息复制到q结点中
q->next=p->next;//将q结点的指针域置为空
p->next=q;
p=p->next;//将指针后移
}
void add_flight(flightnode *&h)//录入航班信息后调用insert_flight函数增加航班
{
flightnode *p=h;
char flight_num[10],start_time[10],end_time[10],start_place[20],end_place[20];
int left,isFull,mark=1;
float price,price_discount;
for(;p->next!=NULL;p=p->next){}//移动指针,找到最后一个结点
while(mark==1)
{
printf("\t\t请输入你要增加的航班号:");
scanf("%s",flight_num);
printf("\t\t请输入出发地:");
scanf("%s",start_place);
printf("\t\t请输入目的地:");
scanf("%s",end_place);
printf("\t\t请输入起飞时间:");
scanf("%s",start_time);
printf("\t\t请输入抵达时间:");
scanf("%s",end_time);
printf("\t\t请输入票价:");
scanf("%f",&price);
printf("\t\t请输入折扣:");
scanf("%f",&price_discount);
printf("\t\t请输入剩余座位数:");
scanf("%d",&left);
printf("\t\t请输入是否满仓(0表示没有满仓1以满仓):");
scanf("%d",&isFull);
insert_flight(p,flight_num,start_place,end_place,start_time,end_time,left,price, price_discount,isFull);
printf("\t\t增加航班%s成功!\n",flight_num);
printf("\t\t是否继续录入航班信息(1表示继续录入;0表示停止录入).\n");
printf("\t\t请输入:");
scanf("%d",&mark);
}
}
void save_passenger(passengerList *PList)
{
FILE* fp = fopen("passenger.dat","wb");
if(fp==NULL)
return;
passengernode *temp=PList->head->next;
while(temp!=NULL)
{
fwrite(temp,sizeof(passengernode),1,fp);
temp = temp->next;
};
fclose(fp);
}
void load_passenger(passengerList *PList)
{
FILE* fp = fopen("passenger.dat","rb");
if(fp==NULL)
return;
passengernode *q;
int n;
while(!feof(fp))
{
q=(passengernode *)malloc(sizeof(passengernode));
n =fread(q,sizeof(passengernode),1,fp);
if(n!=1)
break;
PList->rear->next=q;
PList->rear=q;
}
PList->rear->next=NULL;
fclose(fp);
}
void save_flight(flightnode *h)
{
FILE* fp = fopen("flightList.dat","wb");
if(fp==NULL)
return;
flightnode *temp=h->next;
while(temp!=NULL)
{
fwrite(temp,sizeof(flightnode),1,fp);
temp = temp->next;
};
fclose(fp);
}
void load_flight(flightnode *&h)
{
flightnode *pt=h;
FILE* fp = fopen("flightList.dat","rb");
if(fp==NULL)
return;
flightnode *q;
int n;
while(!feof(fp))
{
q=(flightnode *)malloc(sizeof(flightnode));
n=fread(q,sizeof(flightnode),1,fp);
if(n!=1)
break;
pt->next=q;
pt=q;
}
pt->next=NULL;
fclose(fp);
}
int find_same_flight(flightnode *h,char *flight_num)
{
flightnode *t=h->next,*p=h->next;
int mark=0;
printf("%-8s%-12s%-12s%-10s%-10s%-8s%-6s%-10s%-8s\n","航班号","起飞城市","抵达城市","起飞时间","抵达时间","价格","折扣","是否满仓","空座数");
while(t!=NULL && strcmp(t->flight_num,flight_num)!=0) t=t->next;
while(p!=NULL){
if((strcmp(t->start_place,p->start_place)==0)&&(strcmp(t->end_place,p->end_place)== 0)&&(strcmp(t->flight_num,p->flight_num)!=0))
{
printf("%-8s%-12s%-12s%-10s%-10s%-8.2f%-6.2f%-10d%-8d\n",p->flight_num, p->start_place,p->end_place,p->start_time,p->end_time,p->price,p->price_discount,p->isFull,p->left);
mark=1;
}
p=p->next;
}
if(mark==0)
{
printf("\t\t抱歉,没有可选的航班!\n");
return 0;
}
return 1;
}
void insert_passengerList(flightnode *&h,passengerList *&PList,char *name,char *ID_num,char *flight_num,int ticket_num)
//客户订票后,将客户结点插入客户链表中,并修改相应的航班信息。
{
flightnode *p=h->next;
for(;p!=NULL;p=p->next)
if(strcmp(p->flight_num,flight_num)==0)
{
p->left=p->left-ticket_num;
if(p->left==0)
p->isFull=1;
}
passengernode *q=(passengernode *)malloc(sizeof(passengernode));//新建结点,存放新的客户订单信息
strcpy(q->name,name);
strcpy(q->ID_num,ID_num);
strcpy(q->flight_num,flight_num);
q->ticket_num=ticket_num;
q->next=NULL;
//将新订单连接到链表中
PList->rear->next=q;
q->order_num=PList->rear->order_num+1;//生成订单号
PList->rear=q;
}
void delete_flight(flightnode *&h,passengerList *&PList)
//目的要按照某个航班号删除航班结点
{
flightnode *p,*pr;
passengernode *q,*qr;
char flight_num[10];
int mark=1;
qr=PList->head;//pr为顾客链表的头结点
q=qr->next;//用p作为中间指针对顾客链表中要删除的顾客结点进行查找
pr=h;//pr为航线链表的头结点
p=pr->next;//用p作为指针对航线链表中要删除的航班结点进行查找
printf("\t\t请输入你要删除的航班号:");
scanf("%s",flight_num);
while(p!=NULL)//要删除的航班存在,下面进行删除操作
{
if(strcmp(flight_num,p->flight_num)==0)
{
pr->next=p->next;//移动指针找着要删除的航班结点
free(p);//删除操作
printf("\t\t删除%s航班成功!\n",flight_num);
mark=0;
p=NULL;
}
if(pr->next!=NULL)
{
pr=pr->next;
p=pr->next;
}
}
if(mark==1)
printf("\t\t无此航班,无法删除!\n");
else
{
while(q!=NULL)//要删除的顾客存在,下面进行删除操作
{
if(strcmp(flight_num,q->flight_num)==0)
{
qr->next=q->next;//移动指针找着要删除的顾客结点
free(q);
q=NULL;
}
if(qr->next!=NULL)
{
qr=qr->next;
q=qr->next;
}
}
}
}
int delete_passenger(passengerList *&PList,flightnode *&h,char *name,char *ID_num)
//目的是按照要退票的顾客的姓名查找该顾客结点,进行删除操作
{
passengernode *p,*pr=PList->head;//pr指向顾客链表的头结点
p=pr->next;
while(p!=NULL)
{
if(strcmp(name,p->name)==0&&strcmp(ID_num,p->ID_num)==0)
{
for(flightnode *f=h->next;f!=NULL;f=f->next)
if(strcmp(p->flight_num,f->flight_num)==0)
{
f->left=f->left+p->ticket_num;
f->isFull=0;
break;
}
pr->next=p->next;
free(p);
printf("\t\t顾客%s,%s退票成功!\n",name,ID_num);
return 1;
}
pr=pr->next;
p=pr->next;
}
printf("\t\t无此顾客,无法退票!\n");
return 0;
}
void add_flighten(flightnode *&h)//录入航班信息后调用insert_flight函数增加航班
{
flightnode *p=h;
char flight_num[10],start_time[10],end_time[10],start_place[20],end_place[20];
int left,isFull,mark=1;
float price,price_discount;
ifstream infile("file.txt",ios::in);
if(!infile)
{
cerr<<"open file error!"<<endl;
system("pause");
}
while(infile)
{
infile>>flight_num;
infile>>start_place;
infile>>end_place;
infile>>start_time;
infile>>end_time;
infile>>price;
infile>>price_discount;
infile>>left;
infile>>isFull;
insert_flight(p,flight_num,start_place,end_place,start_time,end_time,left,price, price_discount,isFull);
}
infile.close();
}
int flight_num_check(flightnode *h,char *flight_num)//用航班号进行查询
{
flightnode *p=h;
printf("%-8s%-12s%-12s%-10s%-10s%-8s%-6s%-10s%-8s\n","航班号","起飞城市","抵达城市","起飞时间","抵达时间","价格","折扣","是否满仓","空座数");
for(;p!=NULL;p=p->next)
{
if(strcmp(p->flight_num,flight_num)==0)
{
printf("%-8s%-12s%-12s%-10s%-10s%-8.2f%-6.2f%-10d%-8d\n",p->flight_num, p->start_place,p->end_place,p->start_time,p->end_time,p->price,p->price_discount,p->isFull,p->left);
return 1;
}
}
printf("\t\t抱歉,没有航班号为%s的航班信息!\n",flight_num);
return 0;
}
int place_check(flightnode *h,char *start_place,char *end_place)//用起飞抵达城市进行查询
{
flightnode *p=h;
int mark=0;
printf("%-8s%-12s%-12s%-10s%-10s%-8s%-6s%-10s%-8s\n","航班号","起飞城市","抵达城市","起飞时间","抵达时间","价格","折扣","是否满仓","空座数");
for(;p!=NULL;p=p->next)
{
if(strcmp(p->start_place,start_place)==0&&strcmp(p->end_place,end_place)==0)
{
printf("%-8s%-12s%-12s%-10s%-10s%-8.2f%-6.2f%-10d%-8d\n",p->flight_num, p->start_place,p->end_place,p->start_time,p->end_time,p->price,p->price_discount,p->isFull,p->left);
mark=1;
}
}
if(mark==0)
{
printf("\t\t抱歉,没有从%s到%s的航班信息!\n",start_place,end_place);
return 0;
}
return 1;
}
void check_all_flight(flightnode *h)
{
flightnode *p=h;
int m=0;
printf("%-8s%-12s%-12s%-10s%-10s%-8s%-6s%-10s%-8s\n","航班号","起飞城市","抵达城市","起飞时间","抵达时间","价格","折扣","是否满仓","空座数");
for(;p!=NULL;p=p->next)
{
printf("%-8s%-12s%-12s%-10s%-10s%-8.2f%-6.2f%-10d%-8d\n",p->flight_num, p->start_place,p->end_place,p->start_time,p->end_time,p->price,p->price_discount,p->isFull,p->left);
m=1;
}
if(m==0)
printf("\t\t航班信息为空!\n");
}
void flight_check(flightnode *h)//选择使用哪一个函数进行查询
{
flightnode *p=h->next;
char flight_num[10],start_place[20],end_place[20];
char a;
printf("\t\t请选择航班查询方式:\n");
printf("\t\t1表示按航班号进行查询;\n");
printf("\t\t2表示按起飞抵达城市进行查询;\n");
printf("\t\t3表示浏览全部航班信息.\n\t\t请选择输入:");
cin>>a;
if(a=='1')
{
printf("\t\t请输入航班号:");
scanf("%s",flight_num);
flight_num_check(p,flight_num);
}
else if(a=='2')
{
printf("\t\t请输入起飞城市:");
scanf("%s",start_place);
printf("\t\t请输入抵达城市:");
scanf("%s",end_place);
place_check(p,start_place,end_place);
}
else if(a=='3')
check_all_flight(p);
else
return;
}
int ID_name_check(passengerList *PList,char *name,char *ID_num)
{
passengernode *p=PList->head->next;
int mark=0;
printf("%-8s%-20s%-20s%-10s%-8s%\n","订单号","姓名","证件号","航班号","订票数量");
for(;p!=NULL;p=p->next)
{
if(strcmp(p->ID_num,ID_num)==0&&strcmp(p->name,name)==0)
{
printf("%-8d%-20s%-20s%-10s%-8d%\n",p->order_num,p->name,p->ID_num, p->flight_num,p->ticket_num);
mark=1;
}
}
if(mark==0)
{
printf("\t\t抱歉,没有%s,%s的订单信息!\n",name,ID_num);
return 0;
}
return 1;
}
int order_num_check(passengerList *PList,int order_num)
{
passengernode *p=PList->head->next;
printf("%-8s%-20s%-20s%-10s%-8s%\n","订单号","姓名","证件号","航班号","订票数量");
for(;p!=NULL;p=p->next)
{
if(p->order_num==order_num)
{
printf("%-8d%-20s%-20s%-10s%-8d%\n",p->order_num,p->name,p->ID_num, p->flight_num,p->ticket_num);
return 1;
}
}
printf("\t\t抱歉,没有订单号为%d的订单信息!\n",order_num);
return 0;
}
void check_all_passenger(passengerList *PList)
{
passengernode *p=PList->head->next;
int m=0;
printf("%-8s%-20s%-20s%-10s%-8s%\n","订单号","姓名","证件号","航班号","订票数量");
for(;p!=NULL;p=p->next)
{
printf("%-8d%-20s%-20s%-10s%-8d%\n",p->order_num,p->name,p->ID_num, p->flight_num,p->ticket_num);
m=1;
}
if(m==0)
printf("\t\t订单信息为空!\n");
}
void passenger_check(passengerList *PList)
{
char name[20],ID_num[15];
int order_num;
char a;
printf("\t\t请选择订单查询方式:\n");
printf("\t\t1表示按客户姓名和证件号进行查询;\n");
printf("\t\t2表示按订单号进行查询;\n");
cin>>a;
if(a=='1')
{
printf("\t\t请输入客户姓名:");
scanf("%s",name);
printf("\t\t请输入证件号:");
scanf("%s",ID_num);
ID_name_check(PList,name,ID_num);
}
else if(a=='2')
{
printf("\t\t请输入订单号:");
scanf("%d",&order_num);
order_num_check(PList,order_num);
}
else
return;
}
void modify_flight(flightnode *&h,passengerList *&PList)
{
flightnode *p=h->next;
char flight_num[10],start_time[10],end_time[10];
char a;
printf("\t\t************航线信息修改*************\n");
printf("\t\t*************************************\n");
printf("\t\t* 增加航班-------1 *\n");
printf("\t\t* 删除航班-------2 *\n");
printf("\t\t* 修改航班时间---3 *\n");
printf("\t\t*************************************\n");
printf("\t\t请选择:");
cin>>a;
if(a=='1')
add_flight(h);
else if(a=='2')
delete_flight(h,PList);
else if(a=='3')
{
printf("\t\t请输入要修改的航班的航班号:");
scanf("%s",flight_num);
if(flight_num_check(p,flight_num)==1)
{
printf("\t\t请输入修改后的起飞时间:");
scanf("%s",start_time);
printf("\t\t请输入修改后的抵达时间:");
scanf("%s",end_time);
for(;p!=NULL;p=p->next)
if(strcmp(flight_num,p->flight_num)==0)
{
strcpy(p->start_time,start_time);
strcpy(p->end_time,end_time);
printf("\t\t航班%s时间修改成功!\n",flight_num);
}
}
}
else
return;
}
int book(flightnode *&h,passengerList *&PList)
{
char name[20]; //姓名
char ID_num[20]; //证件号
char flight_num[10]; //航班号
char start_place[20];//起飞城市
char end_place[20]; //抵达城市
int ticket_num; //订票数量
int k;
flightnode *p=h->next;
printf("\t\t请输入信息:\n");
printf("\t\t请输入起飞城市:");
scanf("%s",start_place);
printf("\t\t请输入抵达城市:");
scanf("%s",end_place);
if(place_check(h,start_place,end_place)==1)
{
printf("\t\t航班号:");
scanf("%s",flight_num);
while(flight_num==NULL){
printf("航班号不能为空!\n");
printf("\t\t航班号:");
scanf("%s",flight_num);
}
while(p!=NULL){
if(strcmp(p->flight_num,flight_num)==0)
{
printf("\t\t姓名:");
scanf("%s",name);
printf("\t\t证件号码:");
scanf("%s",ID_num);
printf("\t\t订票数量:");
scanf("%d",&ticket_num);
while(name==NULL){
printf("客户姓名不能为空!\n");
printf("\t\t姓名:");
scanf("%s",name);
}
while(ID_num==NULL){
printf("客户证件号码不能为空!\n");
printf("\t\t证件号码:");
scanf("%s",ID_num);
}
while(ticket_num==0){
printf("客户订票数量不能为空!\n");
printf("\t\t订票数量:");
scanf("%d",&ticket_num);
}
if(p->left>0&&p->left>=ticket_num)
{
insert_passengerList(h,PList,name,ID_num,flight_num,ticket_num);
printf("\t\t你应付金额¥%6.2f.\n",p->price*p->price_discount* ticket_num);
getchar();
printf("\t\t恭喜您,订票成功!\n");
return 1;
}
else
{
printf("\t\t***很遗憾,该航班已满!***\n");
printf("\t\t***如选择其他航班请输入-----1\n\t\t***不选则输入-----0***\n");
printf("\t\t输入数字进行选择:");
scanf("%d",&k);
if(k==1)
{
printf("\t\t此航线上的其他航班有:\n");
if(find_same_flight(h,flight_num)==1)
{
printf("\t\t请输入您选的航班:");
scanf("%s",flight_num);
insert_passengerList(h,PList,name,ID_num,flight_num, ticket_num);
printf("\t\t恭喜您,订票成功!\n");
return 1;
}
}
}
}
else
p=p->next;
}
if(p==NULL)
printf("\t\t对不起,您输入的航班不存在!\n");
}
return 0;
}
void cancel(passengerList *&PList,flightnode *&h)//退票
{
char name[20],ID_num[20];
printf("\t\t请输入你的姓名:");
cin>>name;
printf("\t\t请输入你的证件号:");
cin>>ID_num;
delete_passenger(PList,h,name,ID_num);
}
void Find_ALL_LIST_DATA(passengerList *&PList)//显示所有订单
{
passengernode*p=PList->head;
while(p->next!=NULL)
{
cout<<p->name<<" "<<p->ID_num<<" "<<p->flight_num<<" "<<p->order_num<<" "<<p->ticket_num<<" "<<endl;
p=p->next;
}
system("pause");
}
# include <stdio.h>
# include "header.h"
# include <string.h>
# include <windows.h>
void main()
{
char choice;
int t=1;
flightnode *flight;
passengerList *PList;
init_flight(flight);//初始化航班链表
init_passengerList(PList);
load_flight(flight);
load_passenger(PList);
while(t==1)
{
printf("\t\t************飞机订票系统菜单*************\n");
printf("\t\t*****************************************\n");
printf("\t\t* 录入信息----------1 *\n");
printf("\t\t* 订 票----------2 *\n");
printf("\t\t* 退 票----------3 *\n");
printf("\t\t* 查询航班----------4 *\n");
printf("\t\t* 查询订单----------5 *\n");
printf("\t\t* 修改航线----------6 *\n");
printf("\t\t* 查询所有----------7 *\n");
printf("\t\t* 保存退出----------0 *\n");
printf("\t\t*****************************************\n");
printf("\t\t请选择服务:");
choice=getchar();
printf("%c\n",choice);
system("cls");
if(choice=='1'){
add_flighten(flight);
system("pause");
getchar();
system("cls");
}else if(choice=='2'){
book(flight,PList);
system("pause");
getchar();
system("cls");
}else if(choice=='3'){
cancel(PList,flight);
system("pause");
getchar();
system("cls");
}else if(choice=='4'){
flight_check(flight);
system("pause");
getchar();
system("cls");
}else if(choice=='5'){
passenger_check(PList);
system("pause");
getchar();
system("cls");
}else if(choice=='6'){
modify_flight(flight,PList);
system("pause");
getchar();
system("cls");
}else if(choice=='0'){
printf("\t\t再见!\n");
t=0;
}
else if(choice=='7')
{
check_all_passenger(PList);
system("pause");
}
}
save_flight(flight);
save_passenger(PList);
}
发布者:全栈程序员-用户IM,转载请注明出处:https://javaforall.cn/148303.html原文链接:https://javaforall.cn
【正版授权,激活自己账号】: Jetbrains全家桶Ide使用,1年售后保障,每天仅需1毛
【官方授权 正版激活】: 官方授权 正版激活 支持Jetbrains家族下所有IDE 使用个人JB账号...