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

下载本文档

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

文档简介

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();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;caseb: 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 (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;PLANE 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)printf(对不起,没有您需要的航线。);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(沈阳至%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.price, 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退票成功!);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, planeadd.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, &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);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

温馨提示

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

评论

0/150

提交评论