




已阅读5页,还剩13页未读, 继续免费阅读
版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
二九 二一学年第 二 学期信息科学与工程学院课程设计报告书课程名称: C语言课程设计 班 级: 学 号: 姓 名: 指导教师: 二一 年 九 月 车票管理系统 一.需求分析设计题目及要求:设计题目:车票管理设计要求:建立车票系统,每个车次的信息包括:班次,发车时间,起点站,终点站,行车时间,额定人数,已定票人数等.系统能够完成车票信息的录入,浏览,查询,售票,退票等功能.系统功能需求分析:(1)录入: 录入班次信息(信息用文件保存),可不定时的增加班次数据(2)浏览: 浏览班次信息,可显示出所有班次当前总状态(如果当前系统时间超过了某班次的发车时间,则显示“此班已发出”的提示信息)。(3)查询: 查询线路:可按班次号查询,可按钟点战查询.(4)售票: 当查询出已定票人数小于额定载量且当前系统时间小于发车时间时才能售票,自动更新已售票人数(5)退票: 退票时,输入退票班次,当本班次未出发时才能退票,自动更新已售票人数二.概要设计:系统总体设计框架(系统功能模块图):系统模块图其中:信息输入模块完成班次信息的输入功能,输入信息包括班次、发车时间、起点站、终点站、行车时间、额定载量、定票人数等;信息浏览模块完成已录入信息的显示;信息查询模块完成班次信息的查询,查询时对应有按班次查询和按终点站查询两种方式;售票和退票模块完成车票的购买和退订的功能;菜单选择模块完成用户命令的接收,此模块也是车票管理系统的入口,用户所要进行的各种操作均需在此模块中进行选择并进而调用其他模块实现相应的功能;三详细设计数据结构:本系统中主要的数据结构就是车次的信息,包括班次、发车时间、起点站、终点站、行车时间、额定载量、定票人数等,在处理过程中各项可以作为车次的不同属性来处理。车票系统:typedef struct information int numb; /*列车号*/char starttime10; /*发车时间*/char begin21; /*起点*/char end21; /*终点*/float lasttime; /*行车时间*/int FixNumber; /*额定载客量*/int FixedNumber; /*已定票数*/struct information *next;INFORMATION,*PINF;void main() /*主函数*/ switch(i) case 1:Insert(); printf(n按任意键回主菜单.n);getchar();getchar();break;/*录入*/case 2:Scan();printf(n按任意键回主菜单.n);getchar();getchar();break; /*浏览*/case 3:SearchMenu();break; /*查询*/case 4:Buyticket();break; /*订票*/case 5:TicketDelete();break; /*退票*/case 6:exit();break; /*退出*/default:printf(输入错误,请确保你的输入为1-6.n);break; 系统工作程序流程:系统的执行应从功能菜单的选择开始,依据用户的选择来进行后续的处理,直到用户选择退出系统为止,其间应对用户的选择做出判断及异常处理。算法的流程图如下: 程序流程图四主要源程序代码#include#include /标准库文件#include#include#include #includetypedef struct information /用typedef定义结构体为INFORMATION int numb; /列车号char starttime10; char begin21; char end21; float lasttime; int FixNumber; int FixedNumber; struct information *next;INFORMATION,*PINF; /结构体类型指针INFORMATION *head; /班次头结点INFORMATION *rear; /班次尾结点int main() /主程序 system(color 5f);/system(mode con: cols=140 lines=130);head=rear=(INFORMATION *)malloc(sizeof(INFORMATION);head-next=NULL;/函数声明 void Insert(); /录入班次信息 void input(); /文件读入 void Scan(); /浏览全部信息 void SearchMenu(); /查询信息 void Buyticket(); /预定车票 void TicketDelete(); /退订车票 void Save_In(); /把数据重新保存到文件中 void exit(); /退出该系统input(); int i=0;while(i!=6) printf(*n); printf(* Welcome to use the system of booking tickets *n); printf(*n); printf(* You can choose the operation: *n); printf(* 1:录入班次(Insert a train information) *n); printf(* 2:浏览信息(scan the information) *n); printf(* 3:查询信息(Inquire a train information ) *n); printf(* 4:预订车票(Book a train ticket) *n); printf(* 5:退订车票(quit a train ticket) *n); printf(* 6:退出系统 (quit the system) *n); printf(*n); /总菜单 printf(请选择你所需要的功能:); scanf(%d,&i); switch(i) case 1:Insert(); printf(n按任意键回主菜单.n);getchar();getchar();break; case 2:Scan();printf(n按任意键回主菜单.n);getchar();getchar();break; case 3:SearchMenu();break; case 4:Buyticket();break; case 5:TicketDelete();break; case 6:exit();break; default:printf(输入错误,请确保你的输入为1-6.n);break; /while (i!=6)Save_In(); /保存信息system(pause);return 0;void Insert() FILE *fp; fp=fopen(ticket.txt,r+); INFORMATION *q; q=(INFORMATION *)malloc(sizeof(INFORMATION); printf(请输入班次信息n); scanf(%d%s%s%s%f%d%d,&q-numb,&q-starttime,&q-begin,&q-end,&q-lasttime,&q-FixNumber,&q-FixedNumber); rear-next=q; rear=q; q-next=NULL; rear-next=NULL; fclose(fp); printf(信息已存入n); void input() /班次信息文件读入 FILE *fp; if(fp=fopen(ticket.txt,r+)=0) printf(n打开文件错误!n); exit(0); while(!feof(fp) /读取文件并测试是否抵达文件尾 INFORMATION *p; p=(INFORMATION *)malloc(sizeof(INFORMATION); /开辟内存空间 fscanf(fp,%d%s%s%s%f%d%dn,&p-numb,&p-starttime,&p-begin,&p-end,&p-lasttime,&p-FixNumber,&p-FixedNumber); rear-next=p; /在INFORMATION单链表中依次插入下一结点 rear=p; rear-next=NULL; fclose(fp); void Save_In() /保存数据 FILE *fp; if(fp=fopen(ticket.txt, r+)=0) printf(n打开文件错误!n); exit(0); PINF p=head-next; while(p!=NULL) fprintf(fp,%dt%st%st%st%.2ft%dt%dn,p-numb,p-starttime,p-begin,p-end,p-lasttime,p-FixNumber,p-FixedNumber); p=p-next; fclose(fp);void Scan() PINF p=head-next; printf(n各班次信息如下:n); printf(n班次号t出发时间t起点t终点t行车时间 额定载客量 已订票人数n); printf(_n); while(p!=NULL) printf(%dt%stt%st%st%.2ftt%dtt%dn,p-numb,p-starttime,p-begin,p-end,p-lasttime,p-FixNumber,p-FixedNumber); p=p-next; printf(_n);void SearchMenu() /查询班次信息 system(color 5f); /system(mode con: cols=140 lines=130); void SearchbyNum(); /函数声明 void SearchbyEnd(); /函数声明 int i,j=0; while(j!=1) printf(n); printf( 查询子菜单n); printf(=n); printf( 1.按班次号查询tn); printf( 2.按终点站查询tn); printf(=n); printf(请选择查询方式:); scanf(%d, &i); switch(i) case 1: SearchbyNum(); break; case 2: SearchbyEnd(); break; default : printf(n输入错误,请确保你的输入为1-2.n); break; printf(=n); printf(n1.返回主菜单 2.继续查询 : ); scanf(%d,&j); void SearchbyNum() /按班次号查询班次 system(color 5f); / system(mode con: cols=140 lines=130); int GetHour(char *s); int GetMinute(char *s); PINF p,q; /定义两个结点 int num; /要查询的班次号 int j=0; /判断班次 p=head-next; printf(n请输入需要查询的班次号: ); scanf(%d,&num); while(p!=NULL) if(p-numb-num=0) q=p; printf(n); printf(班次号: t);printf(%dn,q-numb); printf(出发时间:t);printf(%sn,q-starttime); printf(起点: tt);printf(%sn,q-begin); printf(终点: tt);printf(%sn,q-end); printf(行车时间: t);printf(%.2fn,q-lasttime); printf(额定载客量: t);printf(%dn,q-FixNumber); printf(已定票人数: t);printf(%dn,q-FixedNumber); time_t t; struct tm *timeinfo; time(&t); timeinfo = localtime(&t); if(GetHour(q-starttime)tm_hour) printf(n此班次车已发出!n); else if(GetHour(q-starttime) = timeinfo-tm_hour) if(GetMinute(q-starttime)tm_min) printf(n此班次车已发出!n); else printf(n此班次车尚未发出!n); else printf(n此班次车尚未发出!n); j+; p=p-next; /while(p!=NULL) if(j=0) printf(n对不起,不存在此班次!n);void SearchbyEnd() /按终点站查询班次 system(color 5f); /system(mode con: cols=140 lines=130); int GetHour(char *s); int GetMinute(char *s); PINF p,q; /定义两个结点 char end21; /要查询的终点站名 int j=0; p=head-next; printf(n请输入需要查询的终点站名: ); scanf(%s,end); while(p!=NULL) if(strcmp(p-end,end)=0) q=p; printf(n); printf(班次号: t);printf(%dn,q-numb); printf(出发时间:t);printf(%sn,q-starttime); printf(起点: tt);printf(%sn,q-begin); printf(终点: tt);printf(%sn,q-end); printf(行车时间: t);printf(%.2fn,q-lasttime); printf(额定载客量: t);printf(%dn,q-FixNumber); printf(已定票人数: t);printf(%dn,q-FixedNumber); time_t t; struct tm *timeinfo; time(&t); timeinfo=localtime(&t); if(GetHour(q-starttime)tm_hour) printf(n此班已发出!n); else if(GetHour(q-starttime)=timeinfo-tm_hour) if(GetMinute(q-starttime)tm_min) printf(n此班已发出!n); else printf(n此班次车尚未发出!n); else printf(n此班次车尚未发出!n); j+; p=p-next; /while(p!=NULL) if(j=0) printf(n对不起,不存在此班次!n); void Buyticket() /预定车票 system(color 5f); /system(mode con: cols=140 lines=130); int GetHour(char *s); int GetMinute(char *s); int i=0; Scan(); while(i!=1) int num,j=0; PINF p,q; /定义两个结点 p=head-next; time_t t; struct tm *timeinfo; time(&t); timeinfo=localtime(&t); printf(n请输入你要购买的班次号:); scanf(%d,&num); while(p!=NULL) if(p-numb-num=0) q=p; j+; if(q-FixedNumberFixNumber) if(GetHour(q-starttime)timeinfo-tm_hour) printf(n你已订票成功,请按时上车,谢谢使用!n); q-FixedNumber+; else if(GetHour(q-starttime)=timeinfo-tm_hour) & (GetMinute(q-starttime)timeinfo-tm_min) printf(n你已订票成功,请按时上车,谢谢使用!n); q-FixedNumber+; else printf(n对不起,该班次车已经发出,请明天再来!谢谢使用!n); else printf(n对不起,该班次车已经发出,请明天再来!谢谢使用!n); p=p-next; if(j=0) printf(n对不起,不存在此班次!谢谢使用!n); printf(=n); printf(n1. 返回主菜单 2. 继续订票 : ); scanf(%d,&i); /while(i!=1)void TicketDelete() /退订车票 system(color 5f); /system(mode con: cols=140 lines=130); int GetHour(char *s); int GetMinute(char *s); int i=0; while(i!=1) PINF p,q; p=head-next; int num,j=0; time_t t; struct tm *timeinfo; time(&t); timeinfo=localtime(&t); printf(n请输入你要退票的班次号:); scanf(%d,&num); while(p!=NULL) if(p-numb-num=0) q=p; j+; if(GetHour(q-starttime)timeinfo-tm_hour) printf(n你已退票成功,谢谢使用!n); q-FixedNumber-; else if(GetHour(q-starttime)=timeinfo-tm_hour)&(GetMinute(q-starttime)timeinfo-tm_min) printf(n你已退票成功,谢谢使用!n); q-FixedNumber-; else printf(n对不起,该班次车已经发出,不能退票!谢谢使用!n); p=p-next; if(j=0) printf(n对不起,输入错误,不存在此班次车!谢谢使用!n); printf(=n); printf(n1. 返回主菜单 2. 继续退票 : ); scanf(%d,&i); int GetHour(char *s) char *p,*q; p=(char *)malloc(10); strcpy(p,s); q=p; while(*q!=:) q+; *q=0; return atoi(p); /字符串到浮点数的转换 int GetMinute(char *s) char *p; p=(char *)malloc(10); strcpy(p,s); while(*p!=:) p+; p+; return atoi(p); void exit()printf(nn*谢谢使用本系统,欢迎下次继续使用*n);exit(0); 建立一个文本文档“tic
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 绵阳市盐亭县医疗卫生辅助岗招募考试真题2024
- 测绘考试题及答案
- 果实考试题及答案
- 中级微观经济学(对外经济贸易大学)知到智慧树答案
- 中外设计艺术史知到智慧树答案
- 药品召回管理办法试题附答案
- 药品GMP厂房与设施、设备培训考试题(附答案)
- 2025年度船舶租赁与船舶改造升级合同
- 2025年新型手机合约机抵押租赁服务合同
- 2025版智能化工厂临时保洁服务合同
- 湖北省圆创高中名校联盟2026届高三第一次联合测评 语文试卷(含答案)
- 2025秋苏教版(2024)小学科学二年级上册(全册)课时练习及答案(附目录)
- 巡察整改工作课件模板
- 医务人员职业道德准则理论试题
- 2025年城镇燃气条例竞赛题库
- GB/T 22030-2025车用乙醇汽油调合组分油
- 肺癌的护理新进展
- 2025年煤炭矿山职业技能鉴定考试-综采考试历年参考题库含答案解析(5套100道单选题合辑)
- 车务段安全培训课件
- DB42T 1891-2022 人防工程防护及防化通风设备安装标准
- 2025发展对象考试题及答案
评论
0/150
提交评论