航空管理系统的C语言描述

合集下载
  1. 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
  2. 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
  3. 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。

#include"stdio.h"
#include"stdlib.h"
#include"string.h"
typedef struct inf
{
char name[20];
int v;
int n;
int Nnumbre;
int Vnumber;
struct inf * next;
}Node;

typedef struct SN
{ char linenum[10];
Node * data;
struct SN * next;
}SN;

typedef struct queue
{ char name[20];
int v;
int n;
struct queue * next;
}Queue;

typedef struct SE
{ char linenum[10];
queue * waitter;
struct SE * next;
}SE;

typedef struct line
{ char linenum[10];
char from[20];
char end[20];
char ftime[10];
char etime[10];
int num1;
int num2;
int money1;
int money2;
struct line * next;
}Inf;

void menu()
{ printf("\n\n\t\t***************欢迎进入航空订票系统***************\n\n");
printf("\t\t\t\t1:订票业务\n\n");
printf("\t\t\t\t2:退票业务\n\n");
printf("\t\t\t\t3:查询航班最新信息\n\n");
printf("\t\t\t\t4:显示\n\n");
printf("\t\t\t\t5:保存信息\n\n");
printf("\t\t\t\t0:退出 ");
}
void Creat(Inf **r,SN **h,SE **l)
{ Inf *p,*q; char n,i=1; SN *w,*m; Node *data; SE *y,*z; Queue * waitter;
(*h)=m=(SN *)malloc(sizeof(SN));
(*r)=q=(Inf *)malloc(sizeof(Inf));
(*l)=z=(SE *)malloc(sizeof(SE));
q->next=NULL;
printf("请输入今日航班信息");
getchar();
getchar();
while(1)
{ fflush(stdin);
p=(Inf *)malloc(sizeof(Inf));
printf("航班编号: ");
gets(p->linenum);
printf("始发站:");
gets(p->from);
printf("终点站:");
gets(p->end);
printf("起飞时间:");
gets(p->ftime);
printf("抵达时间:");
gets(p->etime);
printf("头等舱座位数:");
scanf("%d",&p->num1);
printf("经济舱座位数:");
scanf("%d",&p->num2);
printf("头等舱票价:");
scanf("%d",&p->money1);
printf("经济舱票价:");
scanf("%d",&p->money2);
p->next=NULL;
q->next=p;
q=p;
printf("是否继续?(Y/N)");
scanf("%c",&n);
scanf("%c",&n);
if(n=='N'||n=='n')
break;
}
for(p=(*r)->next;p;p=p->next)
{ fflush(stdin);
w=(SN *)malloc(sizeof(SN));
strcpy(w->linenum,p->linenum);
data=(Node *)malloc(sizeof(Node));
data->Vnumber=100001;
data->Nnumbre=200001;
data->n=0;
data->v=0;
data->next=NULL;
w->data=data;
w->next=NULL;
m->next=w;
m=w;
}
for(p=(*r)->next;p;p=p->next)
{ y=(SE *)malloc(sizeof(SE));
strcpy(y->linenum,p->linenum);
waitter=(Queue *)malloc(sizeof(Queue));
waitter->n=0;
waitter->v=0;
waitter->next=NULL;
y->waitter=waitter;
y->next=NULL;
z->next=y;
z=y;
}
}

void Wait(char linenum[20],Node *m,SE **l)
{ Queue *p,*q; SE *w;
for(w=(*l)->next;w&&strcmp(linenum,w->linenum)!=0;w=w->next);
if(w==NULL)
printf("程序错误!Sorry....");
else
{ for(q=w->waitter;q->next;q=q->next);
p=(Queue *)malloc(sizeof(Qu

eue));
strcpy(p->name,m->name);;
p->v=m->v;
p->n=m->n;
p->next=NULL;
q->next=p;
}
printf("请稍后等待退票!\n");
}

void print1(Inf *p)
{
printf("\t\t航班编号: %s\n",p->linenum);
printf("始发站: %s\t",p->from);
printf("\t\t\t终点站: %s\n",p->end);
printf("起飞时间: %s\t",p->ftime);
printf("\t\t\t抵达时间: %s\n",p->etime);
printf("头等舱座位数: %d\t",p->num1);
printf("\t\t经济舱座位数: %d\n",p->num2);
printf("头等舱票价: %d\t",p->money1);
printf("\t\t\t经济舱票价: %d\n",p->money2);
}

