航班信息

更新时间:2025-12-15 07:24:51 阅读: 评论:0


2023年5月22日发(作者:defective)需要分析:

A.车寻航线:

1.根据旅客提出的起点站,终点站名输出下列信息:航班号,票价,折扣,最多载客量,是否满载,起飞时间,降落时间和飞行时间;

2.根据订票乘客的姓名可以查询所订航班的航班号,座位号,飞行日期等信息;

3.根据航班号查询航班的起点站,中转站,终点站名,票价,折扣,最多载客量,是否满载,起飞时间,降落时间和飞行时间;

B.承办客户提出的要求(航班号、订票数额)查询该航班票额情况,若有余票,则为客户办理订票手续,输出座位号,需付款项信息;若已满员或余票额少于盯票额,则需重新询问客户要求。若需要,可登记排队候补;

C.根据客户提供的情况(日期、航班),为客户办理退票手续。(然后查询该航班是否有人排队候补,首先询问排第一的客户,若所退票额所能满足他的要求,则为他办理订票手续,否则依次询问其他排队候补客户);

E.内部人员对航班情况的控制:

可以录入航班信息,删除航班信息,修改航班信息,查看基本航班信息。



概要设计:

因为每个客户名单或查询名单都包括多个数据域,这样就需要有一个能存储多个数据域的数据类型来存储,因此采用单链表类型。由于航线的信息是固定的,可选用结构体数组,又因为订票与预约人数无法预计,可选用链表存储信息。

线性表的单链表存储结构:typedef struct Lode{

ElemType;

Struct Lnode*next;}Lode,*LinkList;

a.抽象数据类型顺序表的定义如下:

ADT SqList{

数据对象:D={ai|ai∈数据类型,i=1,,n}

数据关系:R1={|ai-1,ai∈D,i=1,,n}

基本操作:

InitList_Sq(&L)

操作结果:创建空的顺序表。

CreatList_Sq(&L)

操作结果:建立顺序表。

}ADT SqList



b.抽象数据类型单链表的定义如下:

ADT LinkList{

数据对象:D={ai|ai∈结构类型,i=1,,n,n>0}

数据关系:R1={|ai-1,ai∈D,i=1,,n}

基本操作:

InitList_L(&L)

操作结果:创建空的顺序表。

}ADT LinkList

在main()里调用各个函数

2.主程序

void main(){

初始化;

do{

接受命令;

处理命令;

}while(“命令”!=“退出”);

}

3.程序的模块调用:



三.详细设计:

1.所有数据类型:

struct plan /*航班数据*/

{

char num[5];/*航班号码*/

char city[10];/*到达城市*/

char up[8];/*航班起飞时间*/

char down[8];/*航班到达时间*/

int pric ;/*航班价格*/

int rshu ;/*人数*/

int zheg[4];/*价格折扣*/

}

;

struct man/*定票人数据*/

{

char num[10];/*身份证号码*/

char nam[10];/*姓名*/

int demand ;/*定票

数量*/

}

;

typedef struct node/*航班数据结点*/

{

struct plan data ;

struct node*next ;

}

ode,*Link ;

typedef struct people/*乘客数据结点*/

{

struct man data ;

struct people*next ;

}

peo,*LI ;



2.程序所用函数:

void print()/*界面输出*/

