理工大学华夏学院课程设计课程名称数据结构题目基于C语言的航空订票系统的设计与实现------航班录入模块专业软件技术班级软件2111姓名夏孟林成绩指导教师王绪梅2012 年6月18日至2012年6月21日课程设计任务书设计题目:基于C语言的航空订票系统的设计与实现-------航班录入模块设计目的1.学会分析研究数据对象的特性;2.学会数据的组织方法;3.选择合适的数据的逻辑结构和存储结构以及相应操作,把现实世界中的问题转换为计算机部的表示和处理;4.提高学生的程序设计能力、提高算法设计质量与程序设计素质;设计任务(在规定的时间完成下列任务)本项目旨在通过一个简化的航空订票系统项目,使学生在完成对C程序设计语言和基本数据结构与算法课程的学习后,综合运用所学到的语法和算法知识,构建一个接近实际应用场景的软件系统,以达到复习和巩固前期课程容并为后续课程奠定基础的目的。
本系统要现航班录入功能模块,航班录入应该由管理员来处理,可以录入航班情况,包括航班号、航班始发地、航班目的地、航班起飞时间、航班容量和航班价格。
(其中数据可以存储在一个数据文件中,数据结构、具体数据自定)〔算法提示〕采用链表或其他存储结构均可实现具体要完成的任务是:A.编制完成上述问题的C语言程序、进行程序调试并能得出正确的运行结果。
B.写出规的课程设计说明书;时间安排(第19周—6.18至6.25)第一天布置课程设计任务,讲授VC安装,程序结构、数组、函数、文件;第二天查阅资料,讲授排序,查询算法实现;了解航空售票管理系统的需求;第三天讲授快速排序、最短路径问题、哈希查找的算法实现,准备程序第四天完成录入模块的设计与实现,上机调试程序,教师验收;第五天提交课程设计报告,下午4点前提交课程设计报告及文档至综合楼712具体要求课程设计报告按统一通用格式书写,具体容包括:①设计任务与要求②总体方案与说明③软件主要模块的流程图④源程序清单与注释⑤问题分析与解决方案⑥小结与体会附录:①源程序(必须有简单注释)②使用说明③参考资料指导教师签名:2012 年6月15日教研室主任(或责任教师)签名:2012 年6月16日数据结构课程设计报告3.详细设计/***********************************/订票系统:航班和用户信息************************************/#ifndef _INFOR_H#define _INFOR_H //定义头文件//机票信息typedef struct{int m_planeID; //航班IDchar m_from[10]; //航班起始地char m_to[10]; //航班目的地char m_date[10]; //航班起飞时间int m_left; //航班int m_capacity; //航班容量float m_price; //航班价格int m_rebate; //航班折扣}AirPlane;//用户信息typedef struct{char m_ID[20]; //用户的char m_name[20]; //用户int m_planeID; //航班IDchar m_ticketnum[15]; / /航班座位号int m_isFlog;}Passenger;#endif //_INFOR_H3.2 录入功能模块#ifndef _PLAN_H#define _PLAN_H#include<stdio.h>#include<string.h>#include<stdlib.h>#include"infor.h"#define PLANEDAT "plane.dat" //航班记录文件void planin(void); //航班录入int planesave(AirPlane plane); //保存航班记录 0成功 -1失败void plane_check();AirPlane plane_check_id(int id,int flag) ;//按照航班ID查找int plane_check_from_to(char *from,char*to,int flag);//按照航班始发地和目的地查找void showPlane(AirPlane* plane,int n) ;//打印航班void showAllPlane(); //打印所有航班void setrebate(int id) ; //设置折扣#endif //_PLAN_H3.3 void planin(void)录入模块流程图如下:4.源程序清单与注释/*航班录入和查询*/#include"plan.h" //头文件int planesave(AirPlane plane) // 定义变量plane{FILE* fd=fopen(PLANEDAT,"a+"); //打开文件PLANEDATif(NULL==fd){printf("%s OPEN ERROR!\n",PLANEDAT); //如果文件为空则返回 PLANEDAT OPEN ERROR!return -1;}fwrite(&plane,sizeof(plane),1,fd);fclose(fd); //关闭文件fdreturn 0;}void planein(void)//航班录入{char c;AirPlane plane={0};while(1){memset(&plane,0,sizeof(plane));printf("--航班录入-----------------\n");printf("请输入航班号\n");scanf(" %d",&plane.m_planeID);printf("请输入航班始发地\n");scanf(" %s",&plane.m_from);printf("请输入航班目的地\n");scanf(" %s",&plane.m_to);printf("请输入航班起飞时间\n");scanf(" %s",&plane.m_date);printf("请输入航班容量\n");scanf(" %d",&plane.m_capacity);plane.m_left=plane.m_capacity;printf("请输入航班价格\n");scanf(" %f",&plane.m_price);printf("\n航班信息如下:\n");showPlane(&plane,1);printf("是否保存当前记录(y/n)\n");scanf(" %c",&c);if(c=='y'||c=='Y'){if(0==planesave(plane))printf("记录保存成功\n");}printf("是否继续录入(y/n)\n");scanf(" %c",&c);if(c!='y'&&c!='Y')break;}}void plane_check(){int c;while(1){printf("\n--航班查询-------------\n");printf("\t[1]按照起始地点查询\n");printf("\t[2]按照航班号查询\n");printf("\t[3]查询所有航班\n");printf("\t[0] Exit\n");printf("-----------------------\n");printf("请输入:");fflush(stdout);scanf(" %d",&c);if(0==c) break;else if(1==c){char from[10]={0};char to[10]={0};printf("请输入始发地和目的地:例如:wuhan beijing\n");scanf(" %s %s",from,to);if(0==plane_check_from_to(from,to,1))printf("没有满足条件的记录\n");}else if(2==c){int id=0;printf("请输入航班号:\n");scanf(" %d",&id);AirPlane air=plane_check_id(id,1);if(air.m_planeID==0)printf("没有满足条件的记录\n");if(0==air.m_left){printf("\n相关路段航班\n");if(0==plane_check_from_to(air.m_from,air.m_to,1)){printf("----------------------\n");printf(" 相关路段航班:无记录\n");}}}else if(3==c){showAllPlane(); //显示所以航班}else continue;}}AirPlane plane_check_id(int id,int flag)//按照航班ID查找{int r=0;//freadint count=0;//满足条件的记录数AirPlane plane={0};FILE* fd=fopen(PLANEDAT,"r");if(NULL==fd){printf("%s OPEN ERROR!\n",PLANEDAT);plane.m_planeID=-1; //如果fb为空则记planeID=-1return plane;}while(1){r=fread(&plane,sizeof(plane),1,fd);if(r<=0)break;if(plane.m_planeID==id){count++;break;} //判断planeID是否正确}fclose(fd);if(plane.m_planeID==0)return plane;if(flag)showPlane(&plane,count);return plane;}int plane_check_from_to(char *from,char*to,int flog)//按照航班始发地和目的地查找{int r=0;//freadint count=0; //满足条件的记录数AirPlane plane={0};AirPlane temp[20]={0};FILE* fd=fopen(PLANEDAT,"r"); //打开文件fdif(NULL==fd){printf("%s OPEN ERROR!\n",PLANEDAT); //判断文件fp是否存在,不存在则返回returnreturn -1;}while(1){r=fread(&plane,sizeof(plane),1,fd);if(r<=0)break;if(strcmp(plane.m_from,from)==0&&strcmp(plane.m_to,to)==0) //判断起始地和目的地是否正确{temp[count]=plane;count++; //plane的数目加1}}fclose(fd); //关闭文件fpif(!count)return 0;if(flog)showPlane(temp,count);return count;}void showAllPlane() //打印所有航班{int r=0;int i=0;printf("|NO.| id|%10s|%10s|%10s|%10s|LEFT\n","FROM","TO","DATE","PRICE");printf("---------------------------------------------------------------------\n");//打印航班信息AirPlane plane={0};FILE* fd=fopen(PLANEDAT,"r");if(NULL==fd){printf("%s OPEN ERROR!\n",PLANEDAT);return ;}while(1){r=fread(&plane,sizeof(plane),1,fd);if(r<=0)break;printf("|%03d|%4d|%10s|%10s|%10s|%10.2f|%4d\n",++i,plane.m_planeID,plane.m_from,plane.m_to,plane.m_date,plane.m_price*(plane.m_rebate==0?1:(plane.m_rebate/100)), //判断是否航班打折扣plane.m_left);}fclose(fd);}void setrebate(int id){}plane.m_date,void showPlane(AirPlane* plane,int n)//打印航班{if(n==0)return;int i=0;printf("|NO.| id|%10s|%10s|%10s|%10s|LEFT\n","FROM","TO","DATE","PRICE");printf("---------------------------------------------------------------------\n");for(i=0;i<n;i++)printf("|%03d|%4d|%10s|%10s|%10s|%10.2f|%4d\n",i+1, //输出航班的信息plane[i].m_planeID,plane[i].m_from,plane[i].m_to,plane[i].m_date,plane[i].m_price*(plane[i].m_rebate==0?1:(plane[i].m_rebate/100)),plane[i].m_left);}5.问题分析与解决方案1.当输入航班ID的时候会显示这所航班的一些信息,那么是否可以可以显示航班信息?6.小结与体会做了一个星期的程序设计终于做完了,在这次程序设计课中,真是让我获益匪浅,我突然发现写程序还挺有意思的。