您好,欢迎访问三七文档
当前位置:首页 > 办公文档 > 总结/报告 > 火车票务管理系统(C语言)
火车票务管理系统一、课题内容和要求设计目标:设计一个火车票务管理系统,用C语言实现。对该系统的要求如下:需求描述:1.系统功能(1)火车时刻信息录入。包括车次、日期、起点、终点、开车时间、到达时间、票价。数据存入数据文件hchsk.dat或hchsk.txt中。(2)火车时刻信息查询。按照车次查询按终点查询按起点查询按终点和日期查询(3)统计按终点统计每日的车次数按起点统计每日的车次数2.系统主界面应有以下功能选项录入火车时刻信息查询火车时刻信息统计火车车次退出注:建议用VC环境开发用户界面。结果形式:提交程序设计报告和可演示的系统软件二、需求分析系统主界面应有以下功能选项1.录入火车时刻信息2.查询火车时刻信息3.统计火车车次4.退出(1)火车时刻信息录入。包括车次、日期、起点、终点、开车时间、到达时间、票价。数据存入数据文件hchsk.dat或hchsk.txt中。(2)火车时刻信息查询。按照车次查询按终点查询按起点查询按终点和日期查询(3)统计按终点统计每日的车次数按起点统计每日的车次数二、概要设计voidSearchTrainNum();//按照车次查询voidSearchToPlace();//按终点查询voidSearchFromPlace();//按起点查询voidSearchToPlaceAndDate();//按终点和日期查询voidCountToPlace();//按终点统计每日的车次数voidCountFromPlace();//按起点统计每日的车次数三、详细设计程序的源代码与注释#includestdio.h#includestring.h#includestdlib.hvoidSearchTrainNum();voidSearchToPlace();voidSearchFromPlace();voidSearchToPlaceAndDate();voidCountToPlace();voidCountFromPlace();voidStar();structTRAIN{chartrainNum[10];chardate[30];charfromPlace[20];chartoPlace[20];charinTime[30];charoutTime[30];doubleprice;};structTRAINtrain[30];intmain(){intrequest;charch='Y';inti=0;doublemyprice;FILE*fp;repeat:Star();printf(火车管理系统界面\n);printf(1.录入火车时刻信息.\n);printf(2.查询火车时刻信息.\n);printf(3.统计火车车次.\n);printf(4.退出.\n);Star();printf(\n);printf(请输入:);scanf(%d,&request);switch(request)//利用case分支结构{case1:{fp=fopen(.\\train.rec,wb);//利用文件与流if(!fp){printf(Filecannotbeopened\n);exit(1);}do{printf(Enter车次日期起点终点开车时间到达时间票价\n);scanf(%s%s%s%s%s%s%lf,train[i].trainNum,train[i].date,train[i].fromPlace,train[i].toPlace,train[i].inTime,train[i].outTime,&myprice);train[i].price=myprice;fwrite(&train[i],sizeof(structTRAIN),1,fp);i++;printf(continue(Y/N)(Ntoend)?);getchar();scanf(%c,&ch);}while(ch!='N');fclose(fp);printf(返回主界面吗?(Y返回));getchar();scanf(%c,&ch);if(ch=='Y'){printf(\n\n);gotorepeat;}}break;case2:{printf(\n\n);printf(火车时刻信息查询\n);printf(1.按车次查询.\n);printf(2.按终点查询.\n);printf(3.按起点查询.\n);printf(4.按终点和日期查询.\n);printf(5.退出.\n);printf(请输入:);scanf(%d,&request);switch(request){case1:SearchTrainNum();break;case2:SearchToPlace();break;case3:SearchFromPlace();break;case4:SearchToPlaceAndDate();break;case5:exit(0);break;}printf(返回主界面吗?(Y返回));getchar();scanf(%c,&ch);if(ch=='Y'){printf(\n\n);gotorepeat;}}break;case3:{printf(\n\n);printf(火车车次统计系统\n);printf(1.按终点统计每日的车次数.\n);printf(2.按起点统计每日的车次数.\n);printf(3.退出.\n);printf(请输入:);scanf(%d,&request);switch(request){case1:CountToPlace();break;case2:CountFromPlace();break;case3:exit(0);break;}printf(返回主界面吗?(Y返回));getchar();scanf(%c,&ch);if(ch=='Y'){printf(\n\n);gotorepeat;}}break;case4:{Star();printf(欢迎下次使用,拜拜~~\n);Star();}exit(0);break;default:printf(Incorrectnumentered.);printf(Enteranewnum.\n);break;}return0;}voidSearchTrainNum(){FILE*fp1;charnum[20];charch;inti=0;fp1=fopen(.\\train.rec,r+);if(!fp1){printf(Filecannotbeopened\n);exit(1);}do{rewind(fp1);//文件指针的操作,到文件头部函数printf(输入你要查找的车次号.\n);scanf(%s,num);while(!feof(fp1)){fread(&train[i],sizeof(structTRAIN),1,fp1);if(strcmp(num,train[i].trainNum)==0){printf(%-4s%-12s%-8s%-10s%-10s%-8s%.2lf,train[i].trainNum,train[i].date,train[i].fromPlace,train[i].toPlace,train[i].inTime,train[i].outTime,train[i].price);printf(\n);}i++;}printf(continue(Y/N)(Ntoend)?);getchar();scanf(%c,&ch);}while(ch!='N');printf(\n);fclose(fp1);}voidSearchToPlace(){FILE*fp2;charnum[20];charch;inti=0;fp2=fopen(.\\train.rec,r+);if(!fp2){printf(Filecannotbeopened\n);exit(1);}do{rewind(fp2);printf(输入你要查询的终点.\n);scanf(%s,num);while(!feof(fp2)){fread(&train[i],sizeof(structTRAIN),1,fp2);if(strcmp(num,train[i].toPlace)==0){printf(%-4s%-12s%-8s%-10s%-10s%-8s%.2lf,train[i].trainNum,train[i].date,train[i].fromPlace,train[i].toPlace,train[i].inTime,train[i].outTime,train[i].price);printf(\n);}i++;}printf(continue(Y/N)(Ntoend)?);getchar();scanf(%c,&ch);}while(ch!='N');printf(\n);fclose(fp2);}voidSearchFromPlace(){FILE*fp3;charnum[20];charch;inti=0;fp3=fopen(.\\train.rec,r+);if(!fp3){printf(Filecannotbeopened\n);exit(1);}do{rewind(fp3);printf(输入你要查询的起点.\n);scanf(%s,num);while(!feof(fp3)){fread(&train[i],sizeof(structTRAIN),1,fp3);if(strcmp(num,train[i].fromPlace)==0){printf(%-4s%-12s%-8s%-10s%-10s%-8s%.2lf,train[i].trainNum,train[i].date,train[i].fromPlace,train[i].toPlace,train[i].inTime,train[i].outTime,train[i].price);printf(\n);}i++;}printf(continue(Y/N)(Ntoend)?);getchar();scanf(%c,&ch);}while(ch!='N');printf(\n);fclose(fp3);}voidSearchToPlaceAndDate(){FILE*fp4;charnum[20];charnum1[20];charch;inti=0;fp4=fopen(.\\train.rec,r+);if(!fp4){printf(Filecannotbeopened\n);exit(1);}do{rewind(fp4);printf(输入你要查询的终点与日期.\n);scanf(%s,num);scanf(%s,num1);while(!feof(fp4)){fread(&train[i],sizeof(structTRAIN),1,fp4);if((strcmp(num,train[i].toPlace)==0)&&(strcmp(num1,train[i].date)==0)){printf(%-4s%-12s%-8s%-10s%-10s%-8s%.2lf,train[i].trainNum,train[i].date,train[i].fromPlace,train[i].toPlace,train[i].inTime,train[i].outTime,train[i].price);printf(\n);}i++;}printf(continue(Y/N)(Ntoend)?);getchar();scanf(%c,&ch);}while(ch!='N');printf(\n);fclose(fp4);}voidCountToPlace(){FILE*fp5;charnum[20];charch;inti=0;intj=0;fp5=fopen(.
本文标题:火车票务管理系统(C语言)
链接地址:https://www.777doc.com/doc-6851944 .html