C语言程序设计-火车订票系统程序设计报告_第1页
C语言程序设计-火车订票系统程序设计报告_第2页
C语言程序设计-火车订票系统程序设计报告_第3页
C语言程序设计-火车订票系统程序设计报告_第4页
C语言程序设计-火车订票系统程序设计报告_第5页
已阅读5页,还剩30页未读 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

辽宁师范大学设计题目火车订票系设计专:

电信工班:09级3班姓:

张学:word可自由复制编辑

录一总体设计(包含几大功能模块)二详细设计(各功能模块的具体实现算法——流程图......................................................................................2三调试分(包含各模块的测试用例及测试结果)..............................................................................................33.1程序.......................................................................63.2试与测试.............................................................四总结...............................................................................

word可自由复制编辑

总体设计(包含几大功能模块)1.Insertatraininformation(入火车息)2.inquireatrainjinformation(询火车息)3.Bookatrain订票4.Updatethetrain更新火信)5.Advicetoyouaboutthe(建议6.Saveinformationtofile(储存信归档)7.Quitthesystem(出系统)word可自由复制编辑

二、详细设计(各功能模块的具体实现算法——流程图)2.1各函数的能和实现1.Insertatraininformation(入火车信息:输入包火车班次,最终地,始发站火车到站时,车票价,所定票号。用函数voidinput实现此操作2.inquiretrain查询火车息):没有任何记录3.Bookatrainticket(订)输入你想要的城市4.Updatethetrain更新火车信息):可用find()来实现5.Advicetoyouabouttrain(于火车对的建议)6.Saveinformationto储存信归档7.Quitsystem(出系统可用一个函数)来实现,首先将信息保存到文件中放动态创建的内存空间退出此程序。word可自由复制编辑

流程图详见A4纸上绘word可自由复制编辑

三调试分析(包含各模块的测试用例,及测试结果)3.1源程序#include<conio.h>#include<stdio.h>#include<stdlib.h>#include<string.h>intshoudsave=0;intcount1=0,count2=0,mark=0,mark1=0;/*定义存储火车信的结构体*/structtrain{charnum[10];/*列车*/charcity[10];/*的城市/chartakeoffTime[10];/*车时间*/charreceiveTime[10];/*达时间*/intprice;/*票价/intbookNum;/*数*/};word可自由复制编辑

