数据结构课程设计-航班查询与检索(含代码、流程图、输出结果).docx
算法与数据结构实验报告 航班查询与检索 题目:航班查询与检索指导老师:组长: 成员: 一:航班信息的查询与检索初始化信息进行排序主菜单显示输入查询序号判断序号是否合法按航班号查询按时间查询按地点查询按票价查询输出航班信息结束开始按时间查询:输入查询时间Time=1按抵达时间查询按起飞时间查询返回查询信息开始是否开始输入票价范围判断有无符合条件票价票价输出相应信息返回查询信息按票价范围查询按站点查询:开始返回查询信息输入起点终点及ADAD=1?按目的站查询按起点站查询否是二分法查询:输入航班号开始输入航班号对应序列号High=mid+1Low<=highhNum=Fmid.flight_numberMid=(high+low)/2Num<Fmidfligt_numberLow=mid+1返回是否 二:算法分析:程序主要采用结构体 链表 顺序表 队列主要算法:/*航班信息的查询与检索*/三:/*航班信息的查询与检索*/#include<iostream.h>#include<string.h>#include<stdio.h>#define N 6 /航班数/航班信息typedef struct flight char flight_number10; /航班号 char start_address10; /起飞站 char arrived_address10; /终点站 char work_date10; /班期 char start_time6; /起飞时间 char arrived_time6; /到达时间 char FlightType4; /机型 int fare; /票价 DataType;struct flight FlightN;/-按航班号进行基数排序-typedef char KeyType;#define D 7 / D为排序码的最大位数 #define R 'a' / R为基数,这里为小于字母'a'代表的整型值 struct Node; /单链表结点类型 typedef struct Node RadixNode;struct Node KeyType keyD; /关键字 DataType info; /数据信息 RadixNode *next;typedef RadixNode * RadixList;typedef struct QueueNode RadixNode *f; /对列的头指针 RadixNode *e; /对列的尾指针 Queue;Queue queueR;/用队列表示桶void radixSort(RadixList * plist, int d, int r) int i,j,k; RadixNode *p, *head; head=(*plist)->next; for(j=d-1; j>=0; j-) /进行d次分配和收集 p=head; for(i=0; i<r; i+) queuei.f=NULL; queuei.e=NULL; /清队列 while(p!=NULL) k=p->keyj; /按排序码的第j个分量进行分配 if(queuek.f=NULL) queuek.f=p; / 若第k个堆为空,则当前记录为队头 else (queuek.e)->next=p; / 否则当前记录链接到第k队的队尾 queuek.e=p; p=p->next; i=0; while(queuei.f=NULL) i+; / 从r个队列中找出第一个非空的队列 p=queuei.e; head=queuei.f; /head为收集链表的头指针 for(i+; i<r; i+) if(queuei.f!=NULL) p->next=queuei.f; p=queuei.e; / 收集非空队列 p->next=NULL; (*plist)->next=head;/初始化航班信息struct Node elementN+1= " "," "," "," "," "," "," "," ",0,NULL,/表头 "CA1544","CA1544","合肥","北京","1245 ","10:55","12:40","733",960,NULL, "MU5341","MU5341","上海","广州","每日 ","14:20","16:15","M90",1280,NULL, "CZ3869","CZ3869","重庆","深圳","246 ","08:55","10:35","733",1010,NULL, "MU3682","MU3682","桂林","南京","23467","20:50","22:15","M90",1380,NULL, "HU1836","HU1836","上海","北京","每日 ","09:40","11:20","738",1250,NULL, "CZ3528","CZ3528","成都","厦门","13457","15:10","16:50","CRJ",1060,NULL,; /-信 息 显 示-/按表的格式输出某个航班信息/显示头部信息void Cout_info1() cout<<" *n"<<endl;cout<<" * 欢 迎 您 使 用 *n"<<endl; cout<<" * 航 班 信 息 表 *n"<<endl; cout<<" *n"<<endl; cout<<" 航班号 起飞时间 到达时间 起飞站 终点站 班期 机型 票价n"<<endl; /显示主体信息void Cout_info2_1(Node p)/方式一 cout<<" "<<p->info.flight_number; cout<<" "<<p->info.start_time; cout<<" "<<p->info.arrived_time; cout<<" "<<p->info.start_address; cout<<" "<<p->info.arrived_address; cout<<" "<<p->info.work_date; cout<<" "<<p->info.FlightType; cout<<" "<<p->info.fare<<"元"<<endl;void Cout_info2_2(flight F,int i)/方式二 cout<<" "<<Fi.flight_number; cout<<" "<<Fi.start_time; cout<<" "<<Fi.arrived_time; cout<<" "<<Fi.start_address; cout<<" "<<Fi.arrived_address; cout<<" "<<Fi.work_date; cout<<" "<<Fi.FlightType; cout<<" "<<Fi.fare<<"元"<<endl;/显示所有航班信息void output_ALL_info1(Node element) /方式一 RadixList p=element; Cout_info1(); p=p->next; while(p!=NULL) Cout_info2_1(p); p=p->next; cout<<endl;void output_ALL_info2(flight F) /方式二 Cout_info1(); for(int i=0;i<N;i+) Cout_info2_2(F,i); cout<<endl;/-信 息 复 制-/将排好的序列(链表)转化成顺序表存储形式void copy(flight F,Node element) RadixList p=element; p=p->next; int i; for(i=0;i<N && p!=NULL;i+) strcpy(Fi.flight_number,p->info.flight_number); strcpy(Fi.start_time,p->info.start_time); strcpy(Fi.arrived_time,p->info.arrived_time); strcpy(Fi.start_address,p->info.start_address); strcpy(Fi.arrived_address,p->info.arrived_address); strcpy(Fi.work_date,p->info.work_date); strcpy(Fi.FlightType,p->info.FlightType); Fi.fare=p->info.fare; p=p->next; /-服 务 菜 单-void F_By_Time(flight F,int);void F_By_Address(flight F,int);void F_By_fare(flight F);void F_By_FN(flight F); /主菜单void mainmenu() char ch; int y; cout<<" 主菜单n"<<endl; cout<<" =n"<<endl; cout<<" Please choose: (input the number)(输入查询/排序命令)n"<<endl; cout<<" 0. show the mainmenu (显示主菜单)n"<<endl; cout<<" 1. Find by flight number(按航班号查询)n"<<endl; cout<<" 2. Find by start time(按起飞时间查询)n"<<endl; cout<<" 3. Find by arrived time(按到达时间查询)n"<<endl; cout<<" 4. Find by start address(按起飞地点查询)n"<<endl; cout<<" 5. Find by arrived address(按目的地点查询)n"<<endl; cout<<" 6. Find by the fare(按票价范围查询)n"<<endl; cout<<" -其他键退出"<<endl; cout<<" =n"<<endl; while(1) cout<<"请输入服务命令:" cin>>y; switch(y) case 0: mainmenu();break; case 1:F_By_FN(Flight);break; case 2:F_By_Time(Flight,1);break; case 3:F_By_Time(Flight,2);break; case 4:F_By_Address(Flight,1);break; case 5:F_By_Address(Flight,2);break; case 6:F_By_fare(Flight);break; default :cout<<" 谢谢惠顾! "<<endl;break; cout<<"是否退出?(Y/N):" cin>>ch; if(ch='Y'|ch='y') break; /-查 询 系 统-/通过航班号实现二分查找法查找void F_By_FN(flight F) int low=0,high=N,mid; char Num10; cout<<"请输入您要查询的航班号:" cin>>Num; Cout_info1();/显示头部信息 while(low<=high) mid=(low+high)/2; if(strcmp(Num,Fmid.flight_number)=0) Cout_info2_2(F,mid);break; else if(strcmp(Num,Fmid.flight_number)<0) high=mid-1; else low=mid+1; cout<<" *对不起,没有您要查找的航班号* "<<endl;/通过起飞/到达时间查询void F_By_Time(flight F,int Time) int i; char T6; cout<<"请输入您要查询的航班的起飞/抵达时间:" cin>>T; Cout_info1();/显示头部信息 for(i=0;i<N;i+) if(Time=1) /按起飞时间查询 if(strcmp(T,Fi.start_time)=0) Cout_info2_2(F,i); if(Time=2) /按抵达时间查询 if(strcmp(T,Fi.arrived_time)=0) Cout_info2_2(F,i); cout<<" *对不起,该时间没有航班* "<<endl;/通过站点查询void F_By_Address(flight F,int AD) char str10; cout<<"请输入您要查询的航班的起飞/抵达地址:" cin>>str; Cout_info1(); for(int i=0;i<N;i+) if(AD=1) /按起点站查询 if(strcmp(str,Fi.start_address)=0) Cout_info2_2(F,i); if(AD=2) /按目的站查询 if(strcmp(str,Fi.arrived_address)=0) Cout_info2_2(F,i); cout<<" *对不起,该站点不存在* "<<endl;/通过票价范围查询void F_By_fare(flight F) int T1,T2,i; cout<<"请输入您要查询的航班的最低票价(单位:元):" cin>>T1; cout<<"请输入您要查询的航班的最高票价(单位:元):" cin>>T2; Cout_info1(); for(i=0;i<N;i+) if(T1<=Fi.fare && T2>=Fi.fare) Cout_info2_2(F,i); cout<<" *对不起,没有适合您的航班,请修改您的票价范围*" <<endl;/-主 函 数-int main() RadixList p=element; for(int i=0;i<N;i+) elementi.next=&elementi+1; element10.next=NULL; radixSort(&p, D, R); /基数排序 output_ALL_info1(element); /输出排序后的有序序列(航班信息) copy(Flight,element); /另存储排序后的航班信息 mainmenu(); /给出主菜单 return 0;测试数据及测试结果:、边界值处理:四:遇到的问题及解决策略:首先是要实现所要的功能需用什么数据结构的问题,比如排序问题究竟用那一种,在组员的商量下和上网搜寻资料,采用对排序最符合,其次是在时间的查询过程中,比如输入时间16:40开始只能实现输入1640,最后通过改时间的数据类型实现了时间的输入,最后是在各个模块的组合过程中由于各个成员编程所起的名字或者其他原因,程序无法运行 ,最后在大家的努力下一起修改错误使得程序可以正常运行。还未解决的问题:插入的订票的函数无法正常运行。五:实验收获和心得:通过这次次实验我们收获了很多,对数据结构这门课有了更深的了解.让我们对链表、队列、结构体的应用更娴熟,为我们更好的了解课本内容,改进不足提供了件。在这次课程设计的过程中充分说明了团队合作的重要性,组内成员共同讨论,即充分而认真的完成自己负责的模块又对组内其他成员的工作提供建议,使得这次课程设计能够按时完成。我们一定会更加努力,争取在以后的学习中能够学以致用,最后要感谢胡老师在设计过程中给我们的指导,有了胡老师的帮助,我们的流程图更加的规范、正确。再一次谢谢胡老师。六:人员分工:组内成员一起构思了流程图。并完成最后的整理工作