C语言程序设计_火车订票系统程序设计报告
- 格式:doc
- 大小:110.50 KB
- 文档页数:34
word 可自由复制编辑
辽宁师范大学
设计题目:火车订票系统设计
专业: 电子信息工程
班级: 09级3班
姓名: 张宁
学号: 20091121020025
word 可自由复制编辑 目 录
一 总体设计(包含几大功能模块) ............................... 1
二 详细设计(各功能模块的具体实现算法——流程图) ...................................................................................... 2
三 调试分析(包含各模块的测试用例,及测试结果) .............................................................................................. 3
3.1源程序 ....................................................................... 6
3.2调试与测试 ............................................................. 31
四 总结 ............................................................................... 33
word 可自由复制编辑
一 总体设计(包含几大功能模块)
1.Insert a train information(插入火车信息)
2.inquire a train jinformation(查询火车信息)
3.Book a train ticket(订票)
4.Update the train information(更新火车信息)
5.Advice to you about the train (建议)
6.Save information to file(储存信息归档)
7.Quit the system(退出系统)
word 可自由复制编辑 二、详细设计(各功能模块的具体实现算法——流程图)
2.1各函数的功能和实现
1.Insert a train information(插入火车信息):输入包括火车班次,最终目地,始发站,火车到站时间,车票价格,所定票号。可用函数void input来实现此操作
2.inquire a train jinformation(查询火车信息):没有任何记录
3.Book a train ticket(订票):输入你想要去的城市
4.Update the train information(更新火车信息):可用void
find()来实现
5.Advice to you about the train (关于火车对你的建议)
6.Save information to file(储存信息归档)
7.Quit the system(退出系统):可用一个函数exit()来实现,首先将信息保存到文件中,释放动态创建的内存空间,再退出此程序。
word 可自由复制编辑 流程图
详见A4纸上手绘
word 可自由复制编辑
三 调试分析(包含各模块的测试用例,及测试结果)
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 ;/*票数*/
};
word 可自由复制编辑 /*订票人的信息*/
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 ;
word 可自由复制编辑 /* 初始界面*/
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)
{
word 可自由复制编辑 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->data.num,num)==0)
{
printf("the train '%s'has been born!\n",num);
return ;
word 可自由复制编辑 }
s = s->next ;
}
p = (struct node*)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 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 ;