C语言程序设计报告

上传人:re****.1 文档编号:563821056 上传时间:2022-12-23 格式:DOCX 页数:27 大小:21.97KB
返回 下载 相关 举报
C语言程序设计报告_第1页
第1页 / 共27页
C语言程序设计报告_第2页
第2页 / 共27页
C语言程序设计报告_第3页
第3页 / 共27页
C语言程序设计报告_第4页
第4页 / 共27页
C语言程序设计报告_第5页
第5页 / 共27页
点击查看更多>>
资源描述

《C语言程序设计报告》由会员分享,可在线阅读,更多相关《C语言程序设计报告(27页珍藏版)》请在金锄头文库上搜索。

1、C语言程序设计-飞机订票设计题目:飞机订票设计。功能:本飞机共有80个座位,分为20排,每排4个 位子。编号为A,B,C,D。如10D表示10排D座。A和D靠窗,19到20排为 吸烟区。本系统可以让乘客自己选座号和区域,直到乘客满意为止,无法满足的 话,只能改乘另一个航班。订上票的乘客需要题目:飞机订票设计。功能:本飞机共有80个座位,分为20排,每排4个位子。编号为A,B,C,D。 如10D表示10排D座。A和D靠窗,19到20排为吸烟区。本系统可以让乘 客自己选座号和区域,直到乘客满意为止,无法满足的话,只能改乘另一个航班。 订上票的乘客需要给出姓名和身份证号,最后要打印出乘客清单。分布实

2、施:1、初步完成总体设计,搭好框架,确定人机对话的界面,确定两个函数;2、完成最低要求:建立一个小系统,包括5排座位,两个区域,能供乘客选择;3、进一步要求:完成全部功能的系统。要求:1、用C语言实现程序设计;2、利用结构体数组实现信息的数据结构设计;3、系统的各个功能模块要求用函数的形式实现;4、界面友好(良好的人机交互),程序加必要的注释。课程设计试验报告要求:1预习报告:题目、课程设计任务、数据结构、程序的总体设计(算法)、模 块划分。2、实验总结报告:流程图、主要源程序代码(需打印)、测试情况及调试中问 题与解决方案、小结等。#include vstdafx.h #include v

3、conio.h #includevstdio.h #includevstring.h #includevstdlib.h #define OK 1 #define TRUE 1 #define FALSE 0 #define ERROR 0 #define OVERFLOW -2 #define PR printf typedef int status; typedef struct airlinechar line_num8; 航班号char plane_num8; 飞机号char end_place20; 目的的int total;/座位总数int left;/剩余座位struct air

4、line *next;/ 下一个结点airline;typedef struct customerchar name9; 顾客名char line_num8;/ 航班号int seat_num;/ 座位号struct customer *next;/ 下一个结点customer;airline *init_airline()初始化链表airline *l;l=(airline*)malloc(sizeof(airline);if(l二二NULL) exit(0);l-next二NULL;return l;customer * init_customer() 初始化链表customer *l;l

5、=(customer*)malloc(sizeof(customer);if(l = = NULL)exit(O);l-next二NULL;return l;status insert_airline(airline *p,char *line_num,char *plane_num,char*end_place,int total,int left)/airline 链表插入操作airline *q;q=(airline*)malloc(sizeof(airline);strcpy(q-line_num , line_num);strcpy(q-plane_num , plane_num);

6、strcpy(q-end_place , end_place);q-total =total;q-left =left;(*p)-next二q;(*p)=(*p)-next;/ PR(insert %d ,%dis succssed!n,e,bl);return OK;status insert_customer(customer *p,char *name,char *line_num,intseat)/customer链表插入操作customer *q;q=(customer*)malloc(sizeof(customer);/* PR(内存分配失败n);return OVERFLOW;

7、*/strcpy(q-name , name);strcpy(q-line_num , line_num);q-seat_num =seat;q-next二NULL;(*p)- n ext=q;(*p)=(*p)-next;/ PR(insert %d ,%dis succssed!n,e,bl);return OK;airline *modefy_airline(airline *l,char *line_num)(修改 airline 链表中的数据 airline *p;p=l-next ;for(;p!二NULL;p二p-next ) if(strcmp(line_num,p-line_

8、num ) = =0) p-left +;/ PR(modefy %sn,p-line_num );return l;PR(没有这个航班,无法完成修改任务! n);return 0;status delete_airline(airline *h,char *line_num) 删除航班 airline *p,*pr;pr=h;p=pr-next ;while(p!二NULL) if(strcmp(line_num,p-line_num ) = =0) pr-next =p-next ;PR(删除 %s 航班n,p-line_num );return OK;p=pr-next ;PR(无此航班

9、,无法删除! n);return ERROR;status delete_customer(customer *h,char *line_num) 删除顾客 customer *p,*pr;pr=h;p=pr-next ;while(p!二NULL) if(strcmp(line_num,p-line_num ) = =0) pr-next =p-next ;pr=pr-next ;p=pr-next ;/ PR(无此航班,无法删除! n);return OK;status delete_cus(customer *h,airline *l,char *name) 顾客退票 customer

10、*p,*pr;char line_num8;/ qr=h;pr=h;p=pr-next ;/ PR(开始删除n);while(p!二NULL) if(strcmp(name,p-name ) = =0) strcpy(line_num,p-line_num );l二modefy_airline(l,line_num);pr-next =p-next ;PR(顾客 %s 退票成功!n,p-name );return OK;pr=pr-next ;p=pr-next ;PR(无此顾客,无法退票! n);return ERROR;status save_airline(airline *l) 保存

11、airline.dat FILE *fp_airline;char ch = #;char filename = c:airline.dat;if(fp_airline二fopen(filename,wb)二二NULL) printf(can not open file to write:%sn,filename);return ERROR;for(;p! = NULL;p=p-next ) /printf(%s,%s,%s,%d,%dn,p-line_num ,p-plane_num ,p-end_place,p-total ,p-left );fprintf(fp_airline,%s,%

12、s,%s,%d,%d%cn,p-line_num ,p-plane_num ,p-end_place ,p-total ,p-left ,ch);fclose(fp_airline);return OK;status save_customer(customer *l)保存顾客信息 customer.dat FILE *fp_customer;char ch = #;customer *p=l-next ;char filename = c:customer.dat;if(fp_customer=fopen(filename,wb) = = NULL) printf(can not open

13、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,%d%c,p-name ,p-line_num ,p-seat_nu m ,ch);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 (ch

14、iv58&chi4 7) 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 insert_air(airline *l,char *line_num,char *plane_num,char*end_place,int total,int left)/airline 链表插入操作airline *q;q=(airline*)malloc(sizeof(airline);strcpy(q-line_num , line_num);strcpy(q-plane_num , plane_num);strcpy(q-end_place , end_place);q-total =total;q-left =left;q-next=l-next ;l-next=q;/

展开阅读全文
相关资源
相关搜索

当前位置:首页 > 学术论文 > 其它学术论文

电脑版 |金锄头文库版权所有
经营许可证:蜀ICP备13022795号 | 川公网安备 51140202000112号