C语言课程设计报告火车票信息管理系统.docx
- 文档编号:7646627
- 上传时间:2023-01-25
- 格式:DOCX
- 页数:20
- 大小:78.76KB
C语言课程设计报告火车票信息管理系统.docx
《C语言课程设计报告火车票信息管理系统.docx》由会员分享,可在线阅读,更多相关《C语言课程设计报告火车票信息管理系统.docx(20页珍藏版)》请在冰豆网上搜索。
C语言课程设计报告火车票信息管理系统
江苏教育学院信息技术专业
课程设计报告
姓名
班级
学号
课程设计信息
课程名称
C程序设计
课程设计题目
火车票信息管理系统
课程设计时间
2011-11-1至2011-12-30
成绩
评阅教师
2010-2011学年第一学期
票务信息管理程序
一、课程设计内容
我所设计的程序是一个火车票信息管理系统,其是从南京火车站通向47座城市的火车票的查询,购买,退订的程序。
其涉及的主要算法有:
1输入;2.查询;3.输出;4.选择;5.返回。
二、课程设计目的
设计南京火车站的票务信息管理程序,其主要问题要求是做一个车票购买的函数的显示程序
三、算法的基本思想
1.数据的结构
此程序需要设计2个数据结构,结构体设计如下:
(1)typedefstructtraininfor
{
charstation[10][10];//记录车站信息
chartnumber[20];//车次号
floatprice;//车票价格
intlnumber;//生成票量
chartime[20];//到站时间
}pemp;
(2)structticket
{
charbuyer[10];//购票人姓名
charsource[30];//起始站
chardest[30];//终点站
intbnumber;//购买张数
};
2.函数定义
程序源文件中包含的函数如下
源文件
函数类型
功能说明
ticket.c
voidmenu(pemp*pointtr,structticket*pointtk)
打印主菜单
voidbuy(pemp*pointtr,structticket*pointtk)
购买车票
voidreturnt(pemp*pointtr,structticket*pointtk)
退票
voidcheck(pemp*pointtr,structticket*pointtk)
查看起始地车票信息
voidshow(structticket*pointtk,pemp*pointtr)
显示车票信息
Voidexit()
退出程序
3.处理过程
1)菜单显示程序
voidmenu(pemp*pointtr,structticket*pointtk)
{
inta;
printf("\n\n\n\n-----------------目录-----------------\n");
printf("1,查询车票\n");
printf("2,购买车票\n");
printf("3,退订车票\n");
printf("4,退出程序\n");
printf("请输入选项序号:
");
scanf("%d",&a);
if(a==1)
{
check(pointtr,pointtk);//按起始地查找
menu(pointtr,pointtk);//显示菜单程序
}
elseif(a==2)
buy(pointtr,pointtk);//购买车票
elseif(a==3)
returnt(pointtr,pointtk);//退订车票
elseif(a==4)
{
printf("谢谢使用!
");
//exit();
exit(0);
}
}
2)车票购买函数
voidbuy(pemp*pointtr,structticket*pointtk)
{
charchoice[10];
intbuynumber;
printf("请输入您的姓名:
\n");
scanf("%s",pointtk->buyer);//输入姓名
check(pointtr,pointtk);//查询是否有车票
if((strcmp(pointtk->dest,"o"))==0)//如果没有给出提示
{
printf("无此站!
返回菜单!
\n");
menu(pointtr,pointtk);
}
else
{
printf("您确定购买此车票吗?
1.是2.否\n");//确认购买
scanf("%d",choice);
if((strcmp(choice,"1"))==0)
{
printf("请输入您要购买的张数:
\n");//输入张数
{
scanf("%d",&buynumber);
if(buynumber<0)return;
}
if(((pointtr->lnumber)-buynumber)>=0)
{
printf("购买成功!
返回菜单\n");
pointtk->bnumber=buynumber;
(pointtr->lnumber)-=buynumber;
menu(pointtr,pointtk);
}
else
{
printf("车票已售完或不足,不能购买!
返回菜单\n");
menu(pointtr,pointtk);
}
}
elseif((strcmp(choice,"2"))==0)//放弃购买
{
printf("放弃购买,返回菜单\n");
menu(pointtr,pointtk);
}
else
{
menu(pointtr,pointtk);
printf("错误,返回菜单\n");
menu(pointtr,pointtk);
}
}
}
3)退订票务程序
voidreturnt(pemp*pointtr,structticket*pointtk)
{
charchoice[10];
printf("您确定要退票吗?
1.是2.否\n");
scanf("%s",choice);
if((strcmp(choice,"1"))==0)
{
printf("退票成功!
返回菜单\n");
pointtr->lnumber+=pointtk->bnumber;
menu(pointtr,pointtk);
}
elseif((strcmp(choice,"2"))==0)
{
printf("放弃退票,返回菜单\n");
menu(pointtr,pointtk);
}
else
{
menu(pointtr,pointtk);
printf("错误,返回菜单\n");
menu(pointtr,pointtk);
}
}
4)显示信息
voidshow(structticket*pointtk,pemp*pointtr)
{
printf("车次:
");
printf("T11");
printf("起始地-------->目的地:
");
printf("%s--------->",pointtk->source);
printf("%s\n",pointtk->dest);
printf("到达时间:
",pointtk->source);
printf("%s\n",pointtr->time);
printf("票价:
");
printf("%10.2f\n",pointtr->price);
printf("车票数量:
");
printf("%d\n",pointtr->lnumber);
}
5)按起始地目的地查找
voidcheck(pemp*pointtr,structticket*pointtk)
{
inti,j,count=0;
charsour[10];
chardest[10];
printf("请输入起始地:
\n");//输入起始地
scanf("%s",sour);
printf("请输入目的地:
\n");//输入目的地
scanf("%s",dest);
for(i=0;i { if(strcmp(pointtr->station[i],sour)==0)//查找第一个车站 { for(j=0;j { if(strcmp(pointtr->station[j],dest)==0)//查找地二个车站 { strcpy(pointtk->source,pointtr->station[i]);//将车站写入车票中 strcpy(pointtk->dest,pointtr->station[j]); show(pointtk,pointtr); count++; break; } } } if(count==0) { printf("无信息! \n"); strcpy(pointtk->source,"0");//如果没找到车站为空的 strcpy(pointtk->dest,"0"); return; } } } 四、测试结果 1.主菜单显示 -----------------目录----------------- 1,查询车票 2,购买车票 3,退订车票 4,退出程序 请输入选项序号: 2.查询车票 -----------------目录----------------- 1,查询车票 2,购买车票 3,退订车票 4,退出程序 请输入选项序号: 1 请输入起始地: 南京 请输入目的地: 邳州 车次: T11起始地-------->目的地: 南京--------->徐州 到达时间: 2011年11月11日11时11分 票价: 56.00 车票数量: 0 -----------------目录----------------- 1,查询车票 2,购买车票 3,退订车票 4,退出程序 请输入选项序号: 3.购买车票 -----------------目录----------------- 1,查询车票 2,购买车票 3,退订车票 4,退出程序 请输入选项序号: 2 请输入您的姓名: 张洁 请输入起始地: 南京 请输入目的地: 邳州 车次: T11起始地-------->目的地: 南京--------->徐州 到达时间: 2011年11月11日11时11分 票价: 56.00 车票数量: 0 您确定购买此车票吗? 1.是2.否 1 -----------------目录----------------- 1,查询车票 2,购买车票 3,退订车票 4,退出程序 请输入选项序号: 4.退订车票 -----------------目录----------------- 1,查询车票 2,购买车票 3,退订车票 4,退出程序 请输入选项序号: 3 您确定要退票吗? 1.是2.否 1 退票成功! 返回菜单 -----------------目录----------------- 1,查询车票 2,购买车票 3,退订车票 4,退出程序 请输入选项序号: 5.退出程序 -----------------目录----------------- 1,查询车票 2,购买车票 3,退订车票 4,退出程序 请输入选项序号: 4 谢谢使用! Pressanykeytocontinue 五、源程序代码 #include #include #include #definenum100 typedefstructtraininfor { charstation[10][10];//记录车站信息 chartnumber[20];//车次号 floatprice;//车票价格 intlnumber;//生成票量 chartime[20];//到站时间 }pemp; structticket { charbuyer[10];//购票人姓名 charsource[30];//起始站 chardest[30];//终点站 intbnumber;//购买张数 }; voidmenu(pemp*pointtr,structticket*pointtk); voidbuy(pemp*pointtr,structticket*pointtk); voidreturnt(pemp*pointtr,structticket*pointtk); voidcheck(pemp*pointtr,structticket*pointtk); voidshow(structticket*pointtk,pemp*pointtr); //voidexit(); intmain() { pemptraininformation[num]; structticketcheque[num]; pemp*pointtr; structticket*pointtk; pointtr=traininformation; pointtk=cheque; strcpy(pointtr->station[0],"南京"); strcpy(pointtr->station[1],"徐州"); strcpy(pointtr->station[2],"重庆"); strcpy(pointtr->station[3],"苏州"); strcpy(pointtr->station[4],"南通"); strcpy(pointtr->station[5],"上海"); strcpy(pointtr->station[6],"深圳"); strcpy(pointtr->station[7],"广州"); strcpy(pointtr->station[8],"大连"); strcpy(pointtr->station[9],"北京"); strcpy(pointtr->station[10],"天津"); strcpy(pointtr->station[11],"滁州"); strcpy(pointtr->station[12],"扬州"); strcpy(pointtr->station[13],"重庆"); strcpy(pointtr->station[14],"蚌埠"); strcpy(pointtr->station[15],"西安"); strcpy(pointtr->station[16],"济南"); strcpy(pointtr->station[17],"太原"); strcpy(pointtr->station[18],"成都"); strcpy(pointtr->station[19],"石家庄"); strcpy(pointtr->station[20],"长沙"); strcpy(pointtr->station[21],"保定"); strcpy(pointtr->station[22],"贵州"); strcpy(pointtr->station[23],"长春"); strcpy(pointtr->station[24],"哈尔滨"); strcpy(pointtr->station[25],"青岛"); strcpy(pointtr->station[26],"吐鲁番"); strcpy(pointtr->station[27],"拉萨"); strcpy(pointtr->station[28],"杭州"); strcpy(pointtr->station[29],"无锡"); strcpy(pointtr->station[30],"常州"); strcpy(pointtr->station[31],"金华"); strcpy(pointtr->station[32],"合肥"); strcpy(pointtr->station[33],"盐城"); strcpy(pointtr->station[34],"宿迁"); strcpy(pointtr->station[35],"日照"); strcpy(pointtr->station[36],"大理"); strcpy(pointtr->station[37],"昆山"); strcpy(pointtr->station[38],"郑州"); strcpy(pointtr->station[39],"汉口"); strcpy(pointtr->station[40],"宁波"); strcpy(pointtr->station[41],"南昌"); strcpy(pointtr->station[42],"芜湖"); strcpy(pointtr->station[43],"泰州"); strcpy(pointtr->station[44],"镇江"); strcpy(pointtr->station[45],"昆明"); strcpy(pointtr->station[46],"武汉"); strcpy(pointtr->station[47],"沈阳"); strcpy(pointtr->station[48],"武昌"); strcpy(pointtr->tnumber,"T11"); pointtr->price=88.00; pointtr->lnumber=50; strcpy(pointtr->time,"2010年12月22日22时22分"); pointtr->lnumber=0; menu(pointtr,pointtk); return0; } voidmenu(pemp*pointtr,structticket*pointtk) { inta; printf("\n\n\n\n-----------------目录-----------------\n"); printf("1,查询车票\n"); printf("2,购买车票\n"); printf("3,退订车票\n"); printf("4,退出程序\n"); printf("请输入选项序号: "); scanf("%d",&a); if(a==1) { check(pointtr,pointtk);//按起始地查找 menu(pointtr,pointtk);//显示菜单程序 } elseif(a==2) buy(pointtr,pointtk);//购买车票 elseif(a==3) returnt(pointtr,pointtk);//退订车票 elseif(a==4) { printf("谢谢使用! "); //exit(); exit(0); } } voidshow(structticket*pointtk,pemp*pointtr) { printf("车次: "); printf("T11"); printf("起始地-------->目的地: "); printf("%s--------->",pointtk->source); printf("%s\n",pointtk->dest); printf("到达时间: ",pointtk->source); printf("%s\n",pointtr->time); printf("票价: "); printf("%10.2f\n",pointtr->price); printf("车票数量: "); printf("%d\n",pointtr->lnumber); } voidcheck(pemp*pointtr,structticket*pointtk) { inti,j,count=0; charsour[10]; chardest[10]; printf("请输入起始地: \n");//输入起始地 scanf("%s",sour); printf("请输入目的地: \n");//输入目的地 scanf("%s",dest); for(i=0;i { if(strcmp(pointtr->station[i],sour)==0)//查找第一个车站 { for(j=0;j { if(strcmp(pointtr->station[j],dest)==0)//查找地二个车站 { strcpy(pointtk->source,pointtr->station[i]);//将车站写入车票中 strcpy(pointtk->dest,pointtr->station[j]); show(pointtk,pointtr); count++; break; } } } if(count==0) { printf("无信息! \n"); strcpy(pointtk->source,"0");//如果没找到车站为空的 strcpy(pointtk->dest,"0"); return; } } } voidbuy(pemp*pointtr,structticket*pointtk) { charchoice[10]; intbuynumber; printf("请输入您的姓名: \n"); scanf("%s",pointtk->buyer);//输入姓名 check(pointtr,pointtk);//查询是否有车票 if((strcmp(pointtk->dest,"o"))==0)//如果没有给出提示 { printf("无此站! 返回菜单! \n"); menu(pointtr,pointtk); } else { printf("您确定购买此车票吗? 1.是2.否\n");//确认购买 scanf("%d",choice); if((strcmp(choice,"1"))==0) { printf("请输入您要购买的张数: \n");//输入张数
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- 语言 课程设计 报告 火车票 信息管理 系统