2023年7月6日发(作者:)
辽宁师范大学
专业: 电子信息工程
班级: 09级3班
姓名: **
学号: **************
设计题目:火车订票系统设计 目 录
一 总体设计(包含几大功能模块) ............................... 1
二 详细设计(各功能模块的具体实现算法——流程图) ...................................................................................... 2
三 调试分析(包含各模块的测试用例,及测试结果) .............................................................................................. 3
3.1源程序 ....................................................................... 6
3.2调试与测试 ............................................................. 31
四 总结 ...............................................................................
33
一 总体设计(包含几大功能模块)
a train information(插入火车信息)
e a train jinformation(查询火车信息)
a train ticket(订票)
the train information(更新火车信息)
to you about the train (建议)
information to file(储存信息归档)
the system(退出系统) 二、详细设计(各功能模块的具体实现算法——流程图)
2.1各函数的功能和实现
a train information(插入火车信息):输入包括火车班次,最终目地,始发站,火车到站时间,车票价格,所定票号。可用函数void input来实现此操作
e a train jinformation(查询火车信息):没有任何记录
a train ticket(订票):输入你想要去的城市
the train information(更新火车信息):可用void
find()来实现
to you about the train (关于火车对你的建议)
information to file(储存信息归档)
the system(退出系统):可用一个函数exit()来实现,首先将信息保存到文件中,释放动态创建的内存空间,再退出此程序。
流程图
详见A4纸上手绘
三 调试分析(包含各模块的测试用例,及测试结果)
3.1源程序
#include
#include
#include
#include
int shoudsave=0 ;
int count1=0,count2=0,mark=0,mark1=0 ;
/*定义存储火车信息的结构体*/
struct train
{
char num[10];/*列车号*/
char city[10];/*目的城市*/
char takeoffTime[10];/*发车时间*/
char receiveTime[10];/*到达时间*/
int price;/*票价*/ int bookNum ;/*票数*/
};
/*订票人的信息*/
struct man
{
char num[10];/*ID*/
char name[10];/*姓名*/
int bookNum ;/*需求的票数*/
};
/*定义火车信息链表的结点结构*/
typedef 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: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)
{
struct node *p,*r,*s ;
char num[10];
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->,num)==0)
{ printf("the train '%s'has been born!n",num);
return ;
}
s = s->next ;
}
p = (struct node*)malloc(sizeof(struct node));
strcpy(p->,num);
printf("Input the city where the train will reach:");
scanf("%s",p->);
printf("Input the time which the train take off:");
scanf("%s",p->fTime);
printf("Input the time which the train receive:");
scanf("%s",&p->eTime);
printf("Input the price of ticket:");
scanf("%d",&p->);
printf("Input the number of booked tickets:");
scanf("%d",&p->m);
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->);
printf(">>city the train will reach: %sn",p->);
printf(">>the time the train take off: %snthe time the train
reach: %sn",p->fTime,p->eTime);
printf(">>the price of the ticket: %dn",p->);
printf(">>the number of booked tickets: %dn",p->m);
}
struct node * Locate1(Link l,char findmess[],char numorcity[])
{
Node*r ; if(strcmp(numorcity,"num")==0)
{
r=l->next ;
while(r)
{
if(strcmp(r->,findmess)==0)
return r ;
r=r->next ;
}
}
else if(strcmp(numorcity,"city")==0)
{
r=l->next ;
while(r)
{
if(strcmp(r->,findmess)==0)
return r ;
r=r->next ;
} }
return 0 ;
}
/*查询火车信息*/
void QueryTrain(Link l)
{
Node *p ;
int sel ;
char str1[5],str2[10];
if(!l->next)
{
printf("There is not any record !");
return ;
}
printf("Choose the way:n>>1:according to the number of train;n>>2: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 can't be found!");
}
}
else if(sel==2)
{
printf("Input the city:");
scanf("%s",str2); p=Locate1(l,str2,"city");
if(p)
{
printTrainInfo(p);
}
else
{
mark1=1 ;
printf("nthe file can't be found!");
}
}
}
/*订票子模块*/
void BookTicket(Link l,bookManLink k)
{
Node*r[10],*p ;
char ch,dem ;
bookMan*v,*h ; int i=0,t=0 ;
char str[10],str1[10],str2[10];
v=k ;
while(v->next!=NULL)
v=v->next ;
printf("Input the city you want to go: ");
scanf("%s",&str);
p=l->next ;
while(p!=NULL)
{
if(strcmp(p->,str)==0)
{
r[i]=p ;
i++;
}
p=p->next ;
}
printf("nnthe number of record have %dn",i);
for(t=0;t
if(i==0)
printf("ntttSorry!Can't find the train for you!n");
else
{
printf("ndo you want to book it?<1/0>n");
scanf("%d",&ch);
if(ch == 1)
{
h=(bookMan*)malloc(sizeof(bookMan));
printf("Input your name: ");
scanf("%s",&str1);
strcpy(h->,str1);
printf("Input your id: ");
scanf("%s",&str2);
strcpy(h->,str2);
printf("Input your bookNum: ");
scanf("%d",&dem);
h->m=dem ; h->next=NULL ;
v->next=h ;
v=h ;
printf("nLucky!you have booked a ticket!");
getch();
shoudsave=1 ;
}
}
}
bookMan*Locate2(bookManLink k,char findmess[])
{
bookMan*r ;
r=k->next ;
while(r)
{
if(strcmp(r->,findmess)==0)
{
mark=1 ;
return r ; }
r=r->next ;
}
return 0 ;
}
/*修改火车信息*/
void UpdateInfo(Link l)
{
Node*p ;
char findmess[20],ch ;
if(!l->next)
{
printf("nthere isn't record for you to modify!n");
return ;
}
else
{
QueryTrain(l);
if(mark1==0) {
printf("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->);
printf("Input new city the train will reach:");
scanf("%s",&p->);
printf("Input new time the train take off");
scanf("%s",&p->fTime);
printf("Input new time the train reach:");
scanf("%s",&p->eTime); printf("Input new price of the ticket::");
scanf("%d",&p->);
printf("Input new number of people who have booked ticket:");
scanf("%d",&p->m);
printf("nmodifying record is sucessful!n");
shoudsave=1 ;
}
else
printf("tttcan't find the record!");
}
}
else
mark1=0 ;
}
}
/*系统给用户的提示信息*/
void AdvicedTrains(Link l)
{
Node*r ; char str[10];
int mar=0 ;
r=l->next ;
printf("Iuput the city you want to go: ");
scanf("%s",str);
while(r)
{
if(strcmp(r->,str)==0&&r->m<200)
{
mar=1 ;
printf("nyou can select the following train!n");
printf("nnplease select the fourth operation to book the ticket!n");
printTrainInfo(r);
}
r=r->next ;
}
if(mar==0)
printf("ntttyou can't book any ticket now!n");
}
/*保存火车信息*/
void SaveTrainInfo(Link l)
{
FILE*fp ;
Node*p ;
int count=0,flag=1 ;
fp=fopen("c:","wb");
if(fp==NULL)
{
printf("the file can't 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 saved is %dn",count);
shoudsave=0 ;
}
fclose(fp);
}
/*保存订票人的信息*/
void SaveBookmanInfo(bookManLink k)
{
FILE*fp ; bookMan*p ;
int count=0,flag=1 ;
fp=fopen("c:","wb");
if(fp==NULL)
{
printf("the file can't 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("the 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:","ab+");
if((fp1==NULL))
{
printf("can't 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:","ab+");
if((fp2==NULL))
{
printf("can't open the file!");
return 0 ;
}
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("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')
{
SaveBookmanInfo(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;
}
printf("nplease press any key ");
getch();
}
return 0;
}
3.2调试与测试 主要程序运行结果:运行开始
选择1输入信息:
选择2查询信息
选择3订票
选择4没用
选择5对你的建议
选择7退出系统
3. 心得体会 通过这次课程设计,增加了我对软件技术的了解,虽然还不明确软件技术包含的具体内容,但从学习C语言这门课程开始,已发现程序设计的好处,他对我们数学的学习也有很大的帮助。在学习C语言的过程中也学到和巩固了许多计算机应用基础知识,对计算机的机体也有了一个较为详细的了解。在具体操作中对这学期所学的C语言的理论知识得到巩固加强,达到实训的目的,也发现自己的不足之处,为我问以后的c语言学习奠定了基础,同时体会到C语言具有的语句简洁,使用灵活,执行效率高等特点。发现上机操作的重要作用,特别是对数组和循环有了深刻的理解。通过实际操作,学会 C语言程序编程的基本步骤、基本方法,开发了自己的逻辑思维能力,培养了分析问题、解决问题的能力。
4.总结
由于本课题中的许多知识点都没有学过都要靠自己到课外的资料中去查找。在用的时候难免出现这样那样的错误。如开始设计出来的菜单不是预想的那样,而是总个窗中出现混乱。解决的这个问题的办法是调整。最后还是老师帮我帮我们找到了问题的所在。一个系统的菜单和提示信息非常重要。如果没有这些用户根本不知道怎么用你设计的这个系统。在设计的调试过程中也无法顺利的完成调试工作。有了一个清晰简单的菜单和一些提示信息这后,调试过程完成的非常顺利。
回顾起此次课程设计,至今我仍感慨颇多,的确,从拿到题目到完成整个编程,从理论到实践,在整整半个月的日子里,可以学到很多很多的东西,同时不仅可以巩固了以前所学过的知识,而且学到了很多在书本上所没有学到过的知识。通过这次课程设计使我懂得了理论与实际相结合是很重要的,只有理论知识是远远不够的,只有把所学的理论知识与实践相结合起来,从理论中得出结论,才能真正为社会服务,从而提高自己的实际动手能力和独立思考的能力。在设计的过程中遇到问题,可以说得是困难重重,这毕竟第一次做的,难免会遇到过各种各样的问题,同时在设计的过程中发现了自己的不足之处,对以前所学过的知识理解得不够深刻,掌握得不够牢固,比如说结构体……通过这次课程设计之后,一定把以前所学过的知识本次课程设计结束了,对于我的影响很大。我通过这次实践学到了许多知识。学到了设计一个简单的系统。要注意哪些方面。也使我知道自己哪些方面做得还不够。
发布者:admin,转转请注明出处:http://www.yc00.com/xiaochengxu/1688605409a154560.html
评论列表(0条)