/*订票人的信*/structman{charnum[10];/*ID*/charname[10];/*名*/intbookNum;/*求的票数/};/*定义火车信息链的结点结构/typedefstructnode{structtraindata;structnode*next;}Node,*Link;/*定义订票人链表结点结构*/typedefstructpeople{structmandata;structpeople*next;}bookMan,*bookManLink;word可自由复制编辑

/*初始界面/voidprintInterface(){puts("********************************************************");puts("*Welcometousethesystemofbookingtickets*");puts("********************************************************");puts("*Youcanchoosetheoperation:*");puts("*1:Insertatraininformation*");puts("*2:Inquireatraininformation*");puts("*3:Bookatrainticket*");puts("*4:Updatethetraininformation*");puts("*5:Advicetoyouaboutthetrain*");puts("*6:saveinformationtofile*");puts("*7:quitthesystem*");puts("********************************************************");}/*添加一个火车信*/voidInsertTraininfo(Linklinkhead){word可自由复制编辑

structnode*p,*r,*s;charnum[10];r=linkhead;s=linkhead->next;while(r->next!=NULL)r=r->next;while(1){printf("pleaseinputthenumberofthetrain(0-return)");scanf("%s",num);if(strcmp(num,"0")==0)break;/*断是否已经存在/while(s){if(strcmp(s->data.num,num)==0){printf("thetrain'%s'hasbeenborn!\n",num);return;word可自由复制编辑

}s=s->next;}p=(structnode*)malloc(sizeof(structnode));strcpy(p->data.num,num);printf("Inputthecitywherethetrainwillreach:");scanf("%s",p->data.city);printf("Inputthetimewhichthetraintakeoff:");scanf("%s",p->data.takeoffTime);printf("Inputthetimewhichthetrainreceive:");scanf("%s",&p->data.receiveTime);printf("Inputthepriceofticket:");scanf("%d",&p->data.price);printf("Inputthenumberofbookedtickets:");scanf("%d",&p->data.bookNum);p->next=NULL;r->next=p;r=p;shoudsave=1;word可自由复制编辑

}}/*打印火车票信息/voidprintTrainInfo(structnode*p){puts("\nThefollowingistherecordyouwant:");printf(">>numberoftrain:%s\n",p->data.num);printf(">>citythetrainwillreach:%s\n",p->data.city);printf(">>thetimethetraintakeoff:%s\nthetimethetrainreach:%s\n",p->data.takeoffTime,p->data.receiveTime);printf(">>thepriceoftheticket:%d\n",p->data.price);printf(">>thenumberofbookedtickets:%d\n",p->data.bookNum);}structnode*Locate1(Linkl,charfindmess[],charnumorcity[]){Node*r;if(strcmp(numorcity,"num")==0){word可自由复制编辑

r=l->next;while(r){if(strcmp(r->data.num,findmess)==0)returnr;r=r->next;}}elseif(strcmp(numorcity,"city")==0){r=l->next;while(r){if(strcmp(r->data.city,findmess)==0)returnr;r=r->next;}}return0;word可自由复制编辑

}/*查询火车信*/voidQueryTrain(Linkl){Node*p;intsel;charstr1[5],str2[10];if(!l->next){printf("Thereisnotanyrecord!");return;}printf("Choosetheway:\n>>1:accordingtothenumberoftrain;\n>>2:accordingtothecity:\n");scanf("%d",&sel);if(sel==1){word可自由复制编辑

printf("Inputthethenumberoftrain:");scanf("%s",str1);p=Locate1(l,str1,"num");if(p){printTrainInfo(p);}else{mark1=1;printf("\nthefilecan'tbefound!");}}elseif(sel==2){printf("Inputthecity:");scanf("%s",str2);p=Locate1(l,str2,"city");if(p)word可自由复制编辑

{printTrainInfo(p);}else{mark1=1;printf("\nthefilecan'tbefound!");}}}/*订票子模块/voidBookTicket(Linkl,bookManLinkk){Node*r[10],*p;charch,dem;bookMan*v,*h;inti=0,t=0;charstr[10],str1[10],str2[10];word可自由复制编辑

v=k;while(v->next!=NULL)v=v->next;printf("Inputthecityyouwanttogo:");scanf("%s",&str);p=l->next;while(p!=NULL){if(strcmp(p->data.city,str)==0){r[i]=p;i++;}p=p->next;}printf("\n\nthenumberofrecordhave%d\n",i);for(t=0;t<i;t++)printTrainInfo(r[t]);if(i==0)word可自由复制编辑

printf("\n\t\t\tSorry!Can'tfindthetrainforyou!\n");else{printf("\ndoyouwanttobookit?<1/0>\n");scanf("%d",&ch);if(ch==1){h=(bookMan*)malloc(sizeof(bookMan));printf("Inputyourname:");scanf("%s",&str1);strcpy(h->,str1);printf("Inputyourid:");scanf("%s",&str2);strcpy(h->data.num,str2);printf("InputyourbookNum:");scanf("%d",&dem);h->data.bookNum=dem;h->next=NULL;v->next=h;word可自由复制编辑

v=h;printf("\nLucky!youhavebookedaticket!");getch();shoudsave=1;}}}bookMan*Locate2(bookManLinkk,charfindmess[]){bookMan*r;r=k->next;while(r){if(strcmp(r->data.num,findmess)==0){mark=1;returnr;}r=r->next;word可自由复制编辑

}return0;}/*修改火车信*/voidUpdateInfo(Linkl){Node*p;charfindmess[20],ch;if(!l->next){printf("\nthereisn'trecordforyoutomodify!\n");return;}else{QueryTrain(l);if(mark1==0){printf("\nDoyouwanttomodifyit?\n");word可自由复制编辑

getchar();scanf("%c",&ch);if(ch=='y');{printf("\nInputthenumberofthetrain:");scanf("%s",findmess);p=Locate1(l,findmess,"num");if(p){printf("Inputnewnumberoftrain:");scanf("%s",&p->data.num);printf("Inputnewcitythetrainwillreach:");scanf("%s",&p->data.city);printf("Inputnewtimethetraintakeoff");scanf("%s",&p->data.takeoffTime);printf("Inputnewtimethetrainreach:");scanf("%s",&p->data.receiveTime);printf("Inputnewpriceoftheticket::");scanf("%d",&p->data.price);word可自由复制编辑

printf("Inputnewnumberofpeoplewhohavebookedticket:");scanf("%d",&p->data.bookNum);printf("\nmodifyingrecordissucessful!\n");shoudsave=1;}elseprintf("\t\t\tcan'tfindtherecord!");}}elsemark1=0;}}/*系统给用户的提信息*/voidAdvicedTrains(Linkl){Node*r;charstr[10];intmar=0;word可自由复制编辑

r=l->next;printf("Iuputthecityyouwanttogo:");scanf("%s",str);while(r){if(strcmp(r->data.city,str)==0&&r->data.bookNum<200){mar=1;printf("\nyoucanselectthefollowingtrain!\n");printf("\n\npleaseselectthefourthoperationtobooktheticket!\n");printTrainInfo(r);}r=r->next;}if(mar==0)printf("\n\t\t\tyoucan'tbookanyticketnow!\n");}/*保存火车信*/word可自由复制编辑

voidSaveTrainInfo(Linkl){FILE*fp;Node*p;intcount=0,flag=1;fp=fopen("c:\\train.txt","wb");if(fp==NULL){printf("thefilecan'tbeopened!");return;}p=l->next;while(p){if(fwrite(p,sizeof(Node),1,fp)==1){p=p->next;count++;}word可自由复制编辑

else{flag=0;break;}}if(flag){printf("thenumberoftherecordwhichhavebeensavedis%d\n",count);shoudsave=0;}fclose(fp);}/*保存订票人的信*/voidSaveBookmanInfo(bookManLinkk){FILE*fp;bookMan*p;intcount=0,flag=1;word可自由复制编辑

fp=fopen("c:\\man.txt","wb");if(fp==NULL){printf("thefilecan'tbeopened!");return;}p=k->next;while(p){if(fwrite(p,sizeof(bookMan),1,fp)==1){p=p->next;count++;}else{flag=0;break;}word可自由复制编辑

}if(flag){printf("thenumberoftherecordwhichhavebeensavedis%d\n",count);shoudsave=0;}fclose(fp);}intmain(){FILE*fp1,*fp2;Node*p,*r;charch1,ch2;Linkl;bookManLinkk;bookMan*t,*h;intsel;l=(Node*)malloc(sizeof(Node));word可自由复制编辑

l->next=NULL;r=l;k=(bookMan*)malloc(sizeof(bookMan));k->next=NULL;h=k;fp1=fopen("c:\\train.txt","ab+");if((fp1==NULL)){printf("can'topenthefile!");return0;}while(!feof(fp1)){p=(Node*)malloc(sizeof(Node));if(fread(p,sizeof(Node),1,fp1)==1){p->next=NULL;r->next=p;r=p;word可自由复制编辑

count1++;}}fclose(fp1);fp2=fopen("c:\\man.txt","ab+");if((fp2==NULL)){printf("can'topenthefile!");return0;}while(!feof(fp2)){t=(bookMan*)malloc(sizeof(bookMan));if(fread(t,sizeof(bookMan),1,fp2)==1){t->next=NULL;h->next=t;h=t;word可自由复制编辑

count2++;}}fclose(fp2);while(1){clrscr();printInterface();printf("pleasechoosetheoperation:");scanf("%d",&sel);clrscr();if(sel==8){if(shoudsave==1){getchar();printf("\nthefilehavebeenchanged!doyouwanttosaveit(y/n)?\n");scanf("%c",&ch1);if(ch1=='y'||ch1=='Y')word可自由复制编辑

{SaveBookmanInfo(k);SaveTrainInfo(l);}}printf("\nThankyou!!Youarewelcometoo\n");break;}switch(sel){case1:InsertTraininfo(l);break;case2:QueryTrain(l);break;case3:BookTicket(l,k);break;case4:UpdateInfo(l);break;word可自由复制编辑

case5:AdvicedTrains(l);break;case6:SaveTrainInfo(l);SaveBookmanInfo(k);break;case7:return0;}printf("\npleasepressanykeytocontinue.......");getch();}return0;}3.2调试与测试主要程运行结果:行开始word可自由复制编辑

选择入信息选择询信息选择票选择用word可自由复制编辑

选择你的建选择出系统3.心得体会通过这次课

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论