基于C语言数据结构的航班查询系统.doc_第1页
基于C语言数据结构的航班查询系统.doc_第2页
基于C语言数据结构的航班查询系统.doc_第3页
基于C语言数据结构的航班查询系统.doc_第4页
基于C语言数据结构的航班查询系统.doc_第5页
已阅读5页,还剩3页未读 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

/*简易航班查询系统 *By liaoye9281、功能:实现以下功能:1)信息录入2)信息显示(按照起飞时间先后顺序显示)3)信息查询(可根据不同的关键字进行查询)2、说明:1)使用链表对录入的信息进行存储2)对录入的信息进行排序(可按起飞时间进行排序)*/#includeinclude.hint main(void)Node_list *L; /定义存储链表init_N(&L); /初始化链表char ch;Data_type *E; /定义航班信息结构体FILE *fp;/文件指针fp=fopen(flight_input.txt,r);E=(Data_type *)malloc(sizeof(Data_type);while(8 =fscanf(fp,%d %s %s %s %s %s %s %d,&E-number,E-staddress,E-arraddress,E-DATE,E-TYPE,E-stime,E-atime,&E-value)/读取文件内容,对应结构体各元素save_insert(L,E);/将其放入链表存储E=(Data_type *)malloc(sizeof(Data_type);/开辟结构体指针Bubsort_number(L);Welcome:/goto语句标签printf(*n);printf(*n);printf(*- *n);printf(* Flight inquires the system * *n);printf(*- *n);printf(*n);printf(*Please chioce the way to inquires : *n);printf(*- *n);printf(* A:Scan all flight information *n);printf(* B:By flight numble *n);printf(*C:By start address *n);printf(* D:By arrive address *n);printf(* E:By data *n);printf(* F:Exit system *n);printf(*n);printf(*n);char choice;/读取用户选择int num;char s_addr10;char a_addr10;char date10;printf(*Please input your choice here: );while(1 = scanf( %c,&choice)if(A = choice)show_info(L);/浏览所有航班信息printf(*Please input your choice here: );continue;if(B = choice)printf(please input the flight numble:);scanf(%d,&num);inquire_by_number(L,num);/根据航班号查找printf(*Please input your choice here: );continue;if(C = choice)printf(please input the flight take off address:);scanf( %s,s_addr);inquire_by_staddress(L,s_addr);/根据起飞地点查找printf(*Please input your choice here: );continue;if(D = choice)printf(please input the flight arrived address:);scanf( %s,a_addr);inquire_by_araddress(L,a_addr);/根据降落地点查找并显示printf(*Please input your choice here: );continue;if(E = choice)printf(please input the flight take off date:);scanf( %s,date);inquire_by_data(L,date);/根据航班日期浏览,并根据起飞时间排序printf(*Please input your choice here: );continue;if(F = choice)printf(goodbye!n);exit(1);/退出系统else printf(Dont have this option.n*Please input your choice here:n);goto Welcome;/输入错误提示并返回 欢迎界面 return 0;/*定义头文件*/#ifndef _INCLUDE_H_#define _INCLUDE_H_ #include#include#include#includetypedef struct flight /定义航班信息结构体类型int number;char staddress10;char arraddress10;char DATE10;char TYPE4;char stime10;char atime10;int value;Data_type;typedef struct node /定义存储航班信息结构体链表Data_type *info;struct node *next;Node_list;/*各函数的定义*/bool init_N(Node_list *);bool init_D(Data_type *);bool save_insert(Node_list *,Data_type *);bool Bubsort_number(Node_list *);bool Bubsort_statime(Node_list *);void show_info(Node_list *);void inquire_by_number(Node_list *,int);void inquire_by_staddress(Node_list *,char *);void inquire_by_araddress(Node_list *,char *);void inquire_by_data(Node_list *,char *);#endif#includeinclude.hbool init_N(Node_list *L)/用于存储的链表初始化(*L)=(Node_list *)malloc(sizeof(Node_list);if(NULL != (*L)(*L)-next=NULL;return true;elseprintf(malloc failed!n);return false;bool init_D(Data_type *E)/航班信息结构体初始化(*E)=(Data_type *)malloc(sizeof(Data_type);if(NULL != (*E)return true;else printf(malloc failed!n);return false;bool save_insert(Node_list *L,Data_type *E)/插入链表存储Node_list *new_node;init_N(&new_node);new_node-info=E;while(L-next != NULL) L=L-next;L-next=new_node;return true;bool Bubsort_number(Node_list *L)/根据航班号排序Node_list *p,*q;Data_type *tmp;for(p=L-next;p != NULL; p=p-next)for(q=p-next;q != NULL; q=q-next )if(p-info-number q-info-number)tmp=p-info;p-info=q-info;q-info=tmp;void show_one(Node_list *L) /封转打印函数,固定打印格式 printf(%-9d%-10s- %-11s%-10s%-6s%-9s%-9s%-8dn,L-info-number,L-info-staddress,L-info-arraddress,L-info-DATE,L-info-TYPE,L-info-stime,L-info-atime,L-info-value);void show_info(Node_list *L)/显示当前链表的所有信息char a80;printf(f_number path DATE );printf(TYPE statime arr_time valuen);while(L-next != NULL)L=L-next;show_one(L);void inquire_by_number(Node_list *L, int num )/查找航班号为用户所需,并显示到屏幕L=L-next; int flag=0;while(L != NULL)if(num = L-info-number)show_one(L);flag=1;break;L=L-next;if( flag = 0) printf(sorry! Not found this flight!n);void inquire_by_staddress(Node_list *L,char s)/根据起飞地点查找并显示int flag=0;L=L-next;while(L != NULL)if(strcmp(s,L-info-staddress) = 0)show_one(L);flag=1;L=L-next;if(flag = 0) printf(sorry! Not found this flight!n);void inquire_by_araddress(Node_list *L,char a)/根据降落地点查找并显示int flag=0;L=L-next;while(L != NULL)if(strcmp(a,L-info-arraddress) =0)show_one(L);flag=1;L=L-next;if( flag = 0 )printf(sorry! Not found this flight!n);bool Bubsort_statime(Node_list *L)/根据起飞时间排序(用于按航班日期查询显示函数)Node_list *p,*q;Data_type *tmp;for(p=L-next;p != NULL; p=p-next)for(q=p-next;q != NULL; q=q-next )if(strcmp(p-info-stime,q-info-atime) 0)tmp=p-info;p-info=q-info;q-info=tmp;void inquire_by_data(Node_list *L,char d)/根据航班日期查找并显示Node_list *N;/用于存储所有当日的所有航班init_N(&N);L=L-next;int flag = 0;/标签,用于未找到该航班是判断while(L != NULL)if(strcmp(d,L-info-DATE) = 0)save_insert(N,L-info);flag=1; L=L-next;Bubsort_statime(N);/按起飞时间排序show_info(N);/打印当前链表存储的航班信息if(flag = 0)printf(sorry! Not found this flight!n);/*flight_input.txt*/1001 Beijing London 20120701 A 1

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论