#includestdio.h#includestring.h#includestdlib.h#includetime.h#includeconio.h#defineN1000typedefstructTICKET//定义新结构体TICKET{charnum[10];//车次charhour[3];charmin[3];charfrom[10];charto[10];floathours;intmax;//车载容量intnow;//已售票数}CLASS;intclass_num=0;CLASSrecords[N];intsystem_time();voidmessage();voidShowTable1();voidShowTable2(inti);voidDisplay();voidadd();voidsave();voidload();//按班次查询voidsearch();//查询voidchange();//修改voidquit();//退出voidbuyticket();//售票voiddeleteticket();//取消intmenu_select();//菜单intwhether(int);//判断购买时间voidfind(chars1[],chars2[]);//按起点终点查询voiddeletemessage();//删除intfindnum(chars1[]);//班次查询voidget(int,int);//修改及增加班次char*menu[]={欢迎使用车票查询系统,\n*******************菜单***********************,\n1.录入班次,\n2.浏览班次信息,\n3.查询路线,\n4.增加班次,\n5.售票,\n6.退票,\n7.修改班次,\n8.删除班次,\n9.退出};intmain(){system(cls);while(1){switch(menu_select())//菜单{case1:message();break;case2:Display();break;case3:search();break;case4:add();break;case5:buyticket();break;case6:deleteticket();break;case7:change();break;case8:deletemessage();break;case9:quit();break;}}}intmenu_select()//菜单{chars[5];intc,i;system(cls);for(i=0;i11;i++){printf(%s,menu[i]);//输出菜单}i=0;while(c0||c9){printf(\n);printf(\n请输入选项(1-9):);scanf(%s,s);c=atoi(s);}//输出菜单returnc;}voidmessage()//录入{inti=0,j=5,h;chars[5];FILE*fp;//定义文件型指针变量system(cls);//刷屏if((fp=fopen(d:车票管理系统0.dat,rb))!=NULL)//fopen打开文件{printf(增加信息\n);printf(请输入任意键返回\n);scanf(%s,s);i=1;}if(i==0){system(cls);//刷屏printf(请输入班次总数:\n);scanf(%d,&class_num);//指向班次指针system(cls);//刷屏for(i=0;iclass_num;i++){system(cls);//刷屏printf(请输入%d班次信息:\n,i+1);h=-1;for(;h!=i;)///循环输出{printf(请输入班次:\n);scanf(%s,records[i].num);for(h=0;hi;h++)if(strcmp(records[h].num,records[i].num)==0){printf(该班次已存在\n);break;}}get(i,j);//修改及增加班次j=5;}save();//调用保存函数}}/*******************************显示所有函数********************************/voidDisplay()//显示所有函数{inti,j;system(cls);//刷屏load();//按班次查询ShowTable1();for(i=0,j=0;iclass_num;i++,j+=2)//按班次顺序输出{if(whether(i))//判断时间是否超出printf(|%10s|%5s:%-4s|%10s|%10s|%8.1f|%8d|%8d|,records[i].num,records[i].hour,records[i].min,records[i].from,records[i].to,records[i].hours,records[i].max,records[i].now);elseprintf(|%10s|已发车|%10s|%10s|%8.1f|%8d|%8d|,records[i].num,records[i].from,records[i].to,records[i].hours,records[i].max,records[i].now);}ShowTable2(j);printf(\n按任意键继续\n);getch();}voidShowTable1(){inti=2;system(cls);//刷屏printf(班次信息\n);printf(\n|----------|----------|----------|----------|--------|--------|--------|\n);printf(\n|班次|发车时间|起点站|终点站|行车时间|额定载量|已售票|\n);}voidShowTable2(inti){printf(\n|----------|----------|----------|----------|--------|--------|--------|\n);}voidsearch()//查询班次{inti;chars1[10]={'\0'},s2[10]={'\0'};system(cls);//刷屏printf(1.按班次查询\n);printf(2.按终点站查询\n);printf(3.退出\n);printf(请选择(1-3):\n);scanf(%d,&i);load();//按班次查询switch(i){case1:printf(请输入要查询的班次:\n);scanf(%s,s1);find(s1,s2);break;case2:printf(请输入要查询终点站:\n);scanf(%s,s2);find(s1,s2);break;case3:break;default:printf(输入错误!\n);break;}printf(按任意键继续\n);getch();}voidfind(chars1[],chars2[]){inti,h=0,m;ShowTable1();if(s2[0]=='\0')m=1;elsem=0;for(i=0;iclass_num;i++)if(strcmp(s1,records[i].num)==0||strcmp(s2,records[i].to)==0){printf(\n);printf(|%10s|%5s:%-4s|%10s|%10s|%8.1f|%8d|%8d|,records[i].num,records[i].hour,records[i].min,records[i].from,records[i].to,records[i].hours,records[i].max,records[i].now);h+=2;if(m==1)break;}ShowTable2(h);if(h==0)printf(查找的班次不存在\n);}voidadd(){inti,j=5;load();system(cls);printf(1.增加班次\n);printf(2.返回\n);printf(请选择(1-2)\n);scanf(%d,&i);if(i==1){system(cls);printf(1.输入要增加的班次:\n);scanf(%s,records[class_num].num);for(i=0;iclass_num;i++)if(strcmp(records[class_num].num,records[i].num)==0){printf(输入错误\n);getch();break;}if(i==class_num){get(i,j);class_num++;save();}}}voidbuyticket(){inti;charnum[10];system(cls);printf(1.售票\n);printf(2.返回\n);printf(请选择(1-2):\n);scanf(%d,&i);if(i==1){load();//按班次查询search();printf(请输入要订票的班次(若无请输入0):\n);scanf(%s,num);for(i=0;iclass_num;i++)if(strcmp(num,records[i].num)==0)if(records[i].maxrecords[i].now&&whether(i)==1){records[i].now++;printf(通向%s班次为%s的票订票成功\n,records[i].to,records[i].num);save();getch();break;}else{printf(该班次已满或已发出!\n);getch();}}}voiddeleteticket(){inti;charnum[10];system(cls);printf(1.退票\n);printf(2.返回\n);printf(请选择(1-2)\n:);scanf(%d,&i);if(i==1){system(cls);load();printf(请输入要退票的班次:\n);scanf(%s,num);i=findnum(num);if(strcmp(num,records[i].num)==0)if(whether(i)){printf(是否确认);scanf(%s,num);if(num[0]=='y'||num[0]=='Y'){records[i].now--;printf(退票成功\n);save();getch();}}else{printf(该班车已发出,无法退票\n);getch();}if(i==class_num){printf(输入错误\n);getch();}}}voidchange(){charnum[10],s[10];inth=0,j=13,i;load();system(cls);printf(请输入要修改的班次:\n);scanf(%s,num);i=findnum(num);if(i==class_num){printf(输入错误\n);getch();}else{printf(确认修改\n);scanf(%s,s);if(s[0]=='y'||s[0]=='Y'){get(i,j);save();}}}voiddeletemessage(){inti,h=0;charnum[10];system(cls);printf(1.删除班次\n);printf(2.返回\n);printf(请选择(1-2):\n);scanf(%d,&i);if(i==1){system(cls);printf(请输入要删除的班次:\n);scanf(%s,num);i=findnum(num);if(i==class_num