飞机订票系统
#include<stdio.h>#include<stdlib.h>
#include<string.h>
#include<conio.h>
#define OK 1
#define ERROR 0
typedef struct airline{
char air_num;
char plane_num;
char end_place;
inttotal;
intleft;
struct airline *next;
}airline;
typedef struct customer{
char name;
char air_num;
intseat_num;
struct customer *next;
}customer;
airline *start_air()
{
airline *a;
a=(airline*)malloc(sizeof(airline));
if(a==NULL)
a->next=NULL;
return a;
}
customer *start_cus()
{
customer *c;
c=(customer*)malloc(sizeof(customer));
if(c==NULL)
c->next=NULL;
return c;
}
airline *modefy_airline(airline *l,char *air_num)
{
airline *p;
p=l->next;
for(;p!=NULL;p=p->next)
{
if(strcmp(air_num,p->air_num)==0)
{
p->left++;
return l;
}
printf("NO the airline!");
return 0;
}
}
int insert_air(airline **p,char *air_num,char *plane_num,char *end_place,int total,int left)
{
airline *q;
q=(airline*)malloc(sizeof(airline));
strcpy(q->air_num,air_num);
strcpy(q->plane_num,plane_num);
strcpy(q->end_place,end_place);
q->total=total;
q->left=left;
q->next=NULL;
(*p)->next=q;
(*p)=(*p)->next;
return OK;
}
intinsert_cus(customer **p,char *name,char *air_num,int seat_num)
{
customer *q;
q=(customer*)malloc(sizeof(customer));
strcpy(q->name,name);
strcpy(q->air_num,air_num);
q->seat_num=seat_num;
q->next=NULL;
(*p)->next=q;
(*p)=(*p)->next;
return OK;
}
int book(airline *a,char *air_num,customer *c,char *name)
{
airline *p=a;
customer *q=c->next;
p=a->next;
for(;q->next!=NULL;q=q->next){}
for(;p->next!=NULL;p=p->next)
{
if(p->left>0)
{
printf("Your seat number is %d",(p->total-p->left+1));
insert_cus(&q,name,air_num,p->total-p->left+1);
p->left--;
return OK;
}
else
{
printf("seat is full");
return 0;
}
}
return OK;
}
int del_cus(customer *c,airline *l,char *name)
{
customer *p,*pr;
char air_num;
pr=c;
p=pr->next;
while(p!=NULL)
{
if(strcmp(p->name,name)==0)
{
strcpy(air_num,p->air_num);
l=modefy_airline(l,air_num);
pr->next=p->next;
p=pr->next;
printf("finish!");
return OK;
}
pr=pr->next;
p=pr->next;
}
printf("NO the customer!");
return ERROR;
}
int search_air(airline *head)
{
airline *p=head->next;
printf("air_numplane_numend_placetotalleft\n");
for(;p!=NULL;p=p->next)
{
printf("%s %-10s %-8s %-8d%-8d\n",p->air_num,p->plane_num,p->end_place,p->total,p->left);
}
return OK;
}
int search_cus(customer *head)
{
struct customer *q=head->next;
printf("name air_num seat_num\n");
for(;q!=NULL;q=q->next)
{
printf("%-8s%-12s%-d\n",q->name,q->air_num,q->seat_num);
}
return OK;
}
int creat_air(airline **l)
{
airline *p=*l;
int i=0;
char *air_num={"007af","008af","009af"};
char *plane_num={"plane1","plane2","plane3"};
char *end_place={"Beijing","Shanghai","Tianjin"};
int total={100,100,100};
int left={52,54,76};
for(i=0;i<3;i++)
insert_air(&p,air_num,plane_num,end_place,total,left);
return OK;
}
int creat_cus(customer **l)
{
customer *p=*l;
int i=0;
char *name={"zhsan","lisi","wangwu"};
char *air_num={"007af","008af","009af"};
int seat_num={2,5,7};
for(i=0;i<3;i++)
insert_cus(&p,name,air_num,seat_num);
return OK;
}
void main()
{
int t=1;
customer *cus=start_cus();
airline*air=start_air();
char name,air_num,ch;
creat_air(&air);
creat_cus(&cus);
while(t==1)
{
printf("\n");
printf("*********************************\n");
printf("* Welcome to air firm! *\n");
printf("* book--------1 *\n");
printf("* cancel------2 *\n");
printf("* search------3 *\n");
printf("* exit--------4 *\n");
printf("*********************************\n");
ch=getch();
if(ch=='1')
{
printf("Please input a airline number:");
scanf("%s",air_num);
printf("Please input a name:");
scanf("%s",name);
book(air,air_num,cus,name);
}
else
if(ch=='2')
{
printf("Please input the cancel name:");
scanf("%s",name);
del_cus(cus,air,name);
}
else
if(ch=='3')
{
search_air(air);
printf("\n");
search_cus(cus);
}
else
if(ch=='4')
{
t=0;
}
}
}
/*任务:通过此系统可以实现如下功能:
录入:可以录入航班情况(数据可以存储在一个数据文件中,数据结构、具体数据自定)
查询:可以查询某个航线的情况(如,输入航班号,查询起降时间,起飞抵达城市,航班票价,票价折扣,确定航班是否满仓);
可以输入起飞抵达城市,查询飞机航班情况;
订票:(订票情况可以存在一个数据文件中,结构自己设定)
可以订票,如果该航班已经无票,可以提供相关可选择航班;
退票:可退票,退票后修改相关数据文件;
客户资料有姓名,证件号,订票数量及航班情况,订单要有编号。
修改航班信息:当航班信息改变可以修改航班数据文件
要求:
根据以上功能说明,设计航班信息,订票信息的存储结构,设计程序完成功能;*/
页:
[1]