当前位置:首页>旅游>正文

编写C语言:飞机订票系统

2023-04-01 08:25:11 互联网 未知 旅游

编写C语言:飞机订票系统

编写C语言:飞机订票系统

#include
#include
#include
//#include
#define MAXSIZE 3
typedef struct wat_ros
{
char name[10]
int req_amt
struct wat_ros *next
}qnode,*qptr
typedef struct pqueue
{
qptr front
qptr rear
}linkqueue
typedef struct ord_ros
{
char name[10]
int ord_amt
int grade
struct ord_ros *next
}linklist
struct airline
{
char ter_name[10] /* 站点名 */
char air_num[10] /* 航班号 */
char plane_num[10] /* 飞机号 */
char date[7] /* 飞行日期 */
int tkt_amt /* 乘员定额 */
int tkt_sur /* 余票量 */
linklist *order
linkqueue wait
}lineinfo
struct airline *start
struct airline air[MAXSIZE]={
{"beijing", "1", "B8571", "SUN", 3, 1},
{"shanghai","2","S1002","MON",2,5},
{"london","3","L1003","FRI",1,3}
}
void display(struct airline *info)
{
printf("%8s %3s %s %4s \%d \%d ",info->ter_name,info->air_num,info->plane_num,info->date,info->tkt_amt,info->tkt_sur)
}
/* 浏览航线信息函数 */
void list()
{
struct airline *info
int i = 0
info = start
printf("终点站名 航班号 飞机号 飞行日期" "乘员定额" "余票量 ")
while(i < MAXSIZE){
display(info)
info++
i++
}
printf(" ")
}
void search()
{
struct airline *info,*find()
char name[10]
int i=0
info=start
printf("请输入终点站名:")
scanf("%s",name)
while(i{
if(!strcmp(name,info->ter_name)) break
info++
i++
}
if(i>=MAXSIZE)
printf("对不起,该航线未找到! ")
else
{
printf("终点站名 航班号 飞机号 飞行日期 乘员定额 余票量 ")
display(info)
}
}
struct airline *find()
{
struct airline *info
char number[10]
int i=0
info=start
printf("请输入航班号:")
scanf("%s",number)
while(i {
if(!strcmp(number,info->air_num)) return info
info++
i++
}
printf("对不起,该航线末找到! ")
return NULL
}
/* 浏览已订票客户信息 */
void prtlink()
{
linklist *p
struct airline *info
info=find()
p=info->order
if(p!=NULL){
printf("客户姓名 订票数额 舱位等级 ")
while(p){
printf("%s %d %d ",p->name,p->ord_amt,p->grade)
p=p->next
}
}
else
printf("该航线没有客户信息!! ")
}
linklist *insertlink(linklist *head,int amount,char name[],int grade)
{ linklist *p1,*new1
p1=head
new1=(linklist *)malloc(sizeof(linklist))
if(!new1) {printf(" Out of memory!! ")return NULL}
strcpy(new1->name,name)
new1->ord_amt=amount
new1->grade=grade
new1->next=NULL
if(head==NULL)
{head=new1new1->next=NULL}
else
head=new1
new1->next=p1
return head
}
linkqueue appendqueue(linkqueue q,char name[],int amount)
{ qptr new1
new1=(qptr)malloc(sizeof(qnode))
strcpy(new1->name,name)
new1->req_amt=amount
new1->next=NULL
if(q.front==NULL)
q.front=new1
else
q.rear->next=new1
q.rear=new1
return q
}
void order()
{ struct airline *info
int amount,grade
char name[10]
info=start
if(!(info=find())) return
printf("请输入你订票所需要的数量:")
scanf("%d",&amount)
if(amount>info->tkt_amt)
{ printf(" 对不起,您输入的票的数量已经超过乘员定额!")
return
}
if(amount<=info->tkt_sur)
{
int i
printf("请输入您的姓名(订票客户):")
scanf("%s",name)
printf("请输入%s票的舱位等级:",name)
scanf("%d",&grade)
info->order=insertlink(info->order,amount,name,grade)
for(i=0iprintf("%s的座位号是:%d ",name,info->tkt_amt-info->tkt_sur+i+1)
info->tkt_sur-=amount
printf(" 祝您乘坐愉快! ")
}
else
{ char r
printf(" 已经没有更多的票,您需要排队等候吗?(Y/N)")
//r=getch()
//printf("%c",r)
scanf ( "回车继续等待%c", &r )
if(r==Y||r==y)
{ printf(" 请输入您的姓名(排队订票客户):")
scanf("%s",name)
info->wait=appendqueue(info->wait,name,amount)
printf(" 注册成功! ")
}
else printf(" 欢迎您下次再次订购! ")
}
}
void return_tkt()
{ struct airline *info
qnode *t,*back,*f,*r
int grade
linklist *p1,*p2,*head
char cusname[10]
if(!(info=find())) return
head=info->order
p1=head
printf("请输入你的姓名(退票客户):")
scanf("%s",cusname)
while(p1!=NULL) {
if(!strcmp(cusname,p1->name)) break
p2=p1p1=p1->next
}
if(p1==NULL){ printf("对不起,你没有订过票! ")return}
else
{
if(p1==head) head=p1->next
else p2->next=p1->next
info->tkt_sur+=p1->ord_amt
grade=p1->grade
printf("%s成功退票! ",p1->name)
free(p1)
}
info->order=head
f=(info->wait).front
r=(info->wait).rear
t=f
while(t)
{
if((info->tkt_sur = info->wait.front->req_amt))
{
int i
info->wait.front=t->next
printf("%s订票成功! ",t->name)
for(i=0ireq_amti++)
printf("%s的座位号是:%d ",t->name,(info->tkt_sur)-i)
info->tkt_sur-=t->req_amt
info->order=insertlink(info->order,t->req_amt,t->name,grade)
free(t)
break
}
back=tt=t->next
if((info->tkt_sur)>=(t->req_amt)&&t!=NULL)
{ int i
back->next=t->next
printf("%s订票成功! ",t->name)
for(i=0ireq_amti++)
printf("<%s>s seat number is:%d ",t->name,(info->tkt_sur)-i)
info->tkt_sur-=t->req_amt
info->order=insertlink(info->order,t->req_amt,t->name,grade)
free(t)break
}
if(f==r) break
}
}
void sort_tkt()
{
int j
struct airline t,*info,*p,*q
p=info=air
for(p=info(p+1)->tkt_surp++)
for(q=p+1q->tkt_surq++)
{
if(p->tkt_surtkt_sur)
{
t=*p
*p=*q
*q=t
}
}
printf("终点站名 航班号 飞机号 飞行日期 乘员定额 余票量 ")
for(j=0j{
display(info)
info++
}
}
int menu_select()
{
int c
char s[20]
printf(" 航空客运订票系统(by zjhxmjl) ")
printf(" ****************************************** ")
printf(" ** 1.浏览航线信息 ** ")
printf(" ** 2.浏览已订票客户信息 ** ")
printf(" ** 3.查询航线 ** ")
printf(" ** 4.办理订票业务 ** ")
printf(" ** 5.办理退票业务 ** ")
printf(" ** 6.查看剩余票数并排序 ** ")
printf(" ** 0.退出系统 ** ")
printf(" ******************************************* ")
do
{
printf("请选择:")
scanf("%s",s)
c = atoi(s) /* atoi将字符串转换为整型 */
}while(c < 0||c > 7)
return c
}
int main()
{
start = air
for()
{
switch(menu_select())
{
case 1:list()break
case 2:prtlink()break
case 3:search()break
case 4:order()break
case 5:return_tkt()break
case 6:sort_tkt()break
case 0:printf(" 欢迎使用本系统,再见! ")exit(0)
}
printf(" Press any key to continue! ")
getchar()
}
return 0
}

随便看看