航班查询系统C语言源程序.doc
【精品文档】如有侵权,请联系网站删除,仅供学习与交流航班查询系统 C语言源程序.精品文档.#include <stdio.h>#include <stdlib.h>#include <string.h>#define NOD struct plane_liststruct planechar number 10;char start10;char arrive 10;char date10;char starttime10;char arrivingtime10;char price10;char model10;NODchar number 10;char start10;char arrive 10;char date10;char starttime10;char arrivingtime10;char price10;char model10;NOD*next;FILE *fp;/*由文件中的数据生成一个飞机航班的链表,如果文件不存在,则是一个空链表*/NOD *load(char planename) NOD *p,*q,*head; struct plane per; p=(NOD *)malloc(sizeof(NOD); q=head=NULL; if(fp=fopen(planename,"rb")=NULL) return head; else while(!feof(fp) if(fread(&per,sizeof(struct plane),1,fp)=1) p=(NOD *)malloc(sizeof(NOD); strcpy(p->number,per.number); strcpy(p->start,per.start); strcpy(p->arrive,per.arrive); strcpy(p->date,per.date); strcpy(p->starttime,per.starttime); strcpy(p->arrivingtime,per.arrivingtime); strcpy(p->price,per.price); strcpy(p->model,per.model); head=p; p->next=q; q=head; fclose(fp); return(head);/*输入*/NOD *insert(NOD *head) NOD *temp,*p; p=head; temp=(NOD *)malloc(sizeof(NOD);printf("nt请输入航班号:");scanf("%s",temp->number);printf("nt请输入起点站:");scanf("%s",temp->start);printf("nt请输入终点站:");scanf("%s",temp->arrive);printf("nt请输入起飞时间:");scanf("%s",temp->starttime);printf("nt请输入到达时间:");scanf("%s",temp->arrivingtime);printf("nt请输入班期:");scanf("%s",temp->date);printf("nt请输入票价:");scanf("%s",temp->price);printf("nt请输入航班型号:");scanf("%s",temp->model);head=temp;temp->next=p;return head;/*保存*/void save(NOD *head, char filename)NOD*p; struct plane per; if(fp=fopen(filename,"wb")=NULL) printf(" 文件无法写入"); exit(0); else p=head; while(p!=NULL) strcpy(per.number,p->number); strcpy(per.start,p->start); strcpy(per.arrive,p->arrive); strcpy(per.date,p->date); strcpy(per.starttime,p->starttime); strcpy(per.arrivingtime,p->arrivingtime); strcpy(per.price,p->price); strcpy(per.model,p->model);if(fwrite(&per,sizeof(struct plane),1,fp)!=1)printf("文件不能写入数据,请检查后重新运行.n");exit(0);p=p->next; fclose(fp);/*显示*/void display(NOD *head) NOD *p; p=head; while(p!=NULL) printf("航班号:%sn",p->number); printf("起点站:%sn",p->start); printf("终点站:%sn",p->arrive); printf("班期:%sn",p->date); printf("起飞时间:%sn",p->starttime);printf("到达时间:%sn",p->arrivingtime); printf("票价:%sn",p->price); printf("飞机型号:%sn",p->model);p=p->next;/*航班号查找*/void finda(NOD *head) NOD *p; char number10; printf("请输入查找航班的编号:"); scanf("%s",number); p=head; while (p!=NULL) if(strcmp(number,p->number)=0) printf("航班号:%sn",p->number); printf("起点站:%sn",p->start); printf("终点站:%sn",p->arrive); printf("班期:%sn",p->date); printf("起飞时间:%sn",p->starttime);printf("到达时间:%sn",p->arrivingtime); printf("票价:%sn",p->price); printf("飞机型号:%sn",p->model);break; else p=p->next; if(p=NULL) printf("nt查无此航班n");/*起点站查找*/void findb(NOD *head) NOD *p; char start10; printf("请输入查找航班的起点站:"); scanf("%s",start); p=head; while (p!=NULL) if(strcmp(start,p->start)=0) printf("航班号:%sn",p->number); printf("起点站:%sn",p->start); printf("终点站:%sn",p->arrive); printf("班期:%sn",p->date); printf("起飞时间:%sn",p->starttime);printf("到达时间:%sn",p->arrivingtime); printf("票价:%sn",p->price); printf("飞机型号:%sn",p->model);break; else p=p->next; if(p=NULL) printf("nt查无此航班n");/*终点站查找*/void findc(NOD *head) NOD *p; char arrive10; printf("请输入查找航班的终点站:"); scanf("%s",arrive); p=head; while (p!=NULL) if(strcmp(arrive,p->arrive)=0) printf("航班号:%sn",p->number); printf("起点站:%sn",p->start); printf("终点站:%sn",p->arrive); printf("班期:%sn",p->date); printf("起飞时间:%sn",p->starttime);printf("到达时间:%sn",p->arrivingtime); printf("票价:%sn",p->price); printf("飞机型号:%sn",p->model);break; else p=p->next; if(p=NULL) printf("nt查无此航班n");/*起飞时间查找*/void findd(NOD *head) NOD *p; char starttime10; printf("请输入查找航班的起飞时间:"); scanf("%s",starttime); p=head; while (p!=NULL) if(strcmp(starttime,p->starttime)=0) printf("航班号:%sn",p->number); printf("起点站:%sn",p->start); printf("终点站:%sn",p->arrive); printf("班期:%sn",p->date); printf("起飞时间:%sn",p->starttime);printf("到达时间:%sn",p->arrivingtime); printf("票价:%sn",p->price); printf("飞机型号:%sn",p->model);break; else p=p->next; if(p=NULL) printf("nt查无此航班n");/*到达时间查找*/void finde(NOD *head) NOD *p; char arrivingtime10; printf("请输入查找航班的到达时间:"); scanf("%s",arrivingtime); p=head; while (p!=NULL) if(strcmp(arrivingtime,p->arrivingtime)=0) printf("航班号:%sn",p->number); printf("起点站:%sn",p->start); printf("终点站:%sn",p->arrive); printf("班期:%sn",p->date); printf("起飞时间:%sn",p->starttime);printf("到达时间:%sn",p->arrivingtime); printf("票价:%sn",p->price); printf("飞机型号:%sn",p->model);break; else p=p->next; if(p=NULL) printf("nt查无此航班n");/*删除*/NOD *dele(NOD *head) NOD *p,*q; char number5; printf(":请输入要删除的航班编号"); scanf("%s",number); p=q=head; while(p!=NULL) if(strcmp(number,p->number)=0) if(head=p) head=p->next; else q->next=p->next; free(p); break; else q=p; p=p->next; if(p=NULL)printf("nt查无此航班n"); return head;/*主函数*/void main() NOD *head;char fnum10;int choise;printf("nt欢迎光临航班查询系统:");scanf("%s",fnum);head=load(fnum);while(1) printf("ntt 航班信息检索与查询n"); printf("tt*n"); printf("tt 1.航班号查找n"); printf("tt 2.起点站查找n"); printf("tt 3.终点站查找n"); printf("tt 4.起飞时间查找n"); printf("tt 5.到达时间查找n"); printf("tt 6.航班号删除n"); printf("tt 7.增加新航班n"); printf("tt 8.显示所有航班n"); printf("tt 9.存盘并退出n"); printf("nt请选择1-9:"); scanf("%d",&choise); switch(choise) case 1:finda(head);break; case 2:findb(head);break; case 3:findc(head);break; case 4:findd(head);break; case 5:finde(head);break; case 6:head=dele(head);break; case 7:head=insert(head);break; case 8:display(head);break; case 9:save(head,fnum); exit(0); default:printf("输入错误,重新输入n");