void print2(Inf *p,SN *h,SE *l)
{ SN *q; Node *t; SE *w; Queue *y;
int n,v,j,k;
n=v=j=k=0;
for(q=h->next;q&&strcmp(p->linenum,q->linenum)!=0;q=q->next);
if(q==NULL)
printf("程序错误!");
else
{
for(t=q->data->next;t;t=t->next)
{ n=n+t->n;
v=v+t->v;
}
}
if(p->num1<=v&&p->num2<=n)
{
printf("\t\t该航班票已定空!\n");
for(w=l->next;w&&strcmp(p->linenum,w->linenum)!=0;w=w->next);
if(y==NULL)
printf("程序错误!");
else
{
for(y=w->waitter->next;y;y=y->next)
{ j=j+y->n;
k=k+y->v;
}
printf("\t目前:头等舱票透支%d张\t经济舱票透支%d张\n",k,j);
}
}
else
{ if(p->num1printf("\t头等舱所剩座位数: 0\n");
else
printf("\t头等舱所剩座位数: %d\n",p->num1-v);
if(p->num2printf("\t经济舱所剩座位数: 0\n");
else
printf("\t经济舱所剩座位数: %d\n",p->num2-n);
}
}
void book(Inf *r,SN **h,SE **l)
{ Inf * p; SN *q;
Node *m,*t; int n,v;
char end[10],choice;

fflush(stdin);
printf("请输入终点站: ");
gets(end);
for(p=r->next;p&&strcmp(p->end,end)!=0;p=p->next);
if(p==NULL)
printf("无此航班!");
else
{ print1(p);
print2(p,*h,*l);
}
printf("是否订票!(Y/N)");
scanf("%c",&choice);
if(choice=='y'||choice=='Y')
{ fflush(stdin);
n=v=0;
m=(Node *)malloc(sizeof(Node));
printf("请输入姓名:");
gets(m->name);
printf("输入预定头等舱票数: ");
scanf("%d",&m->v);
printf("输入预定经济舱票数: ");
scanf("%d",&m->n);
for(q=(*h)->next;q&&strcmp(p->linenum,q->linenum)!=0;q=q->next);
if(q!=NULL)
for(t=q->data;t->next;t=t->next)
{ n=n+t->next->n;
v=v+t->next->v;
}
if(m->v>p->num1-v||m->n>p->num2-n)
{
printf("剩余座位不够,是否等票!(Y/N)");
scanf("%c",&choice);
scanf("%c",&choice);
if(choice=='Y'||choice=='y')
Wait(p->linenum,m,&(*l));
}
else
{
m->Vnumber=t->Vnumber+t->v;
m->Nnumbre=t->Nnumbre+t->n;
m->next=NULL;
t->next=m;
t=m;
}
}
printf("订票成功!");
getchar();
ge

tchar();
}

void remove(SN **h,SE **l)
{ char linenum[10],name[20],choice;
SN *w; Node *m,*t,*p; SE *y; Queue *z,*a;
int n,v;
fflush(stdin);
printf("请输入航班号:");
gets(linenum);
for(w=(*h)->next;w&&strcmp(w->linenum,linenum)!=0;w=w->next);
if(w==NULL)
printf("无此航班!");
else
{ printf("请输入姓名:");
gets(name);
for(m=w->data;m->next&&strcmp(m->next->name,name)!=0;m=m->next);
if(m->next==NULL)
printf("无此人!");
else
{
printf("姓名:%s\n",m->next->name);
if(m->next->v)
{
printf("\t\t预定头等舱票数:%d\n",m->next->v);
printf("\t\t头等舱票码:%d-----%d\n",m->next->Vnumber,m->next->Vnumber+m->next->v-1);
}
if(m->next->n)
{ printf("\t\t预定经济舱票数:%d\n",m->next->n);
printf("\t\t头等舱票码:%d-----%d\n",m->next->Nnumbre,m->next->Nnumbre+m->next->n-1);
}
}
}
printf("是否退票?(Y/N)");
scanf("%c",&choice);
if(choice=='y'||choice=='Y')
{
if(m->next->v)
{printf("您想退头等舱票张数为: ");
scanf("%d",&v);
}
if(m->next->n)
{ printf("您想退经济舱票数为: ");
scanf("%d",&n);
}

printf("是否确定退票?(Y/N)");
scanf("%c",&choice);
scanf("%c",&choice);
if(choice=='y'||choice=='Y')
{ m->next->v=m->next->v-v;
m->next->n=m->next->n-n;
if(m->next->v<=0&&m->next->n<=0)
{ p=m->next;
m->next=p->next;
free(p);
}
for(p=w->data;p->next!=NULL;p=p->next);
for(y=(*l)->next;y&&strcmp(y->linenum,linenum)!=0;y=y->next);
if(y)
{
for(z=y->waitter;z->next;)
{ if(z->next->v<=v&&z->next->n<=n)
{
printf("%d %d\n",z->next->v,z->next->n);
t=(Node *)malloc(sizeof(Node));
n=n-z->next->n;
v=v-z->next->v;
t->n=z->next->n;
t->v=z->next->v;
t->Nnumbre=p->Nnumbre+p->n;
t->Vnumber=p->Vnumber+p->v;
strcpy(t->name,z->next->name);
t->next=NULL;
p->next=t;
p=t;
a=z->next;
z->next=a->next;
free(a);
}
else
z=z->next;
if(z->next==NULL)
break;
}

}
}
}
printf("退票成功!\n");
getchar();
}

void search(Inf *r,SN *h,SE *l)
{ Inf *p; SN *w; SE *y; char linenum[10];
char choice;
while(1)
{ fflush(stdin);
printf("是否查询?(Y/N)");
scanf("%c",&choice);
if(choice=='Y'||choice=='y')
{ fflush(stdin);
printf("请输入航班编号:");
gets(linenum);
for(p=r->next;p&&strcmp(p->linenum,linenum)!=0;p=p->next);
if(p==NULL)
printf("无此航班!\n");
else
{ print1(p);
print2(p,h,l);

}
}
else
break;
}
}

void save(Inf *r,SN *h,SE *l)
{ Inf *p; SN *w; Node *m; SE *y; Queue *z;
FILE *fp1,*fp2,*fp3;
fp1=fopen("e:/飞机信息.txt","wt");
fp2=fopen("e:/订票客户信息.txt","wt");
fp3=fopen("e:/等票客户信息.txt","wt");
for(p=r->next;p;p=p->next)
{
fprintf(fp1,"\t\t航班编号: %s\n",p->linenum);
fprintf(fp1,"始发站: %s\t",p->from);
fprintf(fp1,"\t\t\t终点站: %s\n",p->end);
fprintf(fp1,"起飞时间: %s\t",p->ftime);
fprintf(fp1,"\t\t\t抵达时间: %s\n",p->etime);
fprintf(fp1,"头等舱座位数: %d\t",p->num1);
fprintf(fp1,"\t\t经济舱座位数: %d\n",p->num2);
fprintf(fp1,"头等舱票价: %d\t",p->money1);
fprintf(fp1,"\t\t\t经济舱票价: %d\n",p->money2);
}
fprintf(fp2,"订票客户名单:\n");
for(w=h->next;w;w=w->next)
{ fprintf(fp2,"\t\t\t航班号:%s\n",w->linenum);
for(m=w->data->next;m;m=m->next)
{
fprintf(fp2,"\t姓名:%s\n",m->name);
if(m->v!=0)
{
fprintf(fp2,"\t\t预定头等舱票数:%d\n",m->v);
fprintf(fp2,"\t\t头等舱票码:%d-----%d\n",m->Vnumber,m->Vnumber+m->v-1);
}
if(m->n!=0)
{ fprintf(fp2,"\t\t预定经济舱票数:%d\n",m->n);
fprintf(fp2,"\t\t经济舱票码:%d-----%d\n",m->Nnumbre,m->Nnumbre+m->n-1);
}
}
}

fprintf(fp3,"等票客户名单:\n");
for(y=l->next;y;y=y->next)
{ fprintf(fp3,"\t\t\t航班号:%s\n",y->linenum);
for(z=y->waitter->next;z;z=z->next)
{ fprintf(fp3,"\t姓名:%s\n",z->name);
if(z->v!=0)
fprintf(fp3,"\t\t预定头等舱票数:%d\n",z->v);
if(z->n!=0)
fprintf(fp3,"\t\t预定经济舱票数:%d\n",z->n);
}
}
fclose(fp1);
fclose(fp2);
fclose(fp3);
printf("保存成功!\n");
getchar();
getchar();
}

void print(Inf *r,SN *h,SE *l)
{ Inf *p; SN *q; SE *y; int choice;
Node *w; Queue *z;
while(1)
{ system("cls");
printf("1:显示所有航班信息\n2:显示航班客户信息\n3:显示各航班等票客户信息\n4:退出 ");
scanf("%d",&choice);
if(choice==1)
for(p=r->next;p;p=p->next)
print1(p);
else if(choice==2)
for(q=h->next;q;q=q->next)
{ printf("\t\t\t航班号:%s\n",q->linenum);
for(w=q->data->next;w;w=w->next)
{
printf("姓名:%s\n",w->name);
if(w->v!=0)
{
printf("\t\t预定头等舱票数:%d\n",w->v);
printf("\t\t头等舱票码:%d-----%d\n",w->Vnumber,w->Vnumber+w->v-1);
}
if(w->n!=0)
{ printf("\t\t预定经济舱票数:%d\n",w->n);
printf("\t\t经济舱票码:%d-----%d\n",w->Nnumbre,w->Nnumbre+w->n-1);
}
}
}
else if(choice==3)
{ printf("等票客户名单:\n");
for(y=l->next;y;y=y->next)
{ printf("\t\t\t航班号:%s\n",y->linenum);
for(z=y->waitter->n

ext;z;z=z->next)
{ printf("姓名:%s\n",z->name);
if(z->v!=0)
printf("\t\t预定头等舱票数:%d\n",z->v);
if(z->n!=0)
printf("\t\t预定经济舱票数:%d\n",z->n);
}
}
}
else if(choice==4)
break;
else
printf("指令错误!");
getchar();
getchar();
}
}

void main()
{ Inf *r; SN * h; SE *l;
int choice=1; char w;
printf("Creat new?(Y/N)");
scanf("%c",&w);
if(w=='y'||w=='Y')
Creat(&r,&h,&l);
while(choice)
{ system("cls");
menu();
scanf("%d",&choice);
switch(choice)
{
case 1:book(r,&h,&l);break; //订票
case 2:remove(&h,&l);break; //退票
case 3:search(r,h,l);break; //查询
case 4:print(r,h,l);break; //显示
case 5:save(r,h,l);break; //保存
}
}
}

相关文档
最新文档