C语言程序设计-飞机订票系统_第1页
C语言程序设计-飞机订票系统_第2页
C语言程序设计-飞机订票系统_第3页
C语言程序设计-飞机订票系统_第4页
C语言程序设计-飞机订票系统_第5页
已阅读5页,还剩2页未读 继续免费阅读

下载本文档

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

文档简介

1、C语言程序设计飞机订票系统代码如下:”#include stdio.h#include stdlib.h#include string.h#define LEN sizeof (struct plane)#define MAX 10;struct planechar destination12;char num10;char time12;int price;int amount;typedef struct plane PLANE;PLANE a100; void menu(); void inp ut(); void search(); void preserve。; void plane

2、add(); void delplane();void main()sys tem(cls); menu();void menu()char *menu = * 欢迎进入飞机订票系统* a:输入航线,b:查询航线c:退订票系统d:追加航线,e:删除航线f:退出,* int i;char NO;int quit 二 0;do sys tem(cls);for (i = 0; i9; i+)pri ntf (n%s, menui);prin tf(n 请输入服务代码 a,b,c,d,e 或fn);NO = get char();switch (NO)casea: input(); break;ca

3、seb: search。; break;casec : preserve。; break;cased : planeadd(); break;casee : delplane(); break; casef : quit 二 1; break; while (!quit);void inp ut()int i, n;FILE *fp;sys tem(cls);if (fp = fopen(D:file, wb) = NULL)printf(error!n); exit(0);prin tf( n请输入航班总数n:); scanf(%d, &n);prin tf(n请按下面提示输入航班信息:起点

4、站:沈阳); for (i = 0; in; i+)printf(nt请输入终点:); scanf(%s, ai.des tination); printf(t 航班班次:);scanf(%s, ai.num); printf(t 时间:); scanf(%s, ai .ti me);printf(t 票价:); scanf(%d, & ai.price);printf(t机票总数:); scanf(%d, & ai.amou nt);fwrite(&ai, sizeof(PLANE), 1, fp);fclose(fp);void search()int i, j = 0, k = 101;

5、char st r12;FILE *fp;PLANE b5;if (fp = fopen(D:file, rb) = NULL) printf(error!n);exi t(0);printf(n请输入航班号:); scanf(%s, st r);while (fread(&bj, LEN, 1, fp) != 0)j+;for (i = 0; ij; i+)if (st rcmp(bi.num, str) = 0) printf(“沈阳至%s航班号:%s时间:%s票价:%d剩余票数:%dn, bi.destination, bi.num, bi.time, bi.price, bi.amou

6、 nt);k = i;if (k = 101)printf(对不起,没有您需要的航线。); fclose(fp);system(pause);void preserve。int a = 0, i = 0, k, m, n, x;char st r12;PLANE preserve10;FILE *fp;if (fp = fopen(D:file, rb) = NULL) printf(error!n);exi t(0);printf(请输入航班号:); scanf(%s, st r);while (fread(&preservei, LEN, 1, fp) != 0) if (st rcmp(

7、preservei.num, str) = 0)printf(“沈阳至%s航班号:%s 时间:%s 价格:%d 剩余票数:%d, preservei.destination, preservei.num, preserved.time, preservei.price, preservei.amou nt);k = i; i+;fclose(fp);printf(n请输入订退票代码:0-订票1-退票“); scanf(%d, & m);if (m = 0) printf(“沈阳至%s航班号:%s时间:%s价格:d元 剩余票数:%d, preservek.des tination, preser

8、vek.num, preservek .ti me, preservek.price, preservek.amou nt);prin tf(n请输入订票总数n:);scanf(%d, &n);x = preservek.price*n;prin tf(n 应付款 %d 元,x); preservek.amou nt 二 preservek.amou nt n; printf(n订票成功!祝您旅途愉快!);if (m = 1)prin tf(n请输入欲退票数n:); scanf(%d, &n);x = preservek.price*n;prin tf(n 应退金额:d 元,x); prese

9、rvek.amou nt 二 preservek.amou nt + n; printf(n退票成功!);fp = fopen(D:file, wb);for (i = 0; i = k; i+)fwrite(&preserved, LEN, 1, fp); fclose(fp);system(pause);void planeadd()int x, k = 1;PLANE planeadd;FILE *fp;do prin tf(n请按下面提示输入新增航班信息:); printf(t请输入终点:); scanf(%s, planeadd.des tination);prin tf(t请输入航

10、班号:); scanf(%s, planeadd.num);printf(t请输入时间:); scanf(%s, planeadd .ti me);prin tf(t请输入价格:,planeadd.price); scanf(%d, & planeadd.price);prin tf(n请输入机票总数:); scanf(%d, & planeadd.amou nt);if (fp = fopen(D:file, ab+) = NULL) prin tf(“文件有错误不能打开!); exi t(0);fseek(fp, LEN, 2);fwrite(&planeadd, LEN, 1, fp);

11、 fclose(fp);prin tf(n增加信息成功);printf(n是否继续增加航班?继续请输入1,否则输入0返回主菜单。); scanf(%d, & x);while (x != 0 & x != 1)printf(n您的输入有误,请重新输入0或1!); scanf(%d, & x);if (x = 0)menu(); k = 0;if (x = 1) k = 1; while (k);void delplane()char st r12;FILE *fp;int total = 0;int i 二 0;int del = 0;PLANE delplane10;if (fp = fopen(D:file, rb) = NULL) prin tf(“文件有错误不能打开!);exi t(0);prin tf(请输入要删除的航班号:); scanf(%s, st r);while (fread(&delplane tot al, LEN, 1, fp) total+;for (i = 0; itotal; i+)if (st rcmp(delplanei.num, str) = 0) break;for (; itotal; i+)delplanei = delplanei + 1; total = total - 1;del = 1;prin tf(n成功

温馨提示

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

评论

0/150

提交评论