1、火车票务管理系统一、课题内容和要求设计目标:设计一个火车票务管理系统,用C语言实现。对该系统的要求如下:需求描述:1. 系统功能火车时刻信息录入。包括车次、日期、起点、终点、开车时间、到达时间、票价。 数据存入数据文件hchsk. dat或hchsk. txt中。(1) 火车时刻信息查询。按照车次查询按终点查询按起点查询按终点和日期查询(2) 统计按终点统计每日的车次数按起点统计每日的车次数2. 系统主界面应有以下功能选项录入火车时刻信息查询火车时刻信息统计火车车次退出注:建议用VC环境开发用户界面。结果形式:提交程序设计报告和可演示的系统软件二、需求分析系统主界面应有以下功能选项录入火车时刻
2、信息1. 查询火车时刻信息统计火车车次rewind(fp2);printfC输入你要查询的终点.n);scanf(s, num);while(!feof(fp2)fread(&traini, sizeof(struct TRAIN), 1, fp2);if (strcmp(nun), traini. toPlace)0)(printf (,z%4s%-12s%8s%-10s%-10s%-8s%. 21f,trainfi. trainNum, traini. date, traini. fromPlace, traini. toPlace,traini. inTime, traini. outT
3、ime, traini. price); printf(n);i+;)printf C,continue(Y/N) (N to end)?”);getchar ();scanf&ch); while (ch!=,;printf(n);fclose(fp2);void SearchFromPlace()(FILE *fp3;char num20:char ch;fp3二fopcn(. train. rcc, r+);if(!fp3)(printf (File can not be openedn,/);exit (1);do!rewind(fp3);printf (输入你要查询的起点.nz,);
4、scanf(s,num);while(!feof(fp3)fread(Straini, sizeof(struct TRAIN),1,fp3);if (strcmp(num, traini. fromPlace)=0)(printf(*%-4s%-12s%-8s%-10s%-10s%-8s%. 21f,traini. trainNum, traini. date, tra fromPlace, traini. toPlace,traini. inTime, trainEi. outTime, traini. price);printf (n);)i+;printf (z,continue(Y/
5、N) (N to end)?”);getchar ();scanf(c,&ch); while (ch!= N);printf(n);fclose(fp3);void SearchToPlaceAndDate()FILEFILE*fp4;charnum20;charnuml20;charch;int i=0;fp4=fopen(/,. train. rec”, r+);printf (,zFile can not be opencdn);exit (1);dorewind(fp4);printfC输入你要查询的终点与日期.n);while(!feof(fp4)fread(&traini, si
6、zeof(struct TRAIN), 1, fp4);if(strcmp(num, traini. toP1ace)=0)&(strcrop(numl, trainEi. date) =0)printf (,z%-4s%-12s%-8s%-10s%-10s%-8s%. 21f,z, trainfi. trainNum, traini. date, trainti. fromPlace, traini.toPlace,traini. inTime, traini. outTime, traini. price); printf(n);i+;printf(continue(Y/N) (N to
7、end)?”);getchar ();scanf(c,&ch);while(ch!=N);printf(n);fclose(fp4);void CountToPlaceOFILE *fp5;char num20;char ch;int i=0;int j=0;fp5=fopen(. train. rec, r+);if(!fp5)printf(File can not be openedn);exit (1);dorewind(fp5);printfC输入你(要统计的车次数的)终点.n); scanf (s, num);j=0;while(!feof(fp5)fread(Straini, si
8、zeof(struct TRAIN), 1,fp5); if (strcmp(num, traini. toPlace)=0)(j+;i+;printf C当日终点Ws的车次数:d,num, j);printf(n);printf(continue(Y/N) (N to end)?”);getchar ();scanf(%c, &ch); while (ch!=, N);fclose(fp5);void CountFromPlace()(FILE *fp6;char num20;char ch;int j=0;fp6=fopen(. train. rec,r+);if(!fp6)printf(
9、File can not be openedn);exit (1);)do(rewind(fp6);printfC输入你(要统计的车次数的)起点.n); scanf (s,num);j=0;while(!feof(fp6)(fread(&traini, sizeof(struct TRAIN), 1,fp6);if (strcmp(num, traini. fromPlace)0)(j+;i+;)printf (,z当日起点s的车次数:d, num, j);printf (n);printf(continue(Y/N) (N to end)?”);getchar ();scanf(c,&ch)
10、; while (ch != N);fclose(fp6);void Star ()(int i;for(i=0;i20;i+)printf(*);)printf(n);)四、测试数据及其结果分析(如图)1.火车时刻信息录入* 息息f面膏f统曹车5车车车f理火火火. j勇询计出5车蓍统退* 少 1 2 3 4鬲输入 gnter车次日期 起点 T001 2010-3-1 NANJING continue?V车次日期 起点 T002 2010-3-1 NANJING continue?车次白期庖,点 T003 2010-3-1 NANJING cont inue?V gnt”车次日期 起点 T00
11、4 2010-3-1 BEIJING cont inue? Rnter车次日期 起点 T005 2010-3-1 SHANGHAI鬲输入 gnter车次日期 起点 T001 2010-3-1 NANJING continue?V车次日期 起点 T002 2010-3-1 NANJING continue?车次白期庖,点 T003 2010-3-1 NANJING cont inue?V gnt”车次日期 起点 T004 2010-3-1 BEIJING cont inue? Rnter车次日期 起点 T005 2010-3-1 SHANGHAI终点开车时间到达时间票价SHANGHAI 7:30
12、8:20300终点开车时间到达时间票价SHANGHAI 10:3011:20 400终点开车时间到达时间票价SHANGHAI 15:3016:20 500终点NANJING开车时间到达时间票价9:5011:00 500终点开车时间到达时间票价TIANJING 19:0020:20 6502. 火车时刻信息查询。(1) 按照车次查询火车时刻信息查询1.2.援终钱而甘丽查询.5 .退出查找的车次号.T001T0012010-3-1 NANJING SHANGHAI7:308:20300.00cont inueT002T0022010-3-1 NANJING SHANGHAI cont inue?V
13、 输入你要查找的车次号.T003T0032010-3-1 NANJING SHANGHAI continue?V 输入你要查找的车次号.T004T0042010-3-1 BEIJING NANJING cont inue?V 输入你要查找的车次号T005T0052010-3-1 SHANGHAITIANJING10:3015:309:5019:0011:20400.0016:20500.0011:00500.0020:20650.00按终点查询火车时刻信息查询 L.铤次查询.侦安练点查询.).波超点查询.I成终点和日期查询.i.退出.10012010-3-1NANJING SHANGHAI7:
14、308:20300.0010022010-3-1NANJING SHANGHAI10:3011:20400.00F0032010-3-1NANJING SHANGHAI15:3016:20500.00cont inue?V腕入你要查询的终点.NANJING10042010-3-1BEIJING NANJING9:5011:00500.00continueTIANJING10052010-3-1 SHANGHAITIANJINGcontinue?N崭乂你要查询的终点SHANGHAI19:0020:20650.00返回主果面吗?NANJINGT0012010-3-1NANJINGSHANGHAIT
15、0022010-3-1NANJINGSHANGHAIT0032010-3-1NANJINGSHANGHAI7:30 10:30 15:308:2011:2016:20300.00400.00500.00continue? 输入你要查询的起点 BEIJINGT0042010-3-1BEIJING NANJINGcontinueSHANGHAI9:5011:00500.00T0052010-3-1SHANGHAITIANJINGcont inueSHANGHAI 2010-3-1T0012010-3-1NANJINGSHANGHAIT0022010-3-1NANJINGSHANGHAIT00320
16、10-3-1NANJINGSHANGHAI7:3010:3015:308:2011:2016:20300.00400.00500.00cont inue? 输入你要查询的终点与日期. NANJING 2010-3-1T0042010-3-1BEIJING NANJINGcont inueTIANJING 2010-3-19:5011:00500.00T0052010-3-1SHANGHAITIANJINGcontinueCV/NXN to end?19:0020:20650.00统计(1)按终点统计每日的车次数火车车次统讦系统SHANGHAI当日终点SHANGHAI的车次数:3 cont in
17、ueNANJING当日终点NANJING的车次数continue?V输入你要统计的车次数的终点.TIANJING当日终点TIANJING的车次数H continue?(2)按起点统计每日的车次数输乂你要统计的车次数的起点.XXXklAM IT HP当日起点NANJING的车次数:3 continueBEIJING含日盘,板BEIJING的车次数cont inueSHANGHAI含日起出SHANGHAI的车次数conti.nueY/NN to end?一退出。4.退出火车时刻信息录入。包括车次、日期、起点、终点、开车时间、到达时间、票价。 数据存入数据文件hchsk. dat或hchsk. tx
18、t中。(2)火车时刻信息查询。按照车次查询按终点查询按起点查询按终点和日期查询统计按终点统计每日的车次数按起点统计每日的车次数二、概要设计void SearchTrainNumO ;/按照车次查询void SearchToPlace (): 按终点查询void SearchFromPlace (); 按起点查询void SearchToPlaceAndDate (); 按终点和日期查询void CountToPlace ();/按终点统计每日的车次数void CountFromPlace (); 按起点统计每日的车次数三、详细设计程序的源代码与注释#include#include#includ
19、evoid SearchTrainNumO ;void SearchToPlace();void SearchFromPlace0;自心自心 面简简 次 统曹专 u 理火火火 勇询计出 车善统退 w.kl21314|jWA=4作者:B09020415S云鹏MMMMMMMMMMMMMMMMMMMM 匚Press any key to continue五、调试过程中的问题编译过程中由于MicrosoftVisualStudioC+6. 0编译器的原因。直接给结构体double赋值会出现问题。在金老师的指导和帮助下: 程序改为如下:struct TRAINchartrainNum10;chardat
20、e30;charfromPlace20;chartoPlace20;charinTime30;charoutTime30;double price;;int main ()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;voidSearchToPlaceA
21、ndDate 0;voidCountToPlaceO ;voidCountFromPlace();voidStar ();struct TRAINchartrainNum101;chardate30;charfromPlace20;chartoPlace20;charinTime30;charoutTime30;double price;;struct TRAIN train30;int main()int request: char ch=Y;int i=0;double myprice;FILE *fp;repeat:Star ();printfC火车管理系统界面n);printf (,z
22、l.录入火车时刻信息.n);printf (z/2.查询火车时刻信息.n);printf C3.统计火车车次.n);printf C4.退出.n);Star ();printf(n);printfC 请输入:);scanf&request);switch (request)/利用 case 分支结构case 1:fp=fopcn(. train. rcc,wb); /利用文件与流if(!fp)(printf (File can not be openedn,/);exit (1);doprintf (Enter车次日期 起点 终点开车时间到达时间 票价n );scanf (%s%s%s%s%s
23、%s%lf,traini. trainNum, traini. date, traini. fromPlace ,traini. toPlace, train。, inTime, traini. outTime, &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);printfC返回主界面吗?(Y返回);getchar (
24、);scanf(%c, &ch);if(ch= Y)printf(nn);goto repeat;)break;case 2: printf(nn);printfC火车时刻信息查询火车车次统计系统); scanfnum);while(!feof(fpl)fread(&traini, sizeof(struct TRAIN), 1,fpl); if (strcmp(num, traini. trainNum) =0)printf (/?%-4s%-12s%-8s%-10s%-10s%-8s%. trainfi. trainNum, traini. date, trainti. fromPlace
25、, 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 (rT);fclose(fpl);void SearchToPlace() (FILE *fp2;char num20;char ch:int i=0;fp2=fopen(. train. rcc, r+);if(!fp2)printf (File can not be openedn,/);exit (1);do