您好,登錄后才能下訂單哦!
本篇內容介紹了“C語言如何實現航班管理系統”的有關知識,在實際案例的操作過程中,不少人都會遇到這樣的困境,接下來就讓小編帶領大家學習一下如何處理這些情況吧!希望大家仔細閱讀,能夠學有所成!
/*C語言實現簡單的航班管理系統(單個文件)*/#include <stdio.h>#include <string.h>#include<stdlib.h>#include<assert.h>#define PERSON_MAXNUM 100#define PERSONNOTICKET_MAX 10#define MAX_SIZE 10int _size = 0;int _person_size = 0;int _personnoticket_size = 0;//定義航班信息結構體typedef struct plane{ char ID[10]; char Start_Place[10]; char End_Place[10]; float price; int Buy_num; int Max_num; char time[20];}Plane;//定義乘客信息結構體typedef struct Person{ int AirPlane_Num; char person_name[20];}Person;void home(Plane* p,Person* person, Person* person_noticket);//初始頁面void InitAirPlane(Plane** p);//初始化航班信息內存void InputAirPlane(Plane* p);//輸入航班信息void CheckAirPlane(Plane* p);//查看航班信息void DelAirPlane(Plane* p);//刪除航班信息void CheckAirPlaneOrder(Plane* p,Person* person);//查看航班訂單void PrintPerson(Plane* p, Person* person, int i);//打印航班乘客void InitPerson(Person** person);//初始化乘客信息內存void BookAirPlane(Plane* p, Person* person,Person* person_noticket);//預定航班int CheckPerson(Plane* p, Person* person);//查看乘客訂單信息void ChangeAirPlane(Plane* p, Person* person);//改簽void ReturnTicket(Plane* p, Person* person);//退票void PrintPerson(Plane* p, Person* person, int i);void CheckPersonNoTicket(Plane* p, Person* person_noticket);//查看候補名單///////////////////////////////////////void home(Plane* p, Person* person, Person* person_noticket){ int a, i, j; printf("\n*****************************歡迎進入飛機票務系統*****************************\n"); printf("\n*************您好,現在要確認您的身份!票務人員請按 1 ,旅客請按 0 ***********\n"); printf("請選擇:"); scanf("%d", &a); //航班管理人員操作 if (a == 1) do{ printf("\n****************** 1.輸入航班信息 *******************\n"); printf("\n****************** 2.刪除航班信息 *******************\n"); printf("\n****************** 3.瀏覽航班信息 *******************\n"); printf("\n****************** 4.瀏覽目前已訂票信息 *************\n"); printf("\n****************** 5.查看候補名單 *******************\n"); printf("\n****************** 0.退出 ********************\n"); printf("請選擇:"); scanf("%d", &i); switch (i) { case 0: break; case 1:InputAirPlane(p);break; case 2:DelAirPlane(p);break; case 3:CheckAirPlane(p);break; case 4:CheckAirPlaneOrder(p, person); break; case 5:CheckPersonNoTicket(p, person_noticket); break; default: printf("輸入錯誤!\n"); break; } } while (i != 0); //乘客操作 if (a == 0) do{ printf("\n*********************** 1.訂票 **********************\n"); printf("\n*********************** 2.改簽 **********************\n"); printf("\n*********************** 3.退票 **********************\n"); printf("\n*********************** 4.瀏覽航班信息 **************\n"); printf("\n*********************** 5.查詢個人訂票信息 **********\n"); printf("\n*********************** 0.退出 **********************\n"); printf("請選擇:"); scanf("%d", &j); switch (j) { case 0:break; case 1:BookAirPlane(p, person,person_noticket);break; case 2:ChangeAirPlane(p, person);break; case 3:ReturnTicket(p, person);break; case 4:CheckAirPlane(p);break; case 5:CheckPerson(p, person); break; } } while (j != 0);}//初始化void InitAirPlane(Plane** p){ assert(p); //申請空間 *p = (Plane*)malloc(sizeof(Plane)*MAX_SIZE); if (NULL == *p) { printf("開辟空間失敗!\n"); return; } (*p)->Buy_num = 0;}//輸入航班信息void InputAirPlane(Plane* p){ if (_size <= MAX_SIZE) { printf("航班編號:%d\n", _size); printf("輸入航班ID:"); scanf("%s", (p+_size)->ID); printf("輸入始發地:"); scanf("%s", (p + _size)->Start_Place); printf("輸入目的地:"); scanf("%s", (p + _size)->End_Place); printf("輸入航班起飛時間:"); scanf("%s", (p + _size)->time); printf("輸入價格:"); scanf("%f", &(p + _size)->price); printf("輸入航班可乘坐最大人數:"); scanf("%d", &(p + _size)->Max_num); do { printf("目前賣出機票數量:"); scanf("%d", &(p + _size)->Buy_num); if ((p + _size)->Buy_num > (p + _size)->Max_num) { printf("輸入已賣出機票數量錯誤!\n"); printf("請重新輸入!\n\n"); } } while ((p + _size)->Buy_num > (p + _size)->Max_num); _size++; printf("添加航班信息完成!\n\n"); } else { printf("內存已滿!\n"); return; }}//瀏覽航班信息void CheckAirPlane(Plane* p){ int i = 0; printf("目前在售的航班信息:\n\n"); for (i = 0; i < _size; i++) { printf("航班編號:%d\n", i); printf("ID:%s\n", (p+i)->ID); printf("始發地:%s\n", (p + i)->Start_Place); printf("目的地:%s\n", (p + i)->End_Place); printf("起飛時間:%s\n", (p + i)->time); printf("機票價格:%2f\n", (p + i)->price); printf("剩余機票:%d\n", ((p + i)->Max_num - (p + i)->Buy_num) ); printf("\n"); }}//刪除航班信息void DelAirPlane(Plane* p){ int j = 0; int i = -1; assert(p); printf("請輸入要刪除的航班編號:"); scanf("%d", &i); for (j = i; j < _size; j++) { strcpy((p + j)->ID, (p + j + 1)->ID); strcpy((p + j)->Start_Place, (p + j + 1)->Start_Place); strcpy((p + j)->End_Place, (p + j)->End_Place); strcpy((p + j)->time, (p + j + 1)->time); (p + j)->price = (p + j + 1)->price; (p + j)->Max_num = (p + j + 1)->Max_num; (p + j)->Buy_num = (p + j + 1)->Buy_num; } _size--;}//初始化訂票信息void InitPerson(Person** person){ assert(person); *person = (Person*)malloc(sizeof(Person)*PERSON_MAXNUM); if (NULL == *person) { printf("開辟空間失敗!\n"); return; }}//訂票void BookAirPlane(Plane* p, Person* person, Person* person_noticket){ int i = -1; CheckAirPlane(p); printf("請選擇你要預定的航班編號:"); scanf("%d", &i); if ((p + i)->Max_num == (p + i)->Buy_num) { printf("對不起,該航班機票已售完!\n"); printf("請輸入您的姓名(我們將把您添加進候補名單):"); scanf("%s", (person_noticket+_personnoticket_size)->person_name); (person_noticket + _personnoticket_size)->AirPlane_Num = i; _personnoticket_size++; printf("添加候補名單成功!\n\n"); return; } else { if (_person_size > PERSON_MAXNUM) { printf("存儲容量不足!\n"); return; } printf("請輸入姓名:"); scanf("%s", (person + _person_size)->person_name); (person + _person_size)->AirPlane_Num = i; _person_size++; (p + i)->Buy_num++; printf("預定成功!\n"); }}//查看個人訂票信息int CheckPerson(Plane* p, Person* person){ int flag = 0; int i = 0; char _name[20] = { 0 }; printf("請輸入您的姓名:"); scanf("%s", &_name); printf("您的個人訂票信息:\n\n"); for (i = 0; i < _person_size; i++) { if (0 == strcmp(_name, (person + i)->person_name)) { flag = 1; printf("訂單編號:%d\n", i); printf("姓名:%s\n", (person + i)->person_name); printf("航班編號:%d\n", (person + i)->AirPlane_Num); printf("航班ID:%s\n", (p + (person + i)->AirPlane_Num)->ID); printf("始發地:%s\n", (p + (person + i)->AirPlane_Num)->Start_Place); printf("目的地:%s\n", (p + (person + i)->AirPlane_Num)->End_Place); printf("起飛時間:%s\n", (p + (person + i)->AirPlane_Num)->time); printf("機票價格:%f\n", (p + (person + i)->AirPlane_Num)->price); printf("\n"); } } if (0 == flag) { printf("未找到該乘客訂票信息!\n"); return 0; } return 1;}//改簽void ChangeAirPlane(Plane* p, Person* person){ int i = -1; int j = -1; if (0 == CheckPerson(p, person)) { return; } printf("請輸入要改簽的訂單編號:"); printf("\n"); scanf("%d", &i); (p + i)->Buy_num--; CheckAirPlane(p); do { printf("請輸入要改簽的航班編號:"); scanf("%d", &j); if ((p + j)->Buy_num >= (p + j)->Max_num) { printf("該次航班已滿員,請重新選擇!\n"); } } while ((p + j)->Buy_num >= (p + j)->Max_num); (person + i)->AirPlane_Num = j; (p + j)->Buy_num++; printf("改簽成功!\n\n");}//刪除訂單void ReturnTicket(Plane* p, Person* person){ int i = -1; int j = 0; CheckPerson(p, person); printf("請輸入要刪除的訂單編號:"); scanf("%d", &i); for (j = i; j < _person_size; j++) { (person + j)->AirPlane_Num = (person + j + 1)->AirPlane_Num; strcpy((person + j)->person_name, (person + j + 1)->person_name); } printf("退票成功!\n");}//查看目前訂票信息void CheckAirPlaneOrder(Plane* p, Person* person){ int i = -1; for (i = 0; i < _size; i++) { printf("航班編號:%d\n", i); printf("ID:%s\n", (p + i)->ID); printf("始發地:%s\n", (p + i)->Start_Place); printf("目的地:%s\n", (p + i)->End_Place); printf("起飛時間:%s\n", (p + i)->time); printf("機票價格:%2f\n", (p + i)->price); printf("剩余機票:%d\n", ((p + i)->Max_num - (p + i)->Buy_num)); printf("買票人信息:"); PrintPerson(p,person, i); }}void PrintPerson(Plane* p, Person* person,int i){ int ticket_num = 0; int j = 0; for (j = 0; j < _person_size; j++) { if ((person + j)->AirPlane_Num == i) { printf("%s ,", (person + j)->person_name); ticket_num++; } } printf("\n\n");}//候補名單初始化void InitPersonNoTicket(Person** person_noticket){ assert(person_noticket); *person_noticket = (Person*)malloc(sizeof(Person)*PERSONNOTICKET_MAX); if (NULL == *person_noticket) { printf("開辟空間失敗!\n"); return; }}//查看候補名單void CheckPersonNoTicket(Plane* p, Person* person_noticket){ int i = 0; printf("候補名單:\n\n"); if (0 == _personnoticket_size) { printf("候補名單為空!\n\n"); return; } for (i = 0; i < _personnoticket_size; i++) { printf("姓名:%s\n", (person_noticket + i)->person_name); printf("所需要航班編號:%d\n", (person_noticket + i)->AirPlane_Num); printf("航班ID:%s\n", (p + ((person_noticket + i)->AirPlane_Num))->ID); printf("始發地:%s\n", ((p + ((person_noticket + i)->AirPlane_Num))->Start_Place)); printf("目的地:%s\n", (p + ((person_noticket + i)->AirPlane_Num))->End_Place); }}//主函數int main(){ Plane* p=NULL; Person* person=NULL; Person* person_noticket = NULL; InitPersonNoTicket(&person_noticket); InitAirPlane(&p); InitPerson(&person); while (1) { home(p, person, person_noticket); } system("pause"); return 0;}
“C語言如何實現航班管理系統”的內容就介紹到這里了,感謝大家的閱讀。如果想了解更多行業相關的知識可以關注億速云網站,小編將為大家輸出更多高質量的實用文章!
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。