《火车票务管理系统(C语言)(共21页).doc》由会员分享,可在线阅读,更多相关《火车票务管理系统(C语言)(共21页).doc(21页珍藏版)》请在taowenge.com淘文阁网|工程机械CAD图纸|机械工程制图|CAD装配图下载|SolidWorks_CaTia_CAD_UG_PROE_设计图分享下载上搜索。
1、精选优质文档-倾情为你奉上火车票务管理系统一、 课题内容和要求设计目标:设计一个火车票务管理系统,用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();/按终点和日期
3、查询void 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;c
4、har 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);printf(请输入
5、:);scanf(%d,&request);switch(request) /利用case分支结构case 1: fp=fopen(.train.rec,wb); /利用文件与流 if(!fp) printf(File can not be openedn); exit(1); doprintf(Enter车次 日期 起点 终点 开车时间 到达时间 票价n );scanf(%s%s%s%s%s%s%lf,traini.trainNum,traini.date,traini.fromPlace ,traini.toPlace,traini.inTime,traini.outTime,&mypri
6、ce);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(火车时刻信息查询火车车次统计系统);scanf(%s,num);whi
7、le(!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)?); getchar(); scanf(%c,&
8、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(File can not be openedn);exit(1); dorewind(fp2);printf(输入你要查询的终点.n);scanf(%s,num);while(!feof(fp2)fread(&traini,sizeof(struct TRAIN),1,fp2);if(strcmp(num,traini.to
9、Place)=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);void SearchFromPlace()FILE *fp3;char num
10、20;char ch;int i=0;fp3=fopen(.train.rec,r+); if(!fp3)printf(File can not be openedn);exit(1); dorewind(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%-10s%-10s%-8s%.2lf,traini.trainNum,traini.da
11、te,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;char ch;int i=0;fp4=fopen(.train.rec,r+); if(!fp4)pri
12、ntf(File can not be openedn);exit(1); dorewind(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%-10s%-10s%-8s%.2lf,traini.trainNum,traini.date,traini.fr
13、omPlace,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;int j=0;fp5=fopen(.train.rec,r+); if(!fp5)printf(File can not be open
14、edn);exit(1); dorewind(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)(N to end)?); getchar();scanf(%c,&ch);while(ch!=N);fclose(fp5);void Cou
15、ntFromPlace()FILE *fp6;char num20;char ch;int i=0; int j=0;fp6=fopen(.train.rec,r+); if(!fp6)printf(File can not be openedn);exit(1); dorewind(fp6);printf(输入你(要统计的车次数的)起点.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(当
16、日起点%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)按照车次查询(2) 按终点查询(3) 按起点查询(4)按终点和日期查询3.统计(1)按终点统计每日的车次数(2)按起点统计每日的车次数4.退出。五、调试过程中的问题编译过程中由于Micr
17、osoftVisualStudioC+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; 专心-专注-专业