数据结构课程设计之飞机订票系统.doc_第1页
数据结构课程设计之飞机订票系统.doc_第2页
数据结构课程设计之飞机订票系统.doc_第3页
数据结构课程设计之飞机订票系统.doc_第4页
数据结构课程设计之飞机订票系统.doc_第5页
已阅读5页,还剩27页未读 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

青岛理工大学数据结构课程设计报告题目:飞机订票系统院(系): 学生姓名: 班级: 学号:起迄日期: 指导教师: 指导教师评语: 成绩: 签名: 年 月 日20102011年度 第 2 学期 一、需求分析 1.问题描述:设计一个模拟飞机订票系统,通过此系统可以录入、查询、修改航班情况,完成用户订票和退票功能,并且可以保存客户和航班的资料。 2.基本功能 1, 录入航班信息。 没个航班的信息包括:航班号,起飞、抵达城市,座位总数,剩余座位数。数据由使用者输入。 数据存储在txt文件中,采用线性表的链式结构。2, 加载航班和客户信息。 可以自动加载保存在txt文件中的航班和客户的信息。3, 查询航班。可以通过输入航班号,查询该航班的所有信息。可以通过输入起飞抵达的城市,查询航班的信息。4, 订票。客户的信息包括:姓名,证件号,所订票的航班号,座号。用户输入要订票的航班号,如果该航班未满,则订票成功,并记录客户的信息。如果该航班已满,则订票失败,输出所有未满的航班信息,供用户选择。5, 退票。删除退票用户的订票信息,相应的航班的剩余票数增加1。6, 修改航班信息。用户输入要修改的航班号,和要修改的内容,修改该航班的相应信息。7, 保存操作。把当前的航班信息,和用户信息分别保存在txt文件中。8, 输出所有客户信息。按一定的格式输出用户的姓名,证件号码,航班号,座号。9, 输出所有航班信息。按一定的格式输出所有的航班的航班号,起飞抵达城市,座位总数,剩余座位数。0, 退出系统。 3.输入输出 在控制台下,根据提示输入要完成功能的标号,然后在提示下选择性的输入航班号、起飞抵达地、证件号码,或者姓名等。系统会根据用户的输入输出相应的航班信息或者用户信息。二、 概要设计1.设计思路:对于航班和用户,分别定义不同的数据结构,并且采用线性表的链式结构进行存储。然后根据要完成的功能,分模块用函数实现。所用到的算法主要有:链表的创建,增加,遍历,插入,删除。 2.数据结构设计: 采用的逻辑结构是线性结构。存储结构是链式结构。/航线结构体。typedef struct airline char line_num10;/航班号char start_place20;/起飞地char end_place20;/目的地int total;/座位总数int left;/剩余座位struct airline *next;/下一个结点airline;/航线结构体的头结点。typedef struct airlinehead int count;airline *next;airlinehead;/客户结构体typedef struct client char name20;/顾客名char id10;/顾客证件号char line_num10;/航班号int seat_num;/座位号struct client *next;/下一个结点client;/客户结构体的头结点。typedef struct clienthead int count;client *next;clienthead;采用线性链表的原因:1,航班情况和客户信息与均成线性,与线性表的结构相符合。2,由于本系统对数据的插入和删除较频繁,所以更适合链式存储结构。3.软件结构设计:/*对航班的操作*/airlinehead* import(int n,airlinehead *pheadline)/录入航班函数,n为所要录入航班的数量;airline* query(airlinehead *phead )/查询航班情况void display_line(airline *node)/打印一个航班结点的所有信息到屏幕void display_all_line(airlinehead *headline)/打印所有航班的信息到屏幕int change_line(airlinehead *headline)/修改航班信息。void display_left_airline(airlinehead *headline)/输出未售完票的航班的信息/*对客户的操作*/void display_client(client *node=NULL)/打印一个客户节点的信息到屏幕。void display_all_client(clienthead *headclient)/打印所有客户信息到屏幕。int bookticket(airlinehead * headline,clienthead *headclient)/订票int returnticket(airlinehead * headline,clienthead *headclient)/退票。/*对文件的操作*/int savemessage(airlinehead *headline,clienthead *headclient)/保存航班和客户的信息到相应的txt文件中。int loadmessage(airlinehead *headline,clienthead *headclient)/加载保存在文件中的信息。模块之间的关系框图:三、 详细设计 1. 定义程序中所有用到的数据及其数据结构,及其基本操作的实现;/航线结构体。typedef struct airline char line_num10;/航班号char start_place20;/起飞地char end_place20;/目的地int total;/座位总数int left;/剩余座位struct airline *next;/下一个结点airline;/航线结构体的头结点。typedef struct airlinehead int count;airline *next;airlinehead;/客户结构体typedef struct client char name20;/顾客名char id10;/顾客证件号char line_num10;/航班号int seat_num;/座位号struct client *next;/下一个结点client;/客户结构体的头结点。typedef struct clienthead int count;client *next;clienthead;2主函数和其他函数的算法;/*主函数*/void main()airlinehead *headline = new airlinehead;headline-count=0;headline-next=NULL;clienthead *headclient = new clienthead;headclient-count=0;headclient-next=NULL;while(1)main_menu();int n;coutn;coutendl;switch(n)case 1:int num;coutnum;coutendl;import(num,headline);coutendl;/display_all_line(headline);cout航班信息成功录入。;coutendlendl;break;case 2:loadmessage(headline,headclient);break;case 3:airline *find;find=query(headline);if(find)display_line(find);break;case 4:bookticket( headline,headclient);/display_all_client(headclient);break;case 5:returnticket(headline,headclient);break;case 6:savemessage(headline,headclient);break;case 7:display_all_line(headline);break;case 8:display_all_client(headclient);break;case 0:exit(1);break;/*订票函数的实现*/int bookticket(airlinehead * headline,clienthead *headclient) /订票coutline_num;airline *temp;temp=headline-next;while(temp)if(strcmp(temp-line_num,line_num)=0)break;temp=temp-next;if(!temp)cout未找到该航班left=0)cout对不起,该航班票已经售完。endl;cout请选择其他合适的航班:;client *custom=new client;coutcustom-id;coutendl;coutcustom-name;coutseat_num=temp-total - temp-left + 1;custom-next=NULL;strcpy(custom-line_num,line_num);temp-left-;headclient-count+;custom-next = headclient-next;headclient-next = custom;cout订票成功,祝您旅途愉快。;return 1;/*退票函数的实现*/int returnticket(airlinehead * headline,clienthead *headclient)/退票。coutid;airline *airlinetemp= headline-next;client *clienttemp= headclient-next;if(NULL=airlinetemp)cout当前没有航班信息。id,id)=0)/要删除的节点为第一个时。strcpy(line_num,clienttemp-line_num);headclient-next=clienttemp-next;delete clienttemp;while(airlinetemp)/修改对票客户所对应的航班的售票信息。if(strcmp(line_num,airlinetemp-line_num)= 0 )airlinetemp-left+;break;airlinetemp = airlinetemp-next;coutnext)/要删除 的节点不是第一个时。if(strcmp(clienttemp-next-id,id)=0)strcpy(line_num,clienttemp-next-line_num); delnext = clienttemp-next-next;delete clienttemp-next;clienttemp-next=delnext;/?while(airlinetemp)/修改对票客户所对应的航班的售票信息。if(strcpy(line_num,airlinetemp-line_num)= 0 )airlinetemp-left+;break;airlinetemp = airlinetemp-next;cout退票成功,生意不成仁义在,有机会继续合作。endlnext;cout未找到该客户的信息。endl;return 0;/*保存文件的实现*/int savemessage(airlinehead *headline,clienthead *headclient)/保存航班和客户的信息到相应的txt文件中。ofstream outline(airline.txt);if(!outline)cout航班信息文件打开失败。endl;return 0;cout正在保存航班信息.endl;outlinecountnext;while(linetemp)outlineline_num start_place end_place total left next;outline.close();cout航班信息保存成功.endl;ofstream outclient(client.txt);if(!outclient)cout客户信息文件打开失败。endl;return 0;cout正在保存客户信息文件.endl;outclientcountnext;while(clienttemp)outclientname id line_num seat_num next;outclient.close();cout客户信息保存成功。endl;return 1;3.主要函数的程序流程图: 4. 画出函数之间的调用关系图。四、 调试分析 1.实际完成的情况说明(完成的功能,支持的数据类型等);完成了所有预设的功能,可以实现航班的录入、查询、修改,和客户的订票、退票,保存信息的功能。2.程序的性能分析,包括时空分析;时间复杂度分析:在订票和退票函数中,都用到了链表的查询算法,时间复杂度为logn. 3.上机过程中出现的问题及其解决方案;调试过程中遇到的问题及解决方法:A, 语法错误,我的调试一个打开文件进行写入操作时遇到这样一个问题,char filename=”C:airline.dat”,fp=fopen “filename”,”wb”);调试了我一个半小时,还是没有找到问题的所在,最后发现是在filename上多了一对引号!B, 逻辑错误,声明一个指针只是在内存中开辟了一个这种数据类型的空间,并让这个指针指向它,由于它还没有指向任何变量,因此不能引用其指向的任何成员。4.程序中可以改进的地方说明;考虑到实际操作过程中的情况,可以设定每个客户的订票上限,和每一张票的价格,以及退票时要扣掉的费用。五、测试结果1,测试所用到的数据如下。航班号起飞城市抵达城市座位总数123ChinaAmerica30456JapanVietnam30789ChianEnglan30姓名证件号码航班犀利哥2012123春哥2013123凤姐2014789姓名证件号码航班测试结果:,六、用户手册一, 录入航班信息:打开系统会出现主界面,输入1后回车,系统会提示要输入航班的个数,航班号,起飞地,目的地,座位总数。依次输入二,加载航班信息:打开系统,在主界面输入2.系统会自动加载上次保存的航班信息及客户信息。操作如图:三, 查询航线信息。选择航线查询功能后,会出现如图界面:可以根据需要选择1,或者2.然后根据提示输入必要的数据。系统会输出航线信息。四, 客户订票。在主界面选择4,然后依次输入航班号,证件号,姓名。操作如图:五, 客户退票选择5,然后输入证件号,操作如图:六, 保存操作,输出所有航班信息,输出所有客户信息。选择保存操作后,系统将把您对数据的修改情况覆盖源文件的信息,以txt形式保存在根目录下。选择输出所有航班信息后,系统将输出所有航班的信息。选择输出所有客户信息后,系统将输出所有客户的信息。七、体会与自我评价 做课程设计的这些天有些累,但更多的是充实。有时候一个bug没能解决,睡觉时脑袋里也全是代码。这西天收获的绝对不仅仅是完成了课程设计,我还体会到了写完程序时带来的那种成就感,锻炼了自己的逻辑思维能力。另外,我感觉一个好的的程序并不只是可以运行,它还应该满足一大堆的条件,如健壮性,可读性,可维护性,高效性,等等。要提高自己的编程能力,你必须亲自去体验、去设计、编辑、编译、调试、运行。开始的时候没有认识到算法的重要性,以为语言是程序设计的基础和核心,随着学习的深入,我渐渐认识到,只有好的算法才能写出出类拔萃的的程序。只有对算法的深入理解,和知道如何使用相应的算法设计相应的程序,才能完成程序设计。实训中深切体会到了老师认真负责的伟大的精神和热情为同学指导的促学方式, 虽 然对有些时候老师没给我们指出解决问题的方法有些小抱怨, 但是到了结束时才知道, 这种 教学让我们自己学会了自学,学会了去看懂别人的代码.更多是老师给的感动,每天在我们 来之前就到了教室, 在讲课中海给我们分享他在公司上班的一些心得和体会, 还有那些我们 应该注意的事项,这些是平时上课时无法学到的,是更深层次的巨大收获.在此之前,我也以为自己对C语言已经比较懂了,可还是遇到了一系列问题,也学到很多东西。每一个程序员都是在失败、尝试、失败、尝试与收获中成长起来的。作为一个团团的计算机学院,大部分学生对计算机竟不大感兴趣,导致学院人才凋零。我本学识尚浅,无权谈论这些,只是希望能对大家有所警醒,编程之道漫漫无边,吾将上下而求索.最后以林锐先生的话来作为自己的追求目标和最后的结束语:以振兴民族软件产业为己任,作真实、正值、优秀的科技人员!源代码#include#includeusing namespace std;#include#includetypedef struct clientchar name20;/顾客名char id10;/顾客证件号char line_num10;/航班号int seat_num;/座位号struct client *next;/下一个结点client;typedef struct clientheadint count;client *next;clienthead;typedef struct airlinechar line_num10;/航班号char start_place20;/起飞地char end_place20;/目的地int total;/座位总数int left;/剩余座位struct airline *next;/下一个结点airline;typedef struct airlineheadint count;airline *next;airlinehead;airlinehead* import(int n,airlinehead *pheadline)/录入航班函数,n为所要录入航班的数量;airline *temp = new airline;temp-next=NULL;pheadline-next=temp;pheadline-count = n;for(int i=0;in;i+)cout请输入第i+1temp-line_num;cout请输入第i+1temp-start_place;cout请输入第i+1temp-end_place;cout请输入第i+1temp-total;temp-left = temp-total;cout第i+1个航班成功录入。endl;if(inext = new airline;if(temp-next = NULL)cout分配内存失败next-next=NULL;temp = temp-next;return pheadline;airline* query(airlinehead *phead )/查询航班情况airline *find=NULL;airline *temp;cout*endl;cout* 1,按航线查询航班情况。 *endl;cout* 2,按起飞抵达城市查询航班情况。 *endl;cout*endl;coutselect;coutendl;switch(select)case 1:coutline_num;temp = phead-next;while(temp )if(strcmp(temp-line_num,line_num) = 0)find= temp;/display_line(find);return temp;break;elsetemp = temp-next;if(!temp)cout没有找到该航班的信息。endl;return NULL;break;case 2:char start_place20;/起飞地 char end_place20;/目的地coutstart_place;coutend_place;/airline *temp;temp = phead-next;while(temp)if(strcmp(temp-start_place,start_place)=0 & strcmp(temp-end_place,end_place) = 0) find = temp;/return temp;break;temp = temp-next;if(!temp)cout没有找到该航班的信息。endl;return NULL;break;default:cout输入错误。endl;break;return find;void display_line(airline *node)/打印一个航班结点的所有信息到屏幕if(node=NULL)cout参数为空,输出失败。endl;return;coutendl;cout航班号tt起飞地tt目的地tt座位总数t剩余座位tendl;coutline_numttstart_placettend_placetttotaltlefttendl;void display_all_line(airlinehead *headline)coutnext;if(!node)cout当前没有航班信息endl;return ;cout航班数目: countnext;int change_line(airlinehead *headline)/修改航班信息。cout当前所有航班的信息为:next;while(temp)display_line(temp);temp=temp-next;coutendl;cout请选择你要进行的操作:endl;cout1,增加航班。endl;cout2,删除航班。endl;cout3,修改当前航班的信息。select;cout3 | select1)cout输入错误。next = (airline*)malloc(sizeof(airline);temp-next = new airline;temp = temp-next;couttemp-line_num;couttemp-start_place;couttemp-end_place;couttemp-total;temp-left = temp-total;temp-next=NULL;headline-count+;cout增加成功。endl;break;case 2:coutline_num;airline * delline;delline = headline-next;while(delline)if(strcmp(delline-next-line_num, line_num)=0)airline *plink;plink = delline-next-next;/free(delline-next);delete delline-next;delline-next=plink;headline-count-;delline=delline-next;if(delline = 0)cout没有找到输入的航班号。endl;return 0;break;case 3:coutline_num3;temp = headline-next;while(temp)if(strcmp(temp-next-line_num, line_num3)=0)cout请选择要修改的内容:endl;cout-1,座位总数。-endl;cout-2,起始地址。-endl;cout-3,目的地址。-next;if(temp=0)cout没有找到输入的航班号。endl;return 0;break;return 1;void display_client(client *node=NULL)/打印一个客户节点的信息到屏幕。if(node=NULL)cout参数为空,输出失败。endl;return;coutendl;cout姓名tt证件号码t座号t航班ttendlendl;coutnamettidttseat_numttline_numttnext;if(!node)cout当前没有客户信息。next;void display_left_airline(airlinehead *headline)/输出未售完票的航班的信息。airline *node = headline-next;if(!node)coutleft!=node-total;node = node-next)display_line(node);int bookticket(airlinehead * headline,clienthead *headclient)/订票/headclient-count=0;coutline_num;airline *temp;temp=headline-next;while(temp)if(strcmp(temp-line_num,line_num)=0)break;temp=temp-next;if(!temp)cout未找到该航班left=0)cout对不起,该航班票已经售完。endl;cout请选择其他合适的航班:;client *custom=new client;coutcustom-id;coutendl;coutcustom-name;coutseat_num=temp-total - temp-left + 1;custom-next=NULL;strcpy(custom-line_num,line_num);/*client *clienttemp = NULL;clienttemp = headclient-next;if(clienttemp = NULL)/线性表为空表的时候headclient-next = custom;temp-left-;headclient-count+;cout订票成功,祝您旅途愉快。next)/线性表不为空表时,寻找最后结点。clienttemp-next=custom;temp-left-;headclient-count+;cout订票成功,祝您旅途愉快。left-;headclient-count+;custom-next = headclient-next;headclient-next = custom;cout订票成功,祝您旅途愉快。;return 1;int returnticket(airlinehead * headline,clienthead *headclient)/退票。coutid;airline *airlinetemp= headline-next;client *clienttemp= headclient-next;if(NULL=airlinetemp)cout当前没有航班信息。id,id)=0)/要删除的节点为第一个时。strcpy(line_num,clienttemp-line_num);headclient-next=clienttemp-next;delete clienttemp;while(airlinetemp)/修改对票客户所对应

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论