收藏 分销(赏)

C语言程序设计火车订票系统程序设计报告.pdf

上传人:人****来 文档编号:3247817 上传时间:2024-06-26 格式:PDF 页数:34 大小:454.41KB
下载 相关 举报
C语言程序设计火车订票系统程序设计报告.pdf_第1页
第1页 / 共34页
C语言程序设计火车订票系统程序设计报告.pdf_第2页
第2页 / 共34页
C语言程序设计火车订票系统程序设计报告.pdf_第3页
第3页 / 共34页
C语言程序设计火车订票系统程序设计报告.pdf_第4页
第4页 / 共34页
C语言程序设计火车订票系统程序设计报告.pdf_第5页
第5页 / 共34页
点击查看更多>>
资源描述

1、 设计题目:火车订票系统设计 专业:电子信息工程 班级:09 级 3 班 姓名:学号:目 录 一 总体设计(包含几大功能模块).1 二 详细设计(各功能模块的具体实现算法流程图).2 三 调试分析(包含各模块的测试用例,及测试结果).3 3.1 源程序.6 3.2 调试与测试.31 四 总结.33 一 总体设计(包含几大功能模块)1.Insert a train information(插入火车信息)2.inquire a train jinformation(查询火车信息)3.Book a train ticket(订票)4.Update the train information(更新火车

2、信息)5.Advice to you about the train(建议)6.Save information to file(储存信息归档)7.Quit the system(退出系统)二、详细设计(各功能模块的具体实现算法流程图)2.1 各函数的功能和实现 1.Insert a train information(插入火车信息):输入包括火车班次,最终目地,始发站,火车到站时间,车票价格,所定票号。可用函数 void input 来实现此操作 2.inquire a train jinformation(查询火车信息):没有任何记录 3.Book a train ticket(订票):输

3、入你想要去的城市 4.Update the train information(更新火车信息):可用 void find()来实现 5.Advice to you about the train(关于火车对你的建议)6.Save information to file(储存信息归档)7.Quit the system(退出系统):可用一个函数 exit()来实现,首先将信息保存到文件中,释放动态创建的内存空间,再退出此程序。流程图 详见A4纸上手绘 三 调试分析(包含各模块的测试用例,及测试结果)3.1 源程序#include#include#include#include int shoud

4、save=0;int count1=0,count2=0,mark=0,mark1=0;/*定义存储火车信息的结构体*/struct train char num10;/*列车号*/char city10;/*目的城市*/char takeoffTime10;/*发车时间*/char receiveTime10;/*到达时间*/int price;/*票价*/int bookNum;/*票数*/;/*订票人的信息*/struct man char num10;/*ID*/char name10;/*姓名*/int bookNum;/*需求的票数*/;/*定义火车信息链表的结点结构*/typed

5、ef struct node struct train data;struct node*next;Node,*Link;/*定义订票人链表的结点结构*/typedef struct people struct man data;struct people*next;bookMan,*bookManLink;/*初始界面*/void printInterface()puts(*);puts(*Welcome to use the system of booking tickets *);puts(*);puts(*You can choose the operation:*);puts(*1:

6、Insert a train information *);puts(*2:Inquire a train information *);puts(*3:Book a train ticket *);puts(*4:Update the train information *);puts(*5:Advice to you about the train *);puts(*6:save information to file *);puts(*7:quit the system *);puts(*);/*添加一个火车信息*/void InsertTraininfo(Link linkhead)s

