




已阅读5页,还剩28页未读, 继续免费阅读
版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
学生实习报告 课程名称_ 数据结构与数据处理应用训练 题目名称 学生学院 专业班级 学 号 学生姓名 指导教师 2014 年 2 月 日XXX计算分院 计算1103【摘要】 模拟铁路客运售票系统,采用链表结构储存数据,有订票、退票、查询、修改、读取文件等功能模块,整体系统运行为一个无限循环,根据输入指令进行不同操作,主要知识有结构的定义,链表的操作,循环的应用。 【关键词】 铁路客运售票模拟系统,查询车次,车票预订,办理退票1 内容与要求铁路客运售票模拟系统【问题描述】铁路客运售票系统的业务活动包括:查询车次、车票预订和办理退票。试设计一个铁路客运售票模拟系统,使上述业务可以借助计算机来完成。【具体要求】铁路客运售票处的计算机系统可以为客户提供下列各项服务:1查询车次:根据旅客提供的出发站、到达站、出发日输出下列信息:车次号、出发站、到达站、出发时间、到达时间、各类车票的余票额(包括软卧、硬卧、软座、硬座、无座)等。还可根据客户要求,输出某车次从起点站到终点站的各站点的名称及出发时间和到达时间。2. 承办订票业务:根据客户提出的要求(日期、车次号、座位类别、订票数额)查询该车次该座位类别票额情况,若尚有余额,则为客户办理订票手续,并输出座位号(座位号信息的输出可作为选做部分);若无票或余票额少于订票额,则需要重新询问客户要求。若客户需要,可预约登记排队等候。3承办退票业务:根据客户提供的情况(日期、车次号、座位类别、退票数额),为客户办理退票手续,然后查询该车次该座位类别是否有人预约登记,首先询问排在第一的客户,若退票数能满足他的要求,则为他办理订票手续,否则依次询问其他排队预约的客户。为简化问题,可以规定同一个座位只能售出一次票,即不考虑同一个座位分不同路段出售多次。还可规定只能查询或预订未来3天之内的车票,即每个车次只需分别保存3个班次的售票情况。【实现提示】每个车次应包含的信息有:车次号、出发日、起点站名、各中途站名、终点站名、各站点的到达时间与出发时间、各类座位车票定额、各类座位余票额、各座位是否已售出信息(选做内容,可用一张表记录每个座位是否已售出)、各类座位已订票的客户名单(包括姓名、出发站、到达站、订票额、座位号(选做)和各类座位预约登记的客户名单(包括姓名、出发站、到达站、所需票额)。这最后两项显然可以分别用线性表和队列实现(每一类别的座位需有各自的线性表和队列)。为查找方便,已订票客户的线性表应按客户姓名有序,并且,为插入和删除方便,应以链表作存储结构;由于预约人数无法预料,队列也应以链表作存储结构。整个系统需汇总各车次的情况记录在一张线性表上,由于车次基本不变,可采用顺序存储结构,并按车次有序,因为每个车次需保存未来3天的售票情况,可考虑每个车次的每一班次是这张表上的一个记录,也可以每个车次是一个记录,里面分别包含3趟班次的售票情况。每个记录需定义成一个结构类型。【测试数据】自己设计,报告上要求写出多批数据测试结果。【实现说明】每个同学可以根据自己的实际情况对该铁路客运售票模拟系统的功能进行增减。有能力的同学在完成上述功能的基础上,可以充分发挥自己的想象力,增加该系统的功能和其它服务项目,如可以按照实用性来完善上述模拟系统,考虑输出座位号信息、同一个座位允许分不同路段出售多次等;能力较弱的同学则可以简化上述系统,如不考虑预约登记排队等候车票、不考虑各种座位类别(即每个车次只有一种座位)、还可以不考虑中途站点(即每个车次只设置起点站与终点站,中间不停)等。2 总体设计3 详细设计路线信息typedef struct trainline /路线 char date9;/日期 char train_num8;/车次号 struct station *sta;/途经站char begin_time6;/出发时间char end_time6;/到达时间int RW;/软卧余量 int YW;/硬卧余量int RZ;/软座余量int YZ;/硬座余量int WZ;/无座余量struct trainline *next;/下一个节点trainline;停靠站点信息typedef struct station/停靠站char stop9;/停靠站名char stop_time;/停靠时间struct station *next;/下一个节点station;乘客订票信息typedef struct customer /乘客 char name9;/顾客名 char date9;/日期 char train_num9;/车次号 int seat_level;/座位类别int seat_num;/座位数量 struct customer *next;/下一个节点 customer;找到路线链表中的末尾节点status increase_train(trainline *l,char *date,char *train_num, station *stat,char *begin_time,char *end_time, int RW,int YW,int RZ,int YZ,int WZ)/增加路线将需要插入的路线信息插入到链表中指定节点之后status insert_trainline(trainline *p,char *date,char *train_num,station *stat,char *begin_time,char *end_time,int RW,int YW,int RZ,int YZ,int WZ)/trainline链表插入操作将需要插入的乘客订票信息插入到链表中status insert_customer(customer *p,char *name,char *date,char *train_num,int seat,int seat_num)/customer链表插入操作删除某条路线,首先搜索到该路线,然后在链表中跳过该节点status delete_trainline(trainline *h,char *date,char *train_num)/删除路线删除某条乘客订票记录,首先搜索到该记录,然后在链表中跳过该节点status delete_customer(customer *h,char *date,char *train_num)/删除顾客修改路线座位余量,首先搜索到该路线,然后删除对应的座位类别的余量trainline *modefy_trainline(trainline *l,char *date,char *train_num,int seat_level,int num) /修改trainline链表中的数据退票,首先搜索到该订票记录,然后确定退票数量,如果大于订票数量,则减去退票数量;如果等于退票数量,则删除此订票记录;如果小于,则输出数量不足,退票失败。如果退票成功,则路线中相应座位余量增加。status delete_cus(customer *h,trainline *l,char *name, char *date,char *train_num,int level,int num)/乘客退票以下两个函数是为了方便操作所赋予的初始化数据status creat_trainline(trainline *l)/创建trainline单链表status creat_customer(customer *l)/创建customer单链表订票查询,根据提供站点,查找路线,判断同意路线中是否有这两个站点,并且顺序正确void book_search(trainline *l,char *begin_place,char *end_place)/订票查询函数订票,首先找到该车次,然后判断余量是否够,如果够,则订票;反之,订票失败。订票成功,则增加乘客订票记录,兵减少相应车次的座位余量。status book(trainline *l,char *date,char *train_num,customer *c,char *name,int seat_level,int num)/订票函数根据路线链表和乘客链表逐个输出信息status print_trainline(trainline *l)/打印路线信息status print_customer(customer *l)/打印乘客信息根据路线链表和乘客链表,逐个在 C盘 trainline.dat 和 customer.dat 文件中输出信息status save_trainline(trainline *l)/保存trainline.datstatus save_customer(customer *l)/保存乘客信息 customer.dat从 C盘 trainline.dat 和 customer.dat 文件中读取记录,并用订票和增加路线函数逐条添加到系统中status load_trainline(trainline *l) /导入路线信息,必须为5个站status load_customer(customer *l) /导入乘客信息4 程序测试3 查询路线、乘客信息status print_trainline(trainline *l)/打印路线信息status print_customer(customer *l)/打印顾客信息1 订票 首先查询 出发站-终点站 void book_search(trainline *l,char *begin_place,char *end_place)/订票查询函数然后根据查询结果购买自己需要车次 status book(trainline *l,char *date,char *train_num,customer *c,char *name,int seat_level,int num)/订票函数订票后的查询结果2 退票 (可以全部退完,也可以退一部分) status delete_cus(customer *h,trainline *l,char *name,char *date,char *train_num,int level,int num)/乘客退票退票后查询结果4 修改路线 默认密码12345678 代码:pass9=123456781 增加路线 status increase_train(trainline *l,char *date,char *train_num, station *stat,char *begin_time,char *end_time, int RW,int YW,int RZ,int YZ,int WZ)/增加路线注意时间“:”为英文字符,输入中文字符会报错增加路线后查询结果2 删除路线删除路线后查询结果5 读入文件 status load_trainline(trainline *l) /导入路线信息,必须为5个站status load_customer(customer *l) /导入乘客信息隐藏密码函数status inputpassword(char cc9)/隐藏密码为*号的函数系统存档status save_trainline(trainline *l)/保存trainline.datstatus save_customer(customer *l)/保存顾客信息 customer.dat每完成一轮操作 系统自动存档一次,如果需要继续上一回的存档,请打开后直接选5读入存档5 总结参考文献1.徐孝凯.数据结构实用教程.清华大学出版社.2006.9附录Slove.h#define OK 1 #define TRUE 1 #define FALSE 0 #define ERROR 0 #define OVERFLOW -2 #define PR printf #define RUANW 1 #define YINGW 2#define RUANZ 3#define YINGZ 4#define WUZ 5typedef int status; typedef struct trainline /路线 char date9;/日期 char train_num8;/车次号 /char begin_place9;/出发地/char end_place9;/目的地struct station *sta;/途经站char begin_time6;/出发时间char end_time6;/到达时间/int total;/座位总数/int left;int RW;/软卧余量 int YW;/硬卧余量int RZ;/软座余量int YZ;/硬座余量int WZ;/无座余量struct trainline *next;/下一个节点trainline; typedef struct station/停靠站char stop9;/停靠站名char stop_time;/停靠时间struct station *next;/下一个节点station;typedef struct customer /乘客 char name9;/顾客名 char date9;/日期 char train_num9;/车次号 int seat_level;/座位类别int seat_num;/座位数量 struct customer *next;/下一个节点 customer; station *init_station()/初始化途经站station *l;l=(station*)malloc(sizeof(station); if(l=NULL) exit(0); l-next=NULL; return l; trainline *init_trainline() /初始化路线链表 trainline *l; l=(trainline*)malloc(sizeof(trainline); if(l=NULL) exit(0); l-next=NULL; return l; customer * init_customer()/初始化乘客链表 customer *l; l=(customer*)malloc(sizeof(customer); if(l=NULL) exit(0);l-next=NULL; return l; status insert_trainline(trainline *p,char *date,char *train_num,/char *begin_place,char *end_place,station *stat,char *begin_time,char *end_time,int RW,int YW,int RZ,int YZ,int WZ)/trainline链表插入操作 trainline *q; q=(trainline*)malloc(sizeof(trainline); strcpy(q-date , date); strcpy(q-train_num , train_num); /strcpy(q-begin_place , begin_place); /strcpy(q-end_place , end_place); q-sta=stat;strcpy(q-begin_time , begin_time); strcpy(q-end_time , end_time); q-RW =RW; q-YW =YW; q-RZ =RZ; q-YZ =YZ;q-WZ =WZ; q-next=NULL; (*p)-next=q; (*p)=(*p)-next; /PR(insert %d ,%dis succssed!n,e,bl); return OK; status insert_customer(customer *p,char *name,char *date,char *train_num,int seat,int seat_num)/customer链表插入操作 customer *q; q=(customer*)malloc(sizeof(customer); /* PR(内存分配失败n); return OVERFLOW; */ strcpy(q-name , name); strcpy(q-date , date); strcpy(q-train_num , train_num);q-seat_level =seat; q-seat_num =seat_num; q-next=NULL; (*p)-next=q; (*p)=(*p)-next; /PR(insert %d ,%dis succssed!n,e,bl); return OK; status delete_trainline(trainline *h,char *date,char *train_num)/删除路线 trainline *p,*pr; pr=h; p=pr-next ; while(p!=NULL) if(strcmp(date,p-date )=0 & strcmp(train_num,p-train_num )=0) pr-next =p-next ; PR(删除 %s 车次n,p-date ); return OK; pr=pr-next ; p=pr-next ; PR(无此车次,无法删除!n); return ERROR; status delete_customer(customer *h,char *date,char *train_num)/删除顾客 customer *p,*pr; pr=h; p=pr-next ; while(p!=NULL) if(strcmp(date,p-date )=0 & strcmp(train_num,p-train_num )=0) pr-next =p-next ; pr=pr-next ; p=pr-next ; return OK; trainline *modefy_trainline(trainline *l,char *date,char *train_num,int seat_level,int num) /修改trainline链表中的数据 trainline *p; p=l-next ; for(;p!=NULL;p=p-next ) if(strcmp(date,p-date )=0 & strcmp(train_num,p-train_num )=0) if(seat_level = RUANW) p-RW += num; else if(seat_level = YINGW) p-YW += num;else if(seat_level = RUANZ) p-RZ += num;else if(seat_level = YINGZ) p-YZ += num;else if(seat_level = WUZ) p-WZ += num;/ PR(modefy %sn,p-line_num ); return l; PR(没有这个路线,无法完成修改任务!n); return 0; status delete_cus(customer *h,trainline *l,char *name,char *date,char *train_num,int level,int num)/乘客退票 customer *p,*pr; int seat_num;/ qr=h; pr=h; p=pr-next ; / PR(开始删除n); while(p!=NULL) if(strcmp(name,p-name )=0 & strcmp(date,p-date )=0 & strcmp(train_num,p-train_num )=0 & level=p-seat_level) seat_num=p-seat_num;l=modefy_trainline(l,date,train_num,level,num); if(num = seat_num)pr-next =p-next ; PR(乘客 %s 退票成功!n,p-name ); else if(num seat_num -= num;PR(乘客 %s 退票成功!n,p-name );else PR(数量不足,退票失败!n,p-name ); return OK; pr=pr-next ; p=pr-next ; PR(无此顾客,无法退票!n); return ERROR; status creat_trainline(trainline *l)/创建trainline单链表 trainline *p=*l; int i=0; char *date3=20140224,20140226,20140225; char *train_num3=T01,D02,G03; char place359=北京,杭州,上海,南昌,广州, 广州,上海,金山,北京,敦煌, 嘉兴,北京,上海,山西,深圳;station *stat3;for(i=0;i3;i+)stati=init_station();for(int j=0;jstop,placeij);/可以在这里加停靠时间st-next=stati;stati=st;/stati-next=NULL;char *begin_time3=12:02,22:42,05:09; char *end_time3=17:15,06:07,10:54; int RW3=100,100,100; int YW3=100,100,100; int RZ3=100,100,100;int YZ3=100,100,100;int WZ3=100,100,100;for (i=0;i3;i+) insert_trainline(&p,datei,train_numi,stati,/begin_placei,end_placei, begin_timei,end_timei,RWi,YWi,RZi,YZi,WZi); return OK; status creat_customer(customer *l)/创建customer单链表 customer *p=*l; int i=0; char *name3=yangj,yunhl,fangs; char *date3=20140224,20140225,20140226; char *train_num3=T01,G03,D02; int seat_level3=RUANW,YINGZ,WUZ; int seat_num3=2,3,4;for (i=0;inext ; for(;p-next !=NULL;p=p-next) insert_trainline(&p,date,train_num,stat,/begin_place,end_place, begin_time,end_time,RW,YW,RZ,YZ,WZ); PR(增加车次 %s %s 成功!n,date,train_num); return OK; status book(trainline *l,char *date,char *train_num,customer *c,char *name,int seat_level,int num)/订票函数 trainline *p=l; customer *q=c-next ; p=l-next ; for(;q-next !=NULL;q=q-next) / PR(%sn,q-name ); for(;p!=NULL;p=p-next ) if(strcmp(date,p-date )=0) if(seat_level = RUANW & p-RW 0) PR(恭喜您!订票成功!n); insert_customer(&q,name,date,train_num,seat_level,num); p-RW -=num; return OK; else if(seat_level = YINGW & p-YW 0) PR(恭喜您!订票成功!n); insert_customer(&q,name,date,train_num,seat_level,num); p-YW -=num; return OK; else if(seat_level = RUANZ & p-RZ 0) PR(恭喜您!订票成功!n); insert_customer(&q,name,date,train_num,seat_level,num); p-RZ -=num; return OK; else if(seat_level = YINGZ & p-YZ 0) PR(恭喜您!订票成功!n); insert_customer(&q,name,date,train_num,seat_level,num); p-YZ -=num; return OK; else if(seat_level = WUZ & p-WZ 0) PR(恭喜您!订票成功!n); insert_customer(&q,name,date,train_num,seat_level,num); p-WZ -=num; return OK; else PR(对不起,余量不足!n); return 0; PR(对不起,没有这个路线号!n); return ERROR; void book_search(trainline *l,char *begin_place,char *end_place)/订票查询函数 trainline *p=l; /customer *q=c-next ; p=l-next ; /for(;q-next !=NULL;q=q-next) / PR(%sn,q-name ); for(;p!=NULL;p=p-next ) station *st=p-sta;int stop_begin=0,stop_end=0,flag=1;for(;st-next!=NULL;st=st-next)if(strcmp(begin_place,st-stop )=0) stop_begin=flag+;if(strcmp(end_place,st-stop )=0) stop_end=flag+;if(stop_begin=1 & stop_end=2)PR(%15s%5s%12s%c%5s%10d%5d%5d%5d%5dn,p-date ,p-train_num , /p-begin_place ,-,p-end_place ,p-begin_time ,-,p-end_time , p-RW ,p-YW,p-RZ ,p-YZ ,p-WZ ); station *st=p-sta;PR(途经: );for(;st-next!=NULL;st=st-next)PR(%s ,st-stop);PR(n);break; status print_trainline(trainline *l)/打印路线信息 trainline *p=l-next ; for(;p!=NULL;p=p-next ) PR(%15s%5s%12s%c%5s%10d%5d%5d%5d%5dn,p-date ,p-train_num , /p-begin_place ,-,p-end_place , p-begin_time ,-,p-end_time , p-RW ,p-YW,p-RZ ,p-YZ ,p-WZ ); station *st=p-sta;PR(途经: );for(;st-next!=NULL;st=st-next)PR(%s ,st-stop);PR(n); return OK; status print_customer(customer *l)/打印顾客信息 customer *p=l-next ; for(;p!=NULL;p=p-next ) PR(%5s %9s %5s %6d %6dn,p-name ,p-date ,p-train_num ,p-seat_level ,p-seat_num ); return OK; status save_trainline(trainline *l)/保存trainline.dat FILE *fp_trainline; trainline *p=l-next ; char filename=c:trainline.dat; if(fp_trainline=fopen(filename,wb)=NULL) printf(can not open file to write:%sn,filename); return ERROR; for(;p!=NULL;p=p-next ) fprintf(fp_trainline,%s,%s,%s,%s,%d,%d,%d,%d,%d,p-date ,p-train_num , /p-begin_place ,p-end_place , p-begin_time ,p-end_time ,p-RW ,p-YW ,p-RZ ,p-YZ ,p-WZ ); station *st=p-sta;for(;st-next!=NULL;st=st-next)fprintf(fp_trainline,%s,st-stop);fprintf(fp_trainline,#); fclose(fp_trainline); return OK; status save_customer(customer *l)/保存顾客信息 customer.dat FILE *fp_customer; customer *p=l-next ; char filename=c:customer.dat; if(fp_customer=fopen(filename,wb)=NULL) printf(can not open file to write:%sn,filename); return ERROR; for(;p!=NULL;p=p-next ) / PR(%s,%s,%dn,p-name ,p-line_num ,p-seat_num ); fprintf(fp_customer,%s,%s,%s,%d,%d,#,p-name ,p-date ,p-train_num ,p-seat_level ,p-seat_num ); fclose(fp_customer); return OK; int changStrInt(char *ch)/把字符串转化为整型 int a=1,b=0,c=0,i; for (i=strlen(ch)-1;i=0;i-) if (chi47) b=a*(chi-48); a=a*10; c=c+b; else PR(%c 不合法,无法将此字符串转化为整形!n,chi); return 0; / printf(the c is %dn,c); return c; status load_trainline(trainline *l) /导入路线信息,必须为5个站FILE *fp_trainline; int flag=0,i=0; char ch; char date9;/日期 char train_num9;/车次号 char begin_time6,end_time6;/时间char RW_str5,YW_str5,RZ_str5,YZ_str5,WZ_str5;/座位余量字符串int RW,YW,RZ,YZ,WZ;/座位余量 char place9;/站名station *sta=init_station();/途经站/ trainline *p=l; char filename=c:trainline.dat; if(fp_trainline=fopen(filename,rb)=NULL) printf(can not open file to load:%sn,filename); return ERROR; while(!feof(fp_trainline) ch=fgetc(fp_trainline); if(ch!=#) if(flag=0&ch!=,) datei=ch; i+; else
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
评论
0/150
提交评论