C語言程序設計——飛機訂票系統(共7頁)_第1頁
C語言程序設計——飛機訂票系統(共7頁)_第2頁
C語言程序設計——飛機訂票系統(共7頁)_第3頁
C語言程序設計——飛機訂票系統(共7頁)_第4頁
C語言程序設計——飛機訂票系統(共7頁)_第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 inpu

2、t();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

3、;int quit = 0;dosystem("cls");for (i = 0; i<9; i+)printf("n%s", menui);printf("n請輸入服務代碼a,b,c,d,e或fn");NO = getchar();switch (NO)case'a': input(); break;case'b': search(); break;case'c': preserve(); break;case'd': planeadd(); break;case

4、'e': delplane(); break;case'f': 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(&quo

5、t;n請按下面提示輸入航班信息:起點站:沈陽");for (i = 0; i<n; 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);pr

6、intf("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請輸入航班號:");s

7、canf("%s", str);while (fread(&bj, LEN, 1, fp) != 0)j+;for (i = 0; i<j; 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(&qu

8、ot;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 (strc

9、mp(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

10、 價格:%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訂票成功!祝您旅途愉快!");

11、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)

12、;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(

13、"%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,

14、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;

15、 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; i<total; i+)if (strcmp(delplanei.num, str) = 0)break;for (; i<total; 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

提交評論