7、truct node*p,*r,*s;char num10;r=linkhead;s=linkhead-next;while(r-next!=NULL)r=r-next;while(1)printf(please input the number of the train(0-return);scanf(%s,num);if(strcmp(num,0)=0)break;/*判断是否已经存在*/while(s)if(strcmp(s-data.num,num)=0)printf(the train%shas been born!n,num);return;s=s-next;p=(struct n

8、ode*)malloc(sizeof(struct node);strcpy(p-data.num,num);printf(Input the city where the train will reach:);scanf(%s,p-data.city);printf(Input the time which the train take off:);scanf(%s,p-data.takeoffTime);printf(Input the time which the train receive:);scanf(%s,&p-data.receiveTime);printf(Input the

9、 price of ticket:);scanf(%d,&p-data.price);printf(Input the number of booked tickets:);scanf(%d,&p-data.bookNum);p-next=NULL;r-next=p;r=p;shoudsave=1;/*打印火车票信息*/void printTrainInfo(struct node*p)puts(nThe following is the record you want:);printf(number of train:%sn,p-data.num);printf(city the train

10、 will reach:%sn,p-data.city);printf(the time the train take off:%snthe time the train reach:%sn,p-data.takeoffTime,p-data.receiveTime);printf(the price of the ticket:%dn,p-data.price);printf(the number of booked tickets:%dn,p-data.bookNum);struct node*Locate1(Link l,char findmess,char numorcity)Node

11、*r;if(strcmp(numorcity,num)=0)r=l-next;while(r)if(strcmp(r-data.num,findmess)=0)return r;r=r-next;else if(strcmp(numorcity,city)=0)r=l-next;while(r)if(strcmp(r-data.city,findmess)=0)return r;r=r-next;return 0;/*查询火车信息*/void QueryTrain(Link l)Node*p;int sel;char str15,str210;if(!l-next)printf(There i

12、s not any record!);return;printf(Choose the way:n1:according to the number of train;n2:according to the city:n);scanf(%d,&sel);if(sel=1)printf(Input the the number of train:);scanf(%s,str1);p=Locate1(l,str1,num);if(p)printTrainInfo(p);else mark1=1;printf(nthe file cant be found!);else if(sel=2)print

13、f(Input the city:);scanf(%s,str2);p=Locate1(l,str2,city);if(p)printTrainInfo(p);else mark1=1;printf(nthe file cant be found!);/*订票子模块*/void BookTicket(Link l,bookManLink k)Node*r10,*p;char ch,dem;bookMan*v,*h;int i=0,t=0;char str10,str110,str210;v=k;while(v-next!=NULL)v=v-next;printf(Input the city

14、you want to go:);scanf(%s,&str);p=l-next;while(p!=NULL)if(strcmp(p-data.city,str)=0)ri=p;i+;p=p-next;printf(nnthe number of record have%dn,i);for(t=0;ti;t+)printTrainInfo(rt);if(i=0)printf(ntttSorry!Cant find the train for you!n);else printf(ndo you want to book it?n);scanf(%d,&ch);if(ch=1)h=(bookMa

15、n*)malloc(sizeof(bookMan);printf(Input your name:);scanf(%s,&str1);strcpy(h-data.name,str1);printf(Input your id:);scanf(%s,&str2);strcpy(h-data.num,str2);printf(Input your bookNum:);scanf(%d,&dem);h-data.bookNum=dem;h-next=NULL;v-next=h;v=h;printf(nLucky!you have booked a ticket!);getch();shoudsave

16、=1;bookMan*Locate2(bookManLink k,char findmess)bookMan*r;r=k-next;while(r)if(strcmp(r-data.num,findmess)=0)mark=1;return r;r=r-next;return 0;/*修改火车信息*/void UpdateInfo(Link l)Node*p;char findmess20,ch;if(!l-next)printf(nthere isnt record for you to modify!n);return;else QueryTrain(l);if(mark1=0)print

17、f(nDo you want to modify it?n);getchar();scanf(%c,&ch);if(ch=y);printf(nInput the number of the train:);scanf(%s,findmess);p=Locate1(l,findmess,num);if(p)printf(Input new number of train:);scanf(%s,&p-data.num);printf(Input new city the train will reach:);scanf(%s,&p-data.city);printf(Input new time

18、 the train take off);scanf(%s,&p-data.takeoffTime);printf(Input new time the train reach:);scanf(%s,&p-data.receiveTime);printf(Input new price of the ticket:);scanf(%d,&p-data.price);printf(Input new number of people who have booked ticket:);scanf(%d,&p-data.bookNum);printf(nmodifying record is suc

19、essful!n);shoudsave=1;else printf(tttcant find the record!);else mark1=0;/*系统给用户的提示信息*/void AdvicedTrains(Link l)Node*r;char str10;int mar=0;r=l-next;printf(Iuput the city you want to go:);scanf(%s,str);while(r)if(strcmp(r-data.city,str)=0&r-data.bookNumnext;if(mar=0)printf(ntttyou cant book any tic

20、ket now!n);/*保存火车信息*/void SaveTrainInfo(Link l)FILE*fp;Node*p;int count=0,flag=1;fp=fopen(c:train.txt,wb);if(fp=NULL)printf(the file cant be opened!);return;p=l-next;while(p)if(fwrite(p,sizeof(Node),1,fp)=1)p=p-next;count+;else flag=0;break;if(flag)printf(the number of the record which have been sav

21、ed is%dn,count);shoudsave=0;fclose(fp);/*保存订票人的信息*/void SaveBookmanInfo(bookManLink k)FILE*fp;bookMan*p;int count=0,flag=1;fp=fopen(c:man.txt,wb);if(fp=NULL)printf(the file cant be opened!);return;p=k-next;while(p)if(fwrite(p,sizeof(bookMan),1,fp)=1)p=p-next;count+;else flag=0;break;if(flag)printf(t

22、he number of the record which have been saved is%dn,count);shoudsave=0;fclose(fp);int main()FILE*fp1,*fp2;Node*p,*r;char ch1,ch2;Link l;bookManLink k;bookMan*t,*h;int sel;l=(Node*)malloc(sizeof(Node);l-next=NULL;r=l;k=(bookMan*)malloc(sizeof(bookMan);k-next=NULL;h=k;fp1=fopen(c:train.txt,ab+);if(fp1

23、=NULL)printf(cant open the file!);return 0;while(!feof(fp1)p=(Node*)malloc(sizeof(Node);if(fread(p,sizeof(Node),1,fp1)=1)p-next=NULL;r-next=p;r=p;count1+;fclose(fp1);fp2=fopen(c:man.txt,ab+);if(fp2=NULL)printf(cant open the file!);return 0;while(!feof(fp2)t=(bookMan*)malloc(sizeof(bookMan);if(fread(

24、t,sizeof(bookMan),1,fp2)=1)t-next=NULL;h-next=t;h=t;count2+;fclose(fp2);while(1)clrscr();printInterface();printf(please choose the operation:);scanf(%d,&sel);clrscr();if(sel=8)if(shoudsave=1)getchar();printf(nthe file have been changed!do you want to save it(y/n)?n);scanf(%c,&ch1);if(ch1=y|ch1=Y)Sav

25、eBookmanInfo(k);SaveTrainInfo(l);printf(nThank you!You are welcome toon);break;switch(sel)case 1:InsertTraininfo(l);break;case 2:QueryTrain(l);break;case 3:BookTicket(l,k);break;case 4:UpdateInfo(l);break;case 5:AdvicedTrains(l);break;case 6:SaveTrainInfo(l);SaveBookmanInfo(k);break;case 7:return 0;

26、printf(nplease press any key to continue.);getch();return 0;3.2 调试与测试 主要程序运行结果:运行开始 选择 1 输入信息:选择 2 查询信息 选择 3 订票 选择 4 没用 选择 5 对你的建议 选择 7 退出系统 3.心得体会 通过这次课程设计,增加了我对软件技术的了解,虽然还不明确软件技术包含的具体内容,但从学习 C 语言这门课程开始,已发现程序设计的好处,他对我们数学的学习也有很大的帮助。在学习 C 语言的过程中也学到和巩固了许多计算机应用基础知识,对计算机的机体也有了一个较为详细的了解。在具体操作中对这学期所学的 C 语

27、言的理论知识得到巩固加强,达到实训的目的,也发现自己的不足之处,为我问以后的 c 语言学习奠定了基础,同时体会到 C 语言具有的语句简洁,使用灵活,执行效率高等特点。发现上机操作的重要作用,特别是对数组和循环有了深刻的理解。通过实际操作,学会 C 语言程序编程的基本步骤、基本方法,开发了自己的逻辑思维能力,培养了分析问题、解决问题的能力。4.总结 由于本课题中的许多知识点都没有学过都要靠自己到课外的资料中去查找。在用的时候难免出现这样那样的错误。如开始设计出来的菜单不是预想的那样,而是总个窗中出现混乱。解决的这个问题的办法是调整。最后还是老师帮我帮我们找到了问题的所在。一个系统的菜单和提示信息

28、非常重要。如果没有这些用户根本不知道怎么用你设计的这个系统。在设计的调试过程中也无法顺利的完成调试工作。有了一个清晰简单的菜单和一些提示信息这后,调试过程完成的非常顺利。回顾起此次课程设计,至今我仍感慨颇多,的确,从拿到题目到完成整个编程,从理论到实践,在整整半个月的日子里,可以学到很多很多的东西,同时不仅可以巩固了以前所学过的知识,而且学到了很多在书本上所没有学到过的知识。通过这次课程设计使我懂得了理论与实际相结合是很重要的,只有理论知识是远远不够的,只有把所学的理论知识与实践相结合起来,从理论中得出结论,才能真正为社会服务,从而提高自己的实际动手能力和独立思考的能力。在设计的过程中遇到问题,可以说得是困难重重,这毕竟第一次做的,难免会遇到过各种各样的问题,同时在设计的过程中发现了自己的不足之处,对以前所学过的知识理解得不够深刻,掌握得不够牢固,比如说结构体通过这次课程设计之后,一定把以前所学过的知识本次课程设计结束了,对于我的影响很大。我通过这次实践学到了许多知识。学到了设计一个简单的系统。要注意哪些方面。也使我知道自己哪些方面做得还不够。但我出总结出了一点点的经验如下:1、要对系统的功能和要求做出详细的分析,并合理分解任务。2、把分解出来的子任务,做给一个相对独立的模块。3、在设计一个模块之前,要简单构想一下总界面的显视情况。4、针对构想出来的界面进行程序的编写。

展开阅读全文
相似文档                                   自信AI助手自信AI助手
猜你喜欢                                   自信AI导航自信AI导航
搜索标签

当前位置:首页 > 通信科技 > 开发语言

移动网页_全站_页脚广告1

关于我们      便捷服务       自信AI       AI导航        获赠5币

©2010-2024 宁波自信网络信息技术有限公司  版权所有

客服电话:4008-655-100  投诉/维权电话:4009-655-100

gongan.png浙公网安备33021202000488号   

icp.png浙ICP备2021020529号-1  |  浙B2-20240490  

关注我们 :gzh.png    weibo.png    LOFTER.png 

客服