自己编的飞机票售票系统
#include<stdio.h> #include<stdlib.h> #include<string.h> #define status 1 #define null 0 #define ok 1 #define error 0 staticint seats_left=1; typedef struct time { int hour; int minute; int second; }time; typedef struct airline { char flight[20]; //航班号 char arrival_station[20]; //终点站 time takeoff_time; //起飞时间 time arrival_time; //到达时间 int seats_num; //飞机总可乘人数 //剩下座位 float ticket_money; //机票价格 struct airline *next; }airline,*airlinelinklist; typedef struct custome { char name[20]; char IDcard[20]; char flight[20]; float ticket_money; time takeoff_time; time arrival_time; char arrival_station[20]; int seat_num; struct custome *next; }custome,*customelinklist; void creat_airline(airlinelinklist &l) { FILE *fp; airline *p,*q; char filename[20]; printf("航班情况数据由机场工作人员输入\n"); a: printf("请输入航班情况文件目录\n"); //scanf("%s",filename); if((fp=fopen("d:\\11.txt","r"))==null) { printf("读入航班数据出现错误请重新读入\n"); goto a; } l=(airline *)malloc(sizeof(airline)); q=(airline *)malloc(sizeof(airline)); q=l; while(!feof(fp)) { p=(airline *)malloc(sizeof(airline)); fscanf(fp,"%s%s%d%d%d%d%d%d%d%f",p->flight,p->arrival_station,&p->takeoff_time.hour,&p->takeoff_time.minute,&p->takeoff_time.second, &p->arrival_time.hour,&p->arrival_time.minute,&p->arrival_time.second,&p->seats_num,&p->ticket_money); q->next=p; q=q->next; } q->next=null; } staticint e=0; void book_custome_flight(airlinelinklist &air,customelinklist &l) { customelinklist p,a; airlinelinklist q; q=(airlinelinklist)malloc(sizeof(airline)); p=(customelinklist)malloc(sizeof(custome)); a=(customelinklist)malloc(sizeof(custome)); printf("请输入您的姓名\n"); scanf("%s",p->name); printf("请输入你的ID号码\n"); scanf("%s",p->IDcard); printf("请输入航班号\n"); scanf("%s",p->flight); q=air->next; a=l; while(a->next) a=a->next; while(q) { if(strcmp(q->flight,p->flight)==0) { if(seats_left<q->seats_num) { p->seat_num=seats_left; seats_left++; p->takeoff_time.hour=q->takeoff_time.hour; p->takeoff_time.minute=q->takeoff_time.minute; p->takeoff_time.second=q->takeoff_time.second; p->arrival_time.hour=q->arrival_time.hour; p->arrival_time.minute=q->arrival_time.minute; p->arrival_time.second=q->arrival_time.second; p->ticket_money=q->ticket_money; strcpy(p->flight,q->flight); strcpy(p->arrival_station,q->arrival_station); a->next=p; p->next=null; printf("恭喜订票成功\n"); printf(" \n"); printf("你的姓名:%s\nIDCARD:%s\n航班号:%s\n起飞时间%d点 %d分 %d秒\n抵达时间%d点 %d分 %d秒\n座位号%d\n抵达目的地%s\n飞机票价格%f\n", p->name,p->IDcard,p->flight,p->takeoff_time.hour,p->takeoff_time.minute,p->takeoff_time.second, p->arrival_time.hour,p->arrival_time.minute,p->arrival_time.second,p->seat_num,p->arrival_station,p->ticket_money); e=1; } else printf("对不起,座位已经满了订票不成功\n"); } q=q->next; } if(e!=1) printf("对不起没有这个航班号\n"); } void book_custome_arrival_station(airlinelinklist &air,customelinklist &l) { customelinklist p,a; airlinelinklist q; q=(airlinelinklist)malloc(sizeof(airline)); p=(customelinklist)malloc(sizeof(custome)); a=(customelinklist)malloc(sizeof(custome)); l=(customelinklist)malloc(sizeof(custome)); l->next=null; q=air->next; printf("请输入您的姓名\n"); scanf("%s",p->name); printf("请输入你的ID号码\n"); scanf("%s",p->IDcard); printf("请输入目的地\n"); scanf("%s",p->arrival_station); a=l; while(a->next) a=a->next; while(q) { if(strcmp(q->arrival_station,p->arrival_station)==0) { if(seats_left<q->seats_num) { p->seat_num=seats_left; seats_left++; p->takeoff_time.hour=q->takeoff_time.hour; p->takeoff_time.minute=q->takeoff_time.minute; p->takeoff_time.second=q->takeoff_time.second; p->arrival_time.hour=q->arrival_time.hour; p->arrival_time.minute=q->arrival_time.minute; p->arrival_time.second=q->arrival_time.second; p->ticket_money=q->ticket_money; strcpy(p->flight,q->flight); a->next=p; p->next=null; printf("恭喜订票成功\n"); printf(" \n"); printf("你的姓名:%s\nIDCARD:%s\n航班号:%s\n起飞时间%d点 %d分 %d秒\n抵达时间%d点 %d分 %d秒\n座位号%d\n抵达目的地%s\n%.2f", p->name,p->IDcard,p->flight,p->takeoff_time.hour,p->takeoff_time.minute,p->takeoff_time.second, p->arrival_time.hour,p->arrival_time.minute,p->arrival_time.second,p->seat_num,p->arrival_station,p->ticket_money); e=1; } else printf("对不起,座位已经满了订票不成功\n"); } q=q->next; } if(e!=1) printf("对不起没有这个抵达地\n"); } void del_custome(customelinklist &l) { customelinklist p; customelinklist q; staticint o=0; p=(customelinklist)malloc(sizeof(custome)); q=(customelinklist)malloc(sizeof(custome)); printf("请输入您的姓名\n"); scanf("%s",p->name); printf("请输入你的ID号码\n"); scanf("%s",p->IDcard); printf("请输入航班号\n"); scanf("%s",p->flight); q=l; if(e!=1) goto m; while(q) { if(strcmp(p->flight,q->next->flight)==0&&strcmp(p->name,q->next->name)==0&&strcmp(q->next->IDcard,p->IDcard)==0) { printf("成功删除,删除的信息为:\n"); printf("姓名:%s IDCARD:%s 航班号:%s\n",q->next->name,q->next->IDcard,q->next->flight); l=q->next; q->next=q->next->next; free(l); o=1; } q=q->next; } if(o!=1) m: printf("对不起,您的姓名、IDCARD、航班号核对错误\n"); } void search_flight(airlinelinklist &air) { airlinelinklist p; p=(airlinelinklist)malloc(sizeof(airline)); p=air->next; while(p) { printf("航班号:%s\n抵达目的地:%s\n起飞时间:%d点 %d分 %d秒\n抵达时间:%d点 %d分 %d秒\n座位数:%d\n飞机票价格:%.2f\n",p->flight,p->arrival_station, p->takeoff_time.hour,p->takeoff_time.minute,p->takeoff_time.second, p->arrival_time.hour,p->arrival_time.minute,p->arrival_time.second,p->seats_num,p->ticket_money); p=p->next; } } int search_name(customelinklist &l) { staticint w=0; customelinklist p; char name[20],idcard[20]; p=(customelinklist)malloc(sizeof(custome)); printf("请输入你要查询的客户名字\n"); scanf("%s",name); printf("请输入此客户的IDCARD\n"); scanf("%s",idcard); p=l->next; if(e!=1) goto n; while(p) { if(strcmp(idcard,p->IDcard)==0&&strcmp(name,p->name)==0) { printf("已经查到此客户信息\n"); printf("姓名:%s\nIDCARD:%s\n航班号:%s\n起飞时间%d点 %d分 %d秒\n抵达时间%d点 %d分 %d秒\n座位号%d\n抵达目的地%s\n飞机票价格:%.2f\n", p->name,p->IDcard,p->flight,p->takeoff_time.hour,p->takeoff_time.minute,p->takeoff_time.second, p->arrival_time.hour,p->arrival_time.minute,p->arrival_time.second,p->seat_num,p->arrival_station,p->ticket_money); w=1; } p=p->next; } if(w!=1) n: printf("对不起没有查到此客户\n"); return1; } void search_station(airlinelinklist &air) { staticint i=0; airlinelinklist p; char station[20]; p=(airlinelinklist)malloc(sizeof(airline)); printf("请输入你要查询的抵达站名称\n"); scanf("%s",station); p=air->next; while(p) { if(strcmp(station,p->arrival_station)==0) { printf("已经查到此站的信息\n"); printf("航班号:%s\n抵达目的地:%s\n起飞时间:%d点 %d分 %d秒\n抵达时间:%d点 %d分 %d秒\n座位数:%d\n飞机票价格:%.2f\n",p->flight, p->arrival_station,p->takeoff_time.hour,p->takeoff_time.minute,p->takeoff_time.second, p->arrival_time.hour,p->arrival_time.minute,p->arrival_time.second,p->seats_num,p->ticket_money); i=1; } p=p->next; } if(i!=1) printf("没有查到此站\n"); } void search_a_flight(airlinelinklist &air) { staticint k=0; airlinelinklist p; char flight[20]; p=(airlinelinklist)malloc(sizeof(airline)); p=air->next; printf("请输入你要查询的航班号\n"); scanf("%s",flight); while(p) { if(strcmp(flight,p->flight)==0) { printf("航班号:%s\n抵达目的地:%s\n起飞时间:%d点 %d分 %d秒\n抵达时间:%d点 %d分 %d秒\n座位数:%d\n飞机票价格:%.2f\n",p->flight,p->arrival_station, p->takeoff_time.hour,p->takeoff_time.minute,p->takeoff_time.second, p->arrival_time.hour,p->arrival_time.minute,p->arrival_time.second,p->seats_num,p->ticket_money); k=1; } p=p->next; } if(k!=1) printf("对不起没有此航班\n"); } main() { int x; airlinelinklist air; customelinklist myl; creat_airline(air); myl=(customelinklist)malloc(sizeof(custome)); myl->next=null; b: printf("********************************\n"); printf(" 欢迎光临飞机票预定系统\n"); printf("********************************\n"); printf("1.订票 2.退票\n"); printf("3.查询 4.退出\n"); c: printf("请输入你的选择:\n"); scanf("%d",&x); getchar(); switch(x) { case1: d: printf("**********欢迎飞机订票************\n"); printf("1.根据航班订票 2.根据目的地订票\n"); printf("3.返回主菜单 4.退出\n"); printf("**********************************\n"); printf("请输入你的选择:\n"); scanf("%d",&x); getchar(); switch(x) { case1: book_custome_flight(air,myl); break; case2: book_custome_arrival_station(air,myl); break; case3: goto b; case4: exit(0); default: printf("输入错误,请重新输入\n"); goto d; } break; case2: del_custome(myl); break; case3: e: printf("**************************\n"); printf("#######欢迎航班查询#######\n"); printf("**************************\n"); printf("1.所有航班查询 2.姓名查询\n"); printf("3.终点站查询 4:指定航班查询\n5.返回主菜单\n"); printf("6.退出\n"); printf("请输入你的选择:\n"); scanf("%d",&x); getchar(); switch(x) { case1: search_flight(air); break; case2: search_name(myl); break; case3: search_station(air); break; case4: search_a_flight(air); break; case5: goto b; break; case6: exit(0); default: printf("输入错误,请重新输入\n"); goto e; } goto e; break; case4: exit(0); default : printf("输入错误,请重新输入\n"); goto b; } goto b; }