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

上传人:b****9 文档编号:25266018 上传时间:2023-06-06 格式:DOCX 页数:24 大小:53.33KB
下载 相关 举报
C语言程序设计火车订票系统程序设计报告.docx_第1页
第1页 / 共24页
C语言程序设计火车订票系统程序设计报告.docx_第2页
第2页 / 共24页
C语言程序设计火车订票系统程序设计报告.docx_第3页
第3页 / 共24页
C语言程序设计火车订票系统程序设计报告.docx_第4页
第4页 / 共24页
C语言程序设计火车订票系统程序设计报告.docx_第5页
第5页 / 共24页
点击查看更多>>
下载资源
资源描述

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

《C语言程序设计火车订票系统程序设计报告.docx》由会员分享,可在线阅读,更多相关《C语言程序设计火车订票系统程序设计报告.docx(24页珍藏版)》请在冰豆网上搜索。

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

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

 

设计题目:

火车订票系统设计

 

专业:

电子信息工程

班级:

09级3班

姓名:

学号:

 

一总体设计(包含几大功能模块)1

二详细设计(各功能模块的具体实现算法——流程图)2

三调试分析(包含各模块的测试用例,及测试结果)3

3.1源程序6

3.2调试与测试31

四总结33

 

一总体设计(包含几大功能模块)

1.Insertatraininformation(插入火车信息)

2.inquireatrainjinformation(查询火车信息)

3.Bookatrainticket(订票)

4.Updatethetraininformation(更新火车信息)

5.Advicetoyouaboutthetrain(建议)

6.Saveinformationtofile(储存信息归档)

7.Quitthesystem(退出系统)

二、详细设计(各功能模块的具体实现算法——流程图)

2.1各函数的功能和实现

 

1.Insertatraininformation(插入火车信息):

输入包括火车班次,最终目地,始发站,火车到站时间,车票价格,所定票号。

可用函数voidinput来实现此操作

2.inquireatrainjinformation(查询火车信息):

没有任何记录

3.Bookatrainticket(订票):

输入你想要去的城市

4.Updatethetraininformation(更新火车信息):

可用voidfind()来实现

5.Advicetoyouaboutthetrain(关于火车对你的建议)

6.Saveinformationtofile(储存信息归档)

7.Quitthesystem(退出系统):

可用一个函数exit()来实现,首先将信息保存到文件中,释放动态创建的内存空间,再退出此程序。

 

流程图

 

详见A4纸上手绘

 

三调试分析(包含各模块的测试用例,及测试结果)

3.1源程序

#include

#include

#include

#include

intshoudsave=0;

intcount1=0,count2=0,mark=0,mark1=0;

/*定义存储火车信息的结构体*/

structtrain

{

charnum[10];/*列车号*/

charcity[10];/*目的城市*/

chartakeoffTime[10];/*发车时间*/

charreceiveTime[10];/*到达时间*/

intprice;/*票价*/

intbookNum;/*票数*/

};

/*订票人的信息*/

structman

{

charnum[10];/*ID*/

charname[10];/*姓名*/

intbookNum;/*需求的票数*/

};

/*定义火车信息链表的结点结构*/

typedefstructnode

{

structtraindata;

structnode*next;

}Node,*Link;

/*定义订票人链表的结点结构*/

typedefstructpeople

{

structmandata;

structpeople*next;

}bookMan,*bookManLink;

/*初始界面*/

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)

{

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;

}

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;

}

}

/*打印火车票信息*/

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)

{

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;

}

/*查询火车信息*/

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)

{

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)

{

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];

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

printTrainInfo(r[t]);

if(i==0)

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->data.name,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;

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;

}

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");

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);

printf("Inputnewnumberofpeoplewhohavebookedticket:

");

scanf("%d",&p->data.bookNum);

printf("\nmodifyingrecordissucessful!

\n");

shoudsave=1;

}

else

printf("\t\t\tcan'tfindtherecord!

");

}

}

else

mark1=0;

}

}

/*系统给用户的提示信息*/

voidAdvicedTrains(Linkl)

{

Node*r;

charstr[10];

intmar=0;

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");

}

/*保存火车信息*/

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++;

}

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;

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;

}

}

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));

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;

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;

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')

{

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;

case5:

AdvicedTrains(l);break;

case6:

SaveTrainInfo(l);SaveBookman

展开阅读全文
相关资源
猜你喜欢
相关搜索
资源标签

当前位置:首页 > 总结汇报 > 学习总结

copyright@ 2008-2022 冰豆网网站版权所有

经营许可证编号:鄂ICP备2022015515号-1