1、火车票务管理系统C语言火车票务管理系统一、课题内容和要求设计目标:设计一个火车票务管理系统,用C语言实现。对该系统的要求如下:需求描述:1.系统功能(1)火车时刻信息录入。包括车次、日期、起点、终点、开车时间、到达时间、票价。数据存入数据文件hchsk.dat或hchsk.txt中。(2)火车时刻信息查询。按照车次查询按终点查询按起点查询按终点和日期查询 (3)统计 按终点统计每日的车次数 按起点统计每日的车次数2. 系统主界面应有以下功能选项录入火车时刻信息查询火车时刻信息统计火车车次退出注:建议用VC环境开发用户界面。结果形式:提交程序设计报告和可演示的系统软件二、需求分析系统主界面应有以
2、下功能选项1录入火车时刻信息2查询火车时刻信息3统计火车车次4.退出 (1)火车时刻信息录入。包括车次、日期、起点、终点、开车时间、到达时间、票价。数据存入数据文件hchsk.dat或hchsk.txt中。(2)火车时刻信息查询。按照车次查询按终点查询按起点查询按终点和日期查询 (3)统计 按终点统计每日的车次数 按起点统计每日的车次数二、概要设计 void SearchTrainNum();/按照车次查询void SearchToPlace();/按终点查询void SearchFromPlace();/按起点查询void SearchToPlaceAndDate();/按终点和日期查询vo
3、id CountToPlace();/按终点统计每日的车次数void CountFromPlace();/按起点统计每日的车次数三、详细设计 程序的源代码与注释 #include#include#includevoid SearchTrainNum();void SearchToPlace();void SearchFromPlace();void SearchToPlaceAndDate();void CountToPlace();void CountFromPlace();void Star();struct TRAIN char trainNum10; char date30; char
4、 fromPlace20; char toPlace20; char inTime30; char outTime30; double price;struct TRAIN train30;int main() int request; char ch=Y; int i=0; double myprice; FILE *fp; repeat: Star(); printf(火车管理系统界面n); printf(1.录入火车时刻信息.n); printf(2.查询火车时刻信息.n); printf(3.统计火车车次.n); printf(4.退出.n); Star(); printf(n); p
5、rintf(请输入:); scanf(%d,&request); switch(request) /利用case分支结构 case 1: fp=fopen(.train.rec,wb); /利用文件与流 if(!fp) printf( not be openedn); exit(1); do printf(Enter车次 日期 起点 终点 开车时间 到达时间 票价n ); scanf(%s%s%s%s%s%s%lf,traini.trainNum,traini.date,traini.fromPlace ,traini.toPlace,traini.inTime,traini.outTime,
6、&myprice); traini.price=myprice; fwrite(&traini,sizeof(struct TRAIN),1,fp); i+; printf(continue(Y/N)(N to end)?); getchar(); scanf(%c,&ch); while(ch!=N); fclose(fp); printf(返回主界面吗?(Y返回); getchar(); scanf(%c,&ch); if(ch=Y) printf(nn); goto repeat; break; case 2: printf(nn); printf(火车时刻信息查询火车车次统计系统);
7、scanf(%s,num); while(!feof(fp1) fread(&traini,sizeof(struct TRAIN),1,fp1); if(strcmp(num,traini.trainNum)=0) printf(%-4s%-12s%-8s%-10s%-10s%-8s%.2lf,traini.trainNum,traini.date,traini.fromPlace,traini.toPlace, traini.inTime,traini.outTime,traini.price); printf(n); i+; printf(continue(Y/N)(N to end)?
8、); getchar(); scanf(%c,&ch); while(ch!=N); printf(n); fclose(fp1);void SearchToPlace() FILE *fp2; char num20; char ch; int i=0; fp2=fopen(.train.rec,r+); if(!fp2) printf( not be openedn); exit(1); do rewind(fp2); printf(输入你要查询的终点.n); scanf(%s,num); while(!feof(fp2) fread(&traini,sizeof(struct TRAIN)
9、,1,fp2); if(strcmp(num,traini.toPlace)=0) printf(%-4s%-12s%-8s%-10s%-10s%-8s%.2lf,traini.trainNum,traini.date,traini.fromPlace,traini.toPlace, traini.inTime,traini.outTime,traini.price); printf(n); i+; printf(continue(Y/N)(N to end)?); getchar(); scanf(%c,&ch); while(ch!=N); printf(n); fclose(fp2);v
10、oid SearchFromPlace() FILE *fp3; char num20; char ch; int i=0; fp3=fopen(.train.rec,r+); if(!fp3) printf( not be openedn); exit(1); do rewind(fp3); printf(输入你要查询的起点.n); scanf(%s,num); while(!feof(fp3) fread(&traini,sizeof(struct TRAIN),1,fp3); if(strcmp(num,traini.fromPlace)=0) printf(%-4s%-12s%-8s%
11、-10s%-10s%-8s%.2lf,traini.trainNum,traini.date,traini.fromPlace,traini.toPlace, traini.inTime,traini.outTime,traini.price); printf(n); i+; printf(continue(Y/N)(N to end)?); getchar(); scanf(%c,&ch); while(ch!=N); printf(n); fclose(fp3);void SearchToPlaceAndDate() FILE *fp4; char num20; char num120;
12、char ch; int i=0; fp4=fopen(.train.rec,r+); if(!fp4) printf( not be openedn); exit(1); do rewind(fp4); printf(输入你要查询的终点与日期.n); scanf(%s,num); scanf(%s,num1); while(!feof(fp4) fread(&traini,sizeof(struct TRAIN),1,fp4); if(strcmp(num,traini.toPlace)=0)&(strcmp(num1,traini.date)=0) printf(%-4s%-12s%-8s
13、%-10s%-10s%-8s%.2lf,traini.trainNum,traini.date,traini.fromPlace,traini.toPlace, traini.inTime,traini.outTime,traini.price); printf(n); i+; printf(continue(Y/N)(N to end)?); getchar(); scanf(%c,&ch); while(ch!=N); printf(n); fclose(fp4);void CountToPlace() FILE *fp5; char num20; char ch; int i=0; in
14、t j=0; fp5=fopen(.train.rec,r+); if(!fp5) printf( not be openedn); exit(1); do rewind(fp5); printf(输入你(要统计的车次数的)终点.n); scanf(%s,num); j=0; while(!feof(fp5) fread(&traini,sizeof(struct TRAIN),1,fp5); if(strcmp(num,traini.toPlace)=0) j+; i+; printf(当日终点%s的车次数:%d,num,j); printf(n); printf(continue(Y/N)
15、(N to end)?); getchar(); scanf(%c,&ch); while(ch!=N); fclose(fp5);void CountFromPlace() FILE *fp6; char num20; char ch; int i=0; int j=0; fp6=fopen(.train.rec,r+); if(!fp6) printf( not be openedn); exit(1); do rewind(fp6); printf(输入你(要统计的车次数的)起点.n); scanf(%s,num); j=0; while(!feof(fp6) fread(&traini
16、,sizeof(struct TRAIN),1,fp6); if(strcmp(num,traini.fromPlace)=0) j+; i+; printf(当日起点%s的车次数:%d,num,j); printf(n); printf(continue(Y/N)(N to end)?); getchar(); scanf(%c,&ch); while(ch!=N); fclose(fp6);void Star() int i; for(i=0;i20;i+) printf(*); printf(n);四、测试数据及其结果分析(如图)1.火车时刻信息录入2. 火车时刻信息查询。(1)按照车次
17、查询(2) 按终点查询(3) 按起点查询(4)按终点和日期查询3.统计(1)按终点统计每日的车次数(2)按起点统计每日的车次数4.退出。五、调试过程中的问题编译过程中由于MicrosoftVisualStudioC+6.0编译器的原因。直接给结构体double赋值会出现问题。在金老师的指导和帮助下:程序改为如下:struct TRAIN char trainNum10; char date30; char fromPlace20; char toPlace20; char inTime30; char outTime30; double price;int main() int request; char ch=Y; int i=0; double myprice; FILE *fp;scanf(%s%s%s%s%s%s%lf,traini.trainNum,traini.date,traini.fromPlace, traini.toPlace,traini.inTime,traini.outTime,&myprice);traini.price=myprice;
copyright@ 2008-2022 冰豆网网站版权所有
经营许可证编号:鄂ICP备2022015515号-1