600字范文,内容丰富有趣,生活中的好帮手!
600字范文 > c语言程序设计飞机 C语言程序设计――飞机订票系统

c语言程序设计飞机 C语言程序设计――飞机订票系统

时间:2018-10-19 01:03:11

相关推荐

c语言程序设计飞机 C语言程序设计――飞机订票系统

《C语言程序设计――飞机订票系统》由会员分享,可在线阅读,更多相关《C语言程序设计――飞机订票系统(7页珍藏版)》请在人人文库网上搜索。

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 input();void search();void preserve();void planeadd()。

2、;void delplane();void main()system(cls);menu();void menu()char *menu = * 欢迎进入飞机订票系统*, a:输入航线 , b:查询航线 , c:退订票系统 , d:追加航线 , e:删除航线 , f: 退出 ,* ;int i;char NO;int quit = 0;dosystem(cls);for (i = 0; i9; i+)printf(n%s, menui);printf(n请输入服务代码a,b,c,d,e或fn);NO = getchar();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 input()int i, n;FILE *fp;system(cls);if (fp = fopen(D:file, wb) = NULL)printf(error!n); exit(0);printf(n请输入航班总数n:);scanf(%d, &n);printf(n请按下面提示输入航班信息:起点站:沈阳);for。

4、 (i = 0; in; i+)printf(nt请输入终点:);scanf(%s, ai.destination);printf(t 航班班次:);scanf(%s, ai.num);printf(t 时间:);scanf(%s, ai.time);printf(t 票价:);scanf(%d, &ai.price);printf(t机票总数:);scanf(%d, &ai.amount);fwrite(&ai, sizeof(PLANE), 1, fp);fclose(fp);void search()int i, j = 0, k = 101;char str12;FILE *fp;PL。

5、ANE b5;if (fp = fopen(D:file, rb) = NULL)printf(error!n);exit(0);printf(n请输入航班号:);scanf(%s, str);while (fread(&bj, LEN, 1, fp) != 0)j+;for (i = 0; ij; i+)if (strcmp(bi.num, str) = 0)printf(沈阳至%s 航班号:%s 时间:%s 票价:%d 剩余票数:%dn, bi.destination, bi.num, bi.time, bi.price, bi.amount);k = i;if (k = 101)prin。

6、tf(对不起,没有您需要的航线。);fclose(fp);system(pause);void preserve()int a = 0, i = 0, k, m, n, x;char str12;PLANE preserve10;FILE *fp;if (fp = fopen(D:file, rb) = NULL)printf(error!n);exit(0);printf(请输入航班号:);scanf(%s, str);while (fread(&preservei, LEN, 1, fp) != 0)if (strcmp(preservei.num, str) = 0)printf(沈阳至。

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

8、ice, preservek.amount);printf(n请输入订票总数n:);scanf(%d, &n);x = preservek.price*n;printf(n应付款%d元, x);preservek.amount = preservek.amount - n;printf(n订票成功!祝您旅途愉快!);if (m = 1)printf(n请输入欲退票数n:);scanf(%d, &n);x = preservek.price*n;printf(n应退金额:%d元, x);preservek.amount = preservek.amount + n;printf(n退票成功!);。

9、fp = fopen(D:file, wb);for (i = 0; i = k; i+)fwrite(&preservei, LEN, 1, fp);fclose(fp);system(pause);void planeadd()int x, k = 1;PLANE planeadd;FILE *fp;doprintf(n请按下面提示输入新增航班信息:);printf(t请输入终点:);scanf(%s, planeadd.destination);printf(t请输入航班号:);scanf(%s, planeadd.num);printf(t请输入时间:);scanf(%s, plane。

10、add.time);printf(t请输入价格:, planeadd.price);scanf(%d, &planeadd.price);printf(n请输入机票总数:);scanf(%d, &planeadd.amount);if (fp = fopen(D:file, ab+) = NULL)printf(文件有错误不能打开!);exit(0);fseek(fp, LEN, 2);fwrite(&planeadd, LEN, 1, fp);fclose(fp);printf(n增加信息成功!);printf(n是否继续增加航班?继续请输入1,否则输入0返回主菜单。);scanf(%d, 。

11、&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 str12;FILE *fp;int total = 0;int i = 0;int del = 0;PLANE delplane10;if (fp = fopen(D:file, rb) = NULL)printf(文件有错误不能打开!);exit(0);printf(请输入要删除的航班号:);scanf(%s, str)。

12、;while (fread(&delplanetotal, LEN, 1, fp)total+;for (i = 0; itotal; i+)if (strcmp(delplanei.num, str) = 0)break;for (; itotal; i+)delplanei = delplanei + 1;total = total - 1;del = 1;printf(n成功删除信息!);if (del = 0)printf(系统中不存在要删除的信息!);menu();elseif (fp = fopen(D:file, wb+) = NULL);printf(文件有错误不能打开!);exit(0);for (i = 0; itotal; i+) fwrite(&delplanei, LEN, 1, fp);fclose(fp。

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。