{

printf("============================System of book ticket===============================
");

printf("
");

printf("t***********************************************************
");

printf("t*t1---Bookticket t2---Dishonorbill *
");

printf("t*t3---Adding flightt4---Adding flight *
");

printf("t*t5---Modify t6---Advice *
");

printf("t*t7---Save t8---exit *
");

printf("t##########################################################
");

}

添加航班模块

void add(Link l)/*添加航班数据*/

{

ode*p,*r,*s ;

char num[10];

r=l ;

s=l->next ;

while(r->next!=ULL)

r=r->next ;

while(1)

{

printf("please input the number of the plan(0-return)");/*输入0就返回*/

scanf("%s",num);

if(strcmp(num,"0")==0)

break ;

while(s)

{

if(strcmp(s->,num)==0)

{

printf("=====tip:the number'%s'has been born!
",num);



return ;

}

s=s->next ;

}

p=(ode*)malloc(sizeof(ode));/*航班数据输入*/

strcpy(p->,num);

printf("Input the city where the plan will reach:");/*飞机到达地城市*/

scanf("%s",p->);

getchar();

printf("Input the time which the plan take off:");/*起飞时间*/

scanf("%s",p->);

getchar();

printf("Input the time which the plan reach:");/*降落时间*/

scanf("%s",&p->);

getchar();

printf("Input the price of ticket:$");/*机票价格*/

scanf("%d",&p->);

getchar();

printf("Input the number of people who have booked ticket:");/*定票数量*/

scanf("%d",&p->);

getchar();

printf("Input the agio of the ticket:");

scanf("%s",&p->);

getchar();

p->next=ULL ;

r->next=p ;

r=p ;

shoudsave=1 ;

}

}

输出模块

void pri(ode*p)/*输出函数*/

{

printf("
tttThe following is the record you want:
");

printf("
number of plan: %s",p->);

printf("
city the plan will reach: %s",p->);

printf("
the time the plan take off: %s
the time the plan reach: %s",p->,p->);

printf("
the price of the ticket: %d",p->);

printf("
the number of people who have booked ticket: %d",p->);

printf("
the agio of the ticket:%s",p->);



}

退出函数模块

ode*Locate1(Link l,char findmess[]

,char numorcity[])

{

ode*r ;

if(strcmp(numorcity,"num")==0)

{

r=l->next ;

while(r)

{

if(strcmp(r->,findmess)==0)

return r ;

r=r->next ;

}

}

else if(strcmp(numorcity,"city")==0)

{

r=l->next ;

while(r)

{

if(strcmp(r->,findmess)==0)

return r ;

r=r->next ;

}

}

return 0 ;

}



航班信息模块

void qur(Link l)/*航班信息查询*/



{

ode*p ;

int sel ;

char str1[5],str2[10];



if(!l->next)

{

printf("TIP:there are not any record to be inquired for you!");

return ;

}

printf("Choose the way:(1->according to the number of plan;2->according to the city):");/*选择航班号查询和终点城市查询*/

scanf("%d",&sel);

if(sel==1)

{

printf("Input the the number of plan:");

scanf("%s",str1);

p=Locate1(l,str1,"num");

if(p)

{

printf("the following is what you want:
");

pri(p);

}

else

{

mark1=1 ;

printf("
the file can't be found!");

}

}

else if(sel==2)

{

printf("Input the city:");

scanf("%s",str2);

p=Locate1(l,str2,"city");

if(p)

{

printf("the following is what you want:
");

pri(p);

}

else

{

mark1=1 ;

printf("
the file can't be found!");

}

}

}



定票模块

void buy(Link l,LI k)/*定票函数*/

{

ode*r[10],*p ;

int ch,dem ;

peo*v,*h ;

int i=0,t=0 ;

char str[10],str1[10],str2[10];

v=k ;

while(v->next!=ULL)

v=v->next ;

printf("Input the city you want to go: ");/*航班终点站城市*/

scanf("%s",&str);

p=l->next ;

while(p!=ULL)

{

if(strcmp(p->,str)==0)

{

r[i]=p ;

i++;

}

p=p->next ;

}

printf("

the number of record have %d
",i);

for(t=0;t
pri(r[t]);

if(i==0)

printf("
tSorry!Can't find the plan for you!
");

else

{

printf("
do you want to book it?<1/0>
");

printf("please choose: ");

scanf("%d",&ch);

if(ch==1)

{

h=(peo*)malloc(sizeof(peo));/*重新分配空间*/

printf("Input your name: ");

scanf("%s",&str1);

strcpy(h->,str1);

printf("Input your id: ");

scanf("%s",&str2);

strcpy(h->,str2);

printf("Input your demand: ");

scanf("%d",&dem);

h->=dem ;

h->next=ULL ;

v->next=h ;

v=h ;

printf("
tLucky!Success in booking ticket!");

getch();



shoudsave=1 ;

}

}

}

peo*Locate2(LI k,char findmess[])

{

peo*r ;

r=k->next ;

while(r)

{

if(strcmp(r->,findmess)==0)

{

mark=1 ;

return r ;

}

r=r->next ;

}

return 0 ;

}

退票模块

void tui(LI k)/*退票函数*/

{

char str[10];

peo*p,*r ;

int ch2=0 ;

printf("Input your id: ");/*输入身份证号*/

scanf("%s",&str);

p=Locate2(k,str);

if(mark!=1)

printf("can't find the people!");

else if(mark==1)

{

mark=0 ;

printf("tttthe following is the record you want:
");

printf("your id:%s
",p->);

printf("name:%s
",p->);

printf("your denmand:%d",p->);

printf("
do you want to refund the ticket?<1/0>");

scanf("%d",&ch2);

if(ch2==1)

{

if(p)

{

r=k ;

while(r->next!=p)

r=r->next ;

r->next=p->next ;

free(p);

}

count2--;

printf("
you have sucessed in refunding ticket!");

shoudsave=1 ;

}

}

}



void Modify(Link l)/*修改航班信息*/

{

ode*p ;

char findmess[20],ch ;

if(!l->next)

{

printf("
=====tip:there isn't record for you to modify!
");

return ;

}

else

{

qur(l);

if(mark1==0)

{

printf("
Do you want to modify it?
");

getchar();

scanf("%c",&ch);

if(ch=='y');

{

printf("
Input the number of the plan:");

scanf("%s",findmess);

p=Locate1(l,findmess,"num");

if(p)

{

printf("Input another number of plan:");

scanf("%s",&p->);

getchar();

printf("Input another city the plan will reach:");

scanf("%s",&p->);

getchar();

printf("Input another time the plan take off");

scanf("%s",&p->);

printf("Input another time the plan reach:");

scanf("%s",&p->);

printf("Input another price of the ticket::");

scanf("%d",&p->);

printf("Input another number of people who have booked ticket:");

scanf("%d",&p->);

printf("Input another agio of the ticket:");

scanf("%s",&p->);

printf("
=====>tip:modifying record is sucessful!
");

shoudsave=1 ;

}

else

printf("tcan't find the flight!");

}

}



else

mark1=0 ;

}

}



void advice(Link l)/*终点站航班查询*/

{

ode*r ;

char str[10];

int mar=0 ;

r=l->next ;

printf("Iuput the city you want to go: ");/*输入终点站城市*/

scanf("%s",str);

while(r)

{

if(strcmp(r->,str)==0&&r-><200)

{

mar=1 ;

printf("
you can select the following plan!
");

printf("

please select the fourth operation to book the ticket!
");

pri(r);

}

r=r->next ;

}

if(mar==0)

printf("
tttyou can't book any ticket now!
");



}



void save1(Link l)/*保存数据*/

{

FILE*fp ;

ode*p ;

int count=0,flag=1 ;

fp=fopen("g:data1","wb");

if(fp==ULL)

{

printf("the file can't be opened!");

return ;

}

p=l->next ;

while(p)

{

if(fwrite(p,sizeof(ode),1,fp)==1)

{

p=p->next ;

count++;

}

else

{

flag=0 ;

break ;

}

}

if(flag)

{

printf("the number of the record which have been saved is %d
",count);

shoudsave=0 ;

}

fclose(fp);

}



void save2(LI k) /*保存数据*/

{

FILE*fp ;

peo*p ;

int count=0,flag=1 ;

fp=fopen("g:data2","wb");/*文件连接*/

if(fp==ULL)

{

printf("the file can't be opened!");

return ;

}

p=k->next ;

while(p)

{

if(fwrite(p,sizeof(peo),1,fp)==1)

{

p=p->next ;

count++;

}

else

{

flag=0 ;

break ;

}

}

if(flag)

{

printf("the number of the record which have been saved is %d
",count);

shoudsave=0 ;

}

fclose(fp);

}





四.主函数模块:





main()

{

FILE*fp1,*fp2 ;

ode*p,*r ;

char ch1,ch2 ;

Link l ;

LI k ;

peo*t,*h ;

int sel ;

l=(ode*)malloc(sizeof(ode));

l->next=ULL ;

r=l ;

k=(peo*)malloc(sizeof(peo));

k->next=ULL ;

h=k ;

fp1=fopen("g:data1","ab+");

if((fp1==ULL))

{

printf("can't open the file!");

return 0 ;

}



while(!feof(fp1))

{

p=(ode*)malloc(sizeof(ode));



if(fread(p,sizeof(ode),1,fp1)==1)

{

p->next=ULL ;

r->next=p ;

r=p ;



count1++;

}

}

fclose(fp1);

fp2=fopen("g:data2","ab+");

if((fp2==ULL))

{

printf("can't open the file!");

return 0 ;

}



while(!feof(fp2))

{

t=(peo*)malloc(sizeof(peo));



if(fread(t,sizeof(peo),1,fp2)==1)

{

t->next=ULL ;

h->next=t ;

h=t ;



count2++;

}



}

fclose(fp2);

while(1)

{



getch();

clrscr();



print();

printf("please choose the operation(1-8): ");

scanf("%d",&sel);

if(sel==8)

{

if(shoudsave==1)

{

getchar();

printf("
=====tip:the file have been changed!do you want to save it(y/n)?
");

scanf("%c",&ch1);

if(ch1=='y'||ch1=='Y')

{

save2(k);

save1(l);

}

}

printf("
tyou have exited! Happy serve for you");

break ;



}

switch(sel)

{

case 1 :

buy(l,k);

break ;



case 2 :

tui(k);

break ;



case 3 :

qur(l);

break ;



case 4 :

add(l);

break ;



case 5 :

Modify(l);

break ;



case 6 :

advice(l);

break ;



case 7 :

{

save1(l);

save2(k);

break ;

}



case 8 :

exit(0);

}



}

getch();

}


本文发布于:2023-05-22 10:01:46,感谢您对本站的认可!

本文链接:https://www.wtabcd.cn/falv/fa/82/93593.html

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。

相关文章
留言与评论(共有 0 条评论)
   
验证码:
推荐文章
排行榜
Copyright ©2019-2022 Comsenz Inc.Powered by © 站长QQ:55-9-10-26