




版權說明:本文檔由用戶提供并上傳,收益歸屬內容提供方,若內容存在侵權,請進行舉報或認領
文檔簡介
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. 本站不保證下載資源的準確性、安全性和完整性, 同時也不承擔用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。
最新文檔
- 2025年微電網穩定性優化與分布式能源管理創新趨勢報告
- 2025年可穿戴醫療設備在兒童健康管理中的應用與創新研究報告
- 2025年城市軌道交通建設規劃與智慧能源運營管理研究報告
- 綠色供應鏈管理在制造業綠色制造與綠色營銷中的應用報告
- 環保產業園區循環經濟模式綠色產業政策創新路徑分析2025年研究報告
- 江蘇村級工程管理制度
- 二級建造師培訓管理制度
- 智能矸選系統管理制度
- 服裝企業存貨管理制度
- 2025年江西省中考歷史真題(原卷版)
- 河道疏浚對漁業發展的影響與對策
- 2024年11月傳播學教程試題庫(附答案解析)
- 2025年中考數學:初中八年級下冊第X單元:代數綜合測試試卷
- 白酒酒店合作合同協議書
- T/CIE 209-2024兒童實物編程教育評價指南
- 中國融通農業發展有限集團有限公司招聘筆試題庫2025
- 塑料包裝制品項目投資計劃書
- 實驗室通風系統工程施工方案
- 慢性活動性EB病毒病診治專家共識(2025版)解讀
- 2025年入團考試常見問題及試題答案
- 2025浙江杭州市科創集團有限公司招聘10人筆試參考題庫附帶答案詳解
評論
0/150
提交評論