




已阅读5页,还剩16页未读, 继续免费阅读
版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
212013.12 中国地质大学C语言课程设计 第一章 实习报告1.1题目描述【要求】假定某民航机场共有n个航班。每个航班有一航班号、确定的航线(起始站、终点站)、确定的飞行时间(星期几)和一定的成员订额。试设计一民航订票系统,能提供下列服务。(1) 航班信息录入功能(航班信息用文件保存)。(2) 航班信息浏览功能。(3) 查询航线:(至少一种查询方式)。按航班号查询。按起点站查询。按终点站查询。按飞行时间查询。【提示】(1) 需求分析航班信息用文件保存,因而要提供文件的输入/输出功能;要浏览航班信息,需要提供显示功能;要查询航线,需要提供查找功能;另外,还要提供键盘式选择菜单以实现功能选择。(2) 总体设计整个系统可以设计为航班信息输入模块、航班信息浏览模块和航线查询模块。(3) 数据结构建立航班结构体,结构体成员包括航班号、起始站、终点站、飞行时间(星期几)、预售票总数、已售票数。1.2算法设计根据需求分析,可以将这个系统的设计分为如下五大模块:输入航班信息,保存航班信息, 浏览航班信息,查找航班信息,退出。飞机订票系统输入航班信息保存航班信息浏览航班信息查找航班信息退出1.3程序设计及代码分析1.结构体设计 建立航班结构体,结构体成员包括航班号,起点站,终点站,飞行时间(星期几),预售票总数。 struct air int fir_num;char start20;char terminus20;char fir_time10;int count;sN; /*sN中每个数组元素依次对应一个航班信息*/注意 sN中的N为学生个数, 程序中采用宏定义的方式, 可以随时在源程序宏定义中改,本程序宏定义# define N 10000。2. 主函数流程图显示一系列功能选项输入j 并判断j 是否为0根据j 的值调用个功能模块函数NY程序void main() int j ;printf(“-welcome to our scheduled flight manage system!-*n”);printf(“*n”);do printf(“1. Please input the scheduled flight informationnm” “2. Look through the scheduled flight informationnn ” “3. Search for the scheduled flight informationnn” “0. EXITnn”);printf(“*n”);printf(“NOTE: This system just support the fly information in the nearest week!nn”);printf(“Please choose one number during 0-3 then push enter: nn”);scanf(“%d”, &j );switch (j) case 1: input(); /*调用输入模块*/break; case 2: print(); /*调用打印模块*/break;case 3: search(); /*调用查找模块*/break; case 0: break; /*退出*/while(j!=0);printf(“Thank you for using our system!Goodbye!n”);3.各功能模块设计3.1 输入航班信息流程图显示提示信息并设置密码读取密码验证密码是否正确N重新输入密码Yi =0i+依次读取第si 班飞机的航班号, 起点站, 终点站,飞行时间, 机票数保存信息i NY退出N程序void input() char f=“20121000748”; /*设置密码*/ int y; printf (“Please input the password then push Enter:nn”); scanf(“%s”,f); /*读取密码*/ if(strcmp(f,“20121000748”)= =0) printf(“Please input the flight information one by one(the number of the ticket should be ended by 0):nn”);printf(“*n”);for(i=0;iN;i+) printf(“Please input the flight number:n”); scanf(“%d”,&si.fir_num); /*读取航班号*/ printf(“Please input the start place:n”); scanf(“%s”,si.start); /*读取起点站*/ printf(“Please input the terminus:n”); scanf(“%s”,si.terminus); /*读取终点站*/ printf(“Please input the time:n”); scanf(“%s”,si.fir_time); /*读取时间*/ printf(“Please input the number of the ticket(the number of the ticket should be ended by 0:)n”,m); scanf(“%d”,&si.count); /*读取机票数*/ m+; printf(“The %d group information have been inputted! Please push any key to continue, push 0 to the end”,m); scanf(“%d”,&y);if(y= =0) save(); /*将结构体存盘*/print(); /*输入输出航班信息*/break; else printf(“password error! Please check your password! Thank you! Goodbye!nn”);3.2 保存信息模块流程图打开文件判断是否出错定义文件指针返回YN向文件写入数据关闭文件程序void save() FILE *fp, *fp1; /*定义文件指针*/ if(fp=fopen(“chen.dat”,”wb”)= =NULL) /*打开文件并判断是否出错*/ printf(“Fail to creat the file!nn”);getchar();return; if(fp1=fopen(“hao.dat”,”wb”)= =NULL) printf(“Fail to creat the file!nn”);getchar();return;for(i=0;im;i+) if(fwrite(&si,sizeof(struct air),1,fp)= =0) /*向文件写入数据并判断是否出错*/ printf(“Fail to input data to the file!nn”); fprintf(fp1,”%d”,m); fclose(fp); /*关闭文件*/ fclose(fp1);3.3浏览信息模块流程图定义文件指针打开文件判断是否出错退出YN从文件中读取信息关闭文件打印信息程序void read() FILE *fp, *fp1; /*定义文件指针*/if(fp=fopen(“chen.dat”,”rb”)= =NULL) /*打开文件判断是否出错*/ printf(“ Error please make sure the file is exist! Push any key back to the menu”); getchar();if(fp1=fopen(“hao.dat”,”rb”)= =NULL) /*打开文件判断是否出错*/ printf(“Fail to creat the file!nn”);getchar(); return; fscanf(fp1,”%d”,&m); fclose(fp1); for(i=0;im;i+) fread(&si,sizeof(s),1,fp); /*从文件中读取信息*/ fclose(fp); /*关闭文件*/ void print() /*打印模块*/ char w10; read(); /*调用读文件函数*/ printf(“FlightNumber StartPlace Terminus Time TicketNumbern”); for(i=0;im;i+) printf(PRINT); /*打印信息*/ printf(“Please push any key back to the up menu:n”); scanf(“%s”,w);3.4 查询信息模块流程图显示查询方式菜单选择查找方式输入要求信息显示查询结果是否继续查找退出NY程序void search() char name120; char name220; char ii10; char time10; int n,no;do printf(Please choose one way you want to search:nn); /*打印查询方式菜单*/ printf(1.According to the flight numbernn 2.According to the Terminusnn 3.According to the start placenn 4.According to the flying timenn 0.BACKnn); printf(Please choose one number during 0-3:nn Push any other key back to the top menu:nn); scanf(%d,&n); /*读取查找方式*/ if(n= =0) break; switch(n) case 1: printf(Please input the flight number:n); scanf(%d,&no); /*航班号*/ break; case 2: printf(Please input the terminus :n); scanf(%s,name2); /*读取终点站*/ break; case 3: printf(Please input the start place:n); scanf(%s,name1); /*读取起点站*/ break; case 4: printf(Please input the flying time:n); scanf(%s,time); break; read(); /*调用读取函数*/ for(i=0;im;i+) if(strcmp(si.start,name1)=0|strcmp(si.terminus,name2)=0)/*按终点站起始站判断输出条件*/ printf(nSucceed in searching for the flight information!n); printf(FlightNumber StartPlace Terminus Time TicketNumbern); printf(PRINT); /*打印信息*/ if(si.fir_num= =no) /*按航班号判断输出条件*/ printf(nSucceed in searching for the flight information!n); printf(FlightNumber StartPlace Terminus Time TicketNumbern); printf(PRINT); if(strcmp(si.fir_time,time)= =0) printf(nSucceed in searching for the flight information!n); printf(FlightNumber StartPlace Terminus Time TicketNumbern); printf(PRINT); /*打印信息*/ printf(Can not find the informtiong you wanted or you have done it:nn Do you want to continue?Please input YES or NO and push enter n);scanf(%s,ii);while(strcmp(ii,yes)=0); 1.4实验数据及运行效果截图1.输入数据管理员输入航班信息:航班号 起点站 终点站 飞行时间 总票数100 quzhou wuhan 9.1 100101 quzhou wuhan 9.2 150102 wuhan quzhou 9.1 130103 beijing wuhan 9.2 100 2.编译,连接和运行3.结果3.1 主菜单函数3.2 输入信息模块3.3浏览信息模块3.4查询信息模块3.4.1 按照航班号查询3.4.2 按照终点站查询3.4.3 按照起点站查询3.4.4 按照时间查询3.4.5 结束1.5设计中出现的错误及解决方法我在程序的设计中遇到了诸如中英输入法错误、标点符号错误等错误,同时在函数调用处多次出错,很感谢马钊老师、殷商珉珉同学和李洋同学的指导,让我学会用模块化的方式处理相关问题。当然,那些错误在编译过程
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 织布机操作工质量追溯知识考核试卷及答案
- 印染洗涤工岗位操作规程考核试卷及答案
- 电池部件制备工理念考核试卷及答案
- 冷冻食品制作工三级安全教育(班组级)考核试卷及答案
- 2024新版2025秋青岛版科学五四制三年级上册教学课件:第四单元 第15课 温度计的秘密
- 2025人民出版社供小学用中华民族大家庭教学课件:第9课 绚丽多姿的民俗风情 含微课视频
- 医院环境卫生学监测考试题及答案解析
- 银行征信知识试题及答案
- 银行行政测试题及答案
- 建筑工程专业试题及答案
- DB21-T 3464-2021 辽西北地区食叶草栽培技术规程
- 综合性医院疼痛科建设课件
- WES溢流堰堰面设计
- 水产品安全控制
- 养老服务公司经营范围(41个范本)
- 青少年脊柱侧弯筛查课件
- 北京十一学校2+4模式
- 第四章 解离平衡
- 小学生仪容仪表课件
- 初中语文中考复习 专题01 名著阅读之《朝花夕拾》(课内文言文+课外文言文)-2022年中考语文一轮复习黄金考点讲练测
- GB/T 38207-2019中国地理实体通名汉语拼音字母拼写规则
评论
0/150
提交评论