C语言实现飞机订票系统
文章目錄
- 題目
- 總體設(shè)計和需求分析
- 設(shè)計目的
- 總體設(shè)計和功能
- 結(jié)構(gòu)體設(shè)計
- 機票信息結(jié)構(gòu)體
- 訂票人信息結(jié)構(gòu)體
- 主函數(shù)的設(shè)計
- 各功能代碼的實現(xiàn)
- 前置
- 添加機票
- 查找機票信息
- 修改機票信息
- 顯示機票信息
- 推薦機票信息
- 訂票
- 退票
- 保存信息
- 顯示時間
- 測試
題目
本文將設(shè)計一個飛機訂票系統(tǒng),主要包括機票的添加、修改、查找、訂票、退票、推薦機票功能,用C語言編程實現(xiàn),并用鏈表存儲產(chǎn)生的航班信息和訂票信息數(shù)據(jù),最后可以把鏈表中的數(shù)據(jù)保存到文件中。
總體設(shè)計和需求分析
設(shè)計目的
1.怎樣去合理的設(shè)計一個數(shù)據(jù)結(jié)構(gòu)來存儲訂票信息和航班信息
2.加深對鏈表的增刪改查功能的學習和理解
3.學習如何鏈表和外部文件之間的讀取和存儲操作
4.學習如何將學到的知識應(yīng)用到實際的問題中
總體設(shè)計和功能
此飛機訂票系統(tǒng)將實現(xiàn)以下功能:
1.初始化功能
??該功能將實現(xiàn)將航班信息文件和訂票人訂票信息文件中的數(shù)據(jù)讀取到鏈表中。
2.添加機票信息功能
??該功能將實現(xiàn)添加航班機票信息,信息包括航班號、出發(fā)地、目的地、起飛時間、降落時間、票價、折扣、剩余票數(shù),然后用鏈表將數(shù)據(jù)保存起來。
3.查詢機票信息功能
??該功能將實現(xiàn)通過航班號來查詢機票信息的功能
4.修改機票信息功能
??該功能將通過航班號調(diào)用查找機票信息功能,定位到要修改的航班信息上,然后通過航班信息子菜單確定要修改的某一項航班信息。
5.顯示機票信息
??該功能將實現(xiàn)把所有航班信息顯示出來
7.推薦機票功能
??該功能將實現(xiàn)通過輸入目的地,和乘客最早出發(fā)時間可以獲得符合條件的航班信息
8.訂票功能
??該功能下乘客輸入目的地,并且輸入訂票人的姓名、身份證號碼、性別、購票數(shù)量、訂購航班號以實現(xiàn)用戶訂票功能
9.退票功能
??該功能下乘客可以訂購的機票進行退回。
10.顯示時間功能
??該功能可以顯示實時時間
11.保存信息功能
該功能下可以把鏈表中的信息保存到文件中。
結(jié)構(gòu)體設(shè)計
我們將定義兩個結(jié)構(gòu)體,分別為機票信息結(jié)構(gòu)體和訂票人信息結(jié)構(gòu)體
機票信息結(jié)構(gòu)體
typedef struct AirPlane {char acFlight[20];//航班號char acOrigin[10]; //出發(fā)地char acDest[20]; //目的地char acTakeOffTime[10]; //起飛時間char acReverceTime[10]; //降落時間float fPrice; //票價char acDisscount[4]; //折扣int iNum; //剩余票數(shù) }AirPlane, * PAirPlane; //定義機票信息節(jié)點的結(jié)構(gòu)體 typedef struct PlaneNode {struct AirPlane stDate;struct PlaneNode* pstNext;}PlaneNode, * PPlaneNode;訂票人信息結(jié)構(gòu)體
typedef struct Man {char acName[20]; //姓名char acID[20]; //身份證號碼char acSex[10]; //性別 int iBookNum; //購票數(shù)量char acBookFilght[10]; //訂購航班號 }Man, * PMan; //訂票人信息節(jié)點的結(jié)構(gòu)體 typedef struct ManNode {struct Man stDate;struct ManNode* pstNext; }ManNode, * PManNode;主函數(shù)的設(shè)計
在主函數(shù)中,首先將通過初始化函數(shù)把文件中的數(shù)據(jù)讀取到鏈表中,然后可以通過switch選擇用戶在飛機訂票系統(tǒng)中需要執(zhí)行的操作
//作為數(shù)據(jù)改動的標志 int iSave = 0;int main() {struct PlaneNode pstPlaneNodeHead; //機票信息頭結(jié)點pstPlaneNodeHead.pstNext = NULL;struct ManNode pstManNodeHead; //購票信息頭結(jié)點pstManNodeHead.pstNext = NULL;Init(&pstPlaneNodeHead, &pstManNodeHead); // 將文件的數(shù)據(jù)加載到內(nèi)存中int iSel = 0; //用于接收用戶對功能的選擇char c1;while (1){system("cls");Menu();printf("Input 0-9 operations:");scanf_s("%d", &iSel);getchar();switch (iSel){case 1:printf("進入添加機票頁面\n");Insert(&pstPlaneNodeHead); // 添加機票信息break;case 2:Search(&pstPlaneNodeHead); //查詢機票信息break;case 3:Book(&pstPlaneNodeHead, &pstManNodeHead);//訂票break;case 4:Modify(&pstPlaneNodeHead); //修改機票信息break;case 5:Show(&pstPlaneNodeHead); //顯示機票信息 break;case 6:Recommend(&pstPlaneNodeHead); //推薦機票信息break;case 7:Refund(&pstPlaneNodeHead, &pstManNodeHead);//退票信息break;case 8:NowTime();//顯示當前時間break;case 9:SaveMan(&pstManNodeHead); //數(shù)據(jù)保存SavePlane(&pstPlaneNodeHead);break;case 0:if (iSave == 1){printf("do you want to save (y/n)");scanf("%c", &c1);getchar();if (c1 == 'y' || c1 == 'Y'){SaveMan(&pstManNodeHead); //保存訂票人的信息SavePlane(&pstPlaneNodeHead); // 保存機票信息}}Destroy(&pstPlaneNodeHead, &pstManNodeHead);return 0;}printf("\nplease press any key to continue...\n");_getch();}Destroy(&pstPlaneNodeHead, &pstManNodeHead);return 0; }各功能代碼的實現(xiàn)
前置
寫入需要用到的頭文件、宏定義以及其中的打印函數(shù)等等
#define _CRT_SECURE_NO_WARNINGS #include<stdio.h> #include<assert.h> #include<Windows.h> #include<malloc.h> #include<string.h> #include<conio.h> #include <time.h>#define HEAD1 "*******************************************************************\n" #define HEAD2 "|Flight|StartCity|DestCity|DepertureTime|Arrival| price |number|\n" #define HEAD3 "|------|---------|--------|-------------|-------|----------|------|\n" #define FORMET "%-9s%-9s%-10s%-14s%-10s%-2.2f%6d\n" #define DATA pst->stDate.acFlight,pst->stDate.acOrigin,pst->stDate.acDest,pst->stDate.acTakeOffTime,pst->stDate.acReverceTime,pst->stDate.fPrice,pst->stDate.iNum```c //主菜單 void Menu() {puts("**********************************************************************");puts("****** Welcome to the airplane tickets booking system");puts("----------------------------------------------------------------------");puts(" choose the follow operation(0-9) *");puts("--------------------------------------------------------------------- ");puts("*********** 1 Insert flights 2 Search flights ");puts("********** 3 Book tickets 4 Modify fligts date");puts("********** 5 Show flights 6 Recommend flights ");puts("************ 7 Refund tickets 8 Show current time ");puts("*********** 9 Save to files 0 quit ");puts("**********************************************************************"); } //打印函數(shù) void PrintHead() {printf(HEAD1);printf(HEAD2);printf(HEAD3); }void PrintDate(PPlaneNode stLP) {PPlaneNode pst = stLP;printf(FORMET, DATA);} //銷毀函數(shù) 防止內(nèi)存泄漏 void Destroy(PPlaneNode pstPlaneNodeHead, PManNode pstManNodeHead) {assert(pstManNodeHead != NULL);assert(pstPlaneNodeHead != NULL);PPlaneNode p = pstPlaneNodeHead->pstNext;PManNode q = pstManNodeHead->pstNext;while (p != NULL){PPlaneNode tmp = p;p = p->pstNext;free(tmp);}while (q != NULL){PManNode tmp = q;q = q->pstNext;free(tmp);}} #### 初始化```c int Init(struct PlaneNode* pstPlaneNodeHead, struct ManNode* pstManNodeHead) {//先加載飛機機票信息FILE* pfPlane; //定義飛機機票信息文件指針struct PlaneNode* pstPlaneNodeTemp, * pstPlaneNodeCur;pstPlaneNodeCur = pstPlaneNodeHead;pstPlaneNodeTemp = NULL;pfPlane = fopen("plane.txt", "ab+");if (pfPlane == NULL){printf("can't open plane.txt!\n");return -1;}else{//把文件數(shù)據(jù)讀入到鏈表中while (!feof(pfPlane)) //讀到文件最后一個數(shù)據(jù){pstPlaneNodeTemp = (struct PlaneNode*)malloc(sizeof(struct PlaneNode));if (fread(pstPlaneNodeTemp, sizeof(struct PlaneNode), 1, pfPlane) !=0){pstPlaneNodeTemp->pstNext = NULL;pstPlaneNodeCur->pstNext = pstPlaneNodeTemp;pstPlaneNodeCur = pstPlaneNodeTemp;}}free(pstPlaneNodeTemp); //此時,釋放的是文件讀完后最后一次申請的指針fclose(pfPlane);}//加載訂票人信息FILE* pfMan; // 定義訂票人信息文件指針struct ManNode* pstManNodeTemp, * pstManNodeCur;pstManNodeCur = pstManNodeHead;pstManNodeTemp = NULL;pfMan = fopen("man.txt", "ab+");if (pfMan == NULL){printf("can't open man.txt!\n");return -1;}else{while (!feof(pfMan)){pstManNodeTemp = (struct ManNode*)malloc(sizeof(struct ManNode));if (fread(pstManNodeTemp, sizeof(struct ManNode), 1, pfMan) == 1){pstManNodeTemp->pstNext = NULL;pstManNodeCur->pstNext = pstManNodeTemp;pstManNodeCur = pstManNodeTemp;}}free(pstManNodeTemp);fclose(pfMan);}return 0; }添加機票
void Insert(struct PlaneNode* pstPlaneNodeHead) {assert(pstPlaneNodeHead != NULL);if (pstPlaneNodeHead == NULL){return;}struct PlaneNode* pstNode, * pstHead, * pstTail, * pstCur, * pstNew;char acFlight[20]; //保存航班號pstHead = pstTail = pstPlaneNodeHead;//讓pstTail指向最后一個節(jié)點while (pstTail->pstNext != NULL){pstTail = pstTail->pstNext;}while (1){printf("Input the flight number (-1 to end):");scanf_s("%s", acFlight, 20);getchar();if (strcmp(acFlight, "-1") == 0){break;}//航班號唯一pstCur = pstPlaneNodeHead->pstNext;while (pstCur != NULL){if (strcmp(acFlight, pstCur->stDate.acFlight) == 0){printf("this flight %s esists!\n", acFlight);return;}pstCur = pstCur->pstNext;}//如果航班號沒有和現(xiàn)有記錄航班號重復(fù) ,則重新建一個鏈表節(jié)點pstNew = (struct PlaneNode*)malloc(sizeof(struct PlaneNode));strcpy_s(pstNew->stDate.acFlight, 20, acFlight);printf("Input the Start City:\n");scanf_s("%s", pstNew->stDate.acOrigin, 10);printf("Input the Dest City:\n");scanf_s("%s", pstNew->stDate.acDest, 20);printf("Input the Departure time(Format 00:00):\n");scanf_s("%s", pstNew->stDate.acTakeOffTime, 10);printf("Input the Arrival time(Format 00:00):\n");scanf_s("%s", pstNew->stDate.acReverceTime, 10);printf("Input the Price of ticket:\n ");scanf_s("%f", &pstNew->stDate.fPrice);printf("Input the discount(Fromat(0.0):\n");scanf_s("%s", pstNew->stDate.acDisscount, 4);printf("Input the number of the tickets:\n");scanf_s("%d", &pstNew->stDate.iNum);pstNew->pstNext = NULL;pstTail->pstNext = pstNew;pstTail = pstNew;//如果有新的航班信息,保存標準置為1,若退出需要提示是否保存信息(見主函數(shù))iSave = 1;} }查找機票信息
//查詢機票信息 void Search(PPlaneNode pstPlaneNodeHead) {assert(pstPlaneNodeHead != NULL);if (pstPlaneNodeHead == NULL){return;}system("cls");int iSel = 0;int icount = 0;PPlaneNode pstPlaneNodeCur = pstPlaneNodeHead->pstNext;if (pstPlaneNodeCur == NULL){printf("No flight record");return;}printf("Choose one way according to:\n 1.flight 2.Dest:\n");scanf_s("%d", &iSel);if (iSel == 1){char acFlight[20];printf("請輸入要查詢的航班號:\n");scanf_s("%s", &acFlight, 20);getchar();//打開訂票信息文件for (pstPlaneNodeCur; pstPlaneNodeCur != NULL; pstPlaneNodeCur = pstPlaneNodeCur->pstNext){if (strcmp(pstPlaneNodeCur->stDate.acFlight, acFlight) == 0){PrintHead();PrintDate(pstPlaneNodeCur);break; //航班號唯一,查到就退出}}}else if (iSel == 2){char acDest;printf("Input the Dest City:\n");scanf_s("%s", &acDest, 20);PrintHead();for (pstPlaneNodeCur; pstPlaneNodeCur != NULL; pstPlaneNodeCur = pstPlaneNodeCur->pstNext){if (strcmp(pstPlaneNodeCur->stDate.acDest, &acDest) == 0){PrintDate(pstPlaneNodeCur);icount++; //同一個目的地可能有多個數(shù)據(jù)}}if (icount == 0) //遍歷完一遍,記錄數(shù)為0,則沒有記錄:{printf("Sorry ,no record!\n");}}else{printf("sorry please input right number1-2");}}修改機票信息
void Mod_menu() {puts("**********************************************************************");puts("----------------------------------------------------------------------");puts(" choose the follow operation(0-8) ");puts("--------------------------------------------------------------------- ");puts("******************* 1 flights ******************** ");puts("******************* 2 Origin ******************** ");puts("******************* 3 Destination ******************** ");puts("******************* 4 Take off time ******************** ");puts("******************* 5 Reverce time ******************** ");puts("******************* 6 Prices ******************** ");puts("******************* 7 Disscount ******************** ");puts("******************* 8 ticket number ******************** ");puts("******************* 0 quits ******************** ");puts("**********************************************************************"); } void Modify(PPlaneNode pstPlaneNodeHead) {assert(pstPlaneNodeHead != NULL);if (pstPlaneNodeHead == NULL){return;}char acFlight[20];PPlaneNode pstPlaneNodeCur = pstPlaneNodeHead->pstNext;if (pstPlaneNodeCur == NULL){printf("No flight to modifty!\n");return;}else{printf("Input the flight number you want to modify:\n");scanf_s("%s", acFlight, 20);for (pstPlaneNodeCur; pstPlaneNodeCur != NULL; pstPlaneNodeCur = pstPlaneNodeCur->pstNext){if (strcmp(pstPlaneNodeCur->stDate.acFlight, acFlight) == 0){break;}}if (pstPlaneNodeCur){//子菜單int isel = 0;system("cls");Mod_menu();printf("please Input 0-8: ");scanf_s("%d", &isel);getchar();switch (isel){case 1:printf("Input new flights!\n");scanf("%s", pstPlaneNodeCur->stDate.acFlight);break;case 2:printf("Input new Origin!\n");scanf("%s", pstPlaneNodeCur->stDate.acOrigin);break;case 3:printf("Input new Destination!\n");scanf("%s", pstPlaneNodeCur->stDate.acDest);break;case 4:printf("Input new Take off time!\n");scanf("%s", pstPlaneNodeCur->stDate.acTakeOffTime);break;case 5:printf("Input new Reverce time!\n");scanf("%s", pstPlaneNodeCur->stDate.acReverceTime);break;case 6:printf("Input new Prices!\n");scanf("%f", &pstPlaneNodeCur->stDate.fPrice);break;case 7:printf("Input new Disscount!\n");scanf("%s", pstPlaneNodeCur->stDate.acDisscount);break;case 8:printf("Input new ticket number!\n");scanf("%d", &pstPlaneNodeCur->stDate.iNum);break;case 0:printf("quit!\n");break;}printf("End Modifying information!\n");}else{printf("flights number not exist!\n");}}}顯示機票信息
void Show(PPlaneNode pstPlaneNodeHead) {assert(pstPlaneNodeHead != NULL);PPlaneNode pstPlaneNodeCur = pstPlaneNodeHead->pstNext;PrintHead();if (pstPlaneNodeHead->pstNext == NULL){printf("no flight ticket!\n");}else{while (pstPlaneNodeCur != NULL){PrintDate(pstPlaneNodeCur);pstPlaneNodeCur = pstPlaneNodeCur->pstNext;}} }推薦機票信息
struct ManNode* FindMan(PManNode pstManNodeHead, char acId[20]){PManNode pstManNodeCur = pstManNodeHead->pstNext;for (pstManNodeCur; pstManNodeCur != NULL; pstManNodeCur = pstManNodeCur->pstNext){if (strcmp(pstManNodeCur->stDate.acID, acId) == 0) // 知道到id號相同的訂票人的{return pstManNodeCur;}}return NULL; }PPlaneNode FindPlane(PPlaneNode pstPlaneNodeHead, char* acBookFlight) {PPlaneNode pstPlaneNodeCur = pstPlaneNodeHead->pstNext;for (pstPlaneNodeCur; pstPlaneNodeCur != NULL; pstPlaneNodeCur = pstPlaneNodeCur->pstNext){if (strcmp(pstPlaneNodeCur->stDate.acFlight, acBookFlight) == 0) // 知道到id號相同的訂票人的{return pstPlaneNodeCur;}}return NULL; } void Recommend(PPlaneNode pstPlaneNodeHead) {//推薦給用用戶合適的機票//時間 地點PPlaneNode pstPlaneNodeCur;char acDest[20];char acTime[10];int iNum = 0;pstPlaneNodeCur = pstPlaneNodeHead->pstNext;printf("Input your destination");scanf_s("%s", acDest, 20);printf("Input the earlist time you can take:");scanf_s("%s", acTime, 10);PrintHead();for (pstPlaneNodeCur; pstPlaneNodeCur != NULL; pstPlaneNodeCur = pstPlaneNodeCur->pstNext){if (strcmp(pstPlaneNodeCur->stDate.acDest, acDest) == 0){if (strcmp(acTime,pstPlaneNodeCur->stDate.acTakeOffTime) < 0){PrintDate(pstPlaneNodeCur);iNum++;}}}}訂票
void Book(PPlaneNode pstPlaneNodeHead, PManNode pstManNodeHead) {//接收訂票人頭指針PPlaneNode pstPlaneNodeCur, astPlaneNode[10];PManNode pstManNodeCur, astManNodeTemp = NULL;char acDest[20];char acId[20];char acName[20];char acSex[10];char acDecision[2];char acFlight[20];int iNum = 0;int iRecord = 0;int k = 0;char iFlag = 0;pstManNodeCur = pstManNodeHead;for (pstManNodeCur; pstManNodeCur->pstNext != NULL; pstManNodeCur = pstManNodeCur->pstNext);//將訂票人結(jié)構(gòu)體指向尾巴//輸入目的地printf("please Input Dest City:\n");scanf_s("%s", &acDest, 20);getchar();//查找目的地 存入結(jié)構(gòu)體數(shù)組中pstPlaneNodeCur = pstPlaneNodeHead->pstNext;for (pstPlaneNodeCur; pstPlaneNodeCur != NULL; pstPlaneNodeCur = pstPlaneNodeCur->pstNext){if (strcmp(pstPlaneNodeCur->stDate.acDest, acDest) == 0){astPlaneNode[iRecord] = pstPlaneNodeCur;iRecord++;}}printf("\n there are %d flight you can choose! \n", iRecord);PrintHead();for (k = 0; k < iRecord; k++){PrintDate(astPlaneNode[k]);}if (iRecord == 0){printf("sorry ,No flights you can book ! \n");}else{printf("do you want to book it?(y(Y)/n(N))");scanf_s("%s", acDecision, 2);getchar();if (strcmp(acDecision, "y") == 0 || strcmp(acDecision, "Y") == 0){printf("Input your information ! \n");astManNodeTemp = (PManNode)malloc(sizeof(ManNode));//assertprintf("Input your Name :\n");scanf_s("%s", acName, 20);strcpy(astManNodeTemp->stDate.acName, acName);printf("Input your Id: \n");scanf_s("%s", acId, 20);strcpy(astManNodeTemp->stDate.acID, acId);printf("Input your sex(M/F) : \n");scanf_s("%s", acSex, 10);strcpy(astManNodeTemp->stDate.acSex, acSex);printf("Input your Flights :\n");scanf_s("%s", acFlight, 20);strcpy(astManNodeTemp->stDate.acBookFilght, acFlight);for (k = 0; k < iRecord; k++){if (strcmp(astPlaneNode[k]->stDate.acFlight, acFlight) == 0){if (astPlaneNode[k]->stDate.iNum < 1){printf("No tickets!");return;}printf("return %d tickets!\n", astPlaneNode[k]->stDate.iNum);iFlag = 1;break;}}if (iFlag == 0){printf("error");return;}printf("Input the book number: \n"); //訂購幾張票scanf_s("%d", &iNum);astPlaneNode[k]->stDate.iNum = astPlaneNode[k]->stDate.iNum - iNum; //還剩下的票數(shù)astManNodeTemp->stDate.iBookNum = iNum; //訂購票數(shù)pstManNodeCur->pstNext = astManNodeTemp; //鏈接鏈表astManNodeTemp->pstNext = NULL;pstManNodeCur = astManNodeTemp; //移動當前鏈表指針位置printf("Finish Book!\n");}} }退票
//退票 void Refund(PPlaneNode pstPlaneNodeHead, PManNode pstManNodeHead) {PManNode pstManNodeCur, pstManNodeFind = NULL;PPlaneNode pstPlaneNodeFind = NULL;char acId[20];char acDecision[2];int iNum = 0; //剩余票數(shù)int iBookNum; ////找到訂票人的結(jié)構(gòu)體printf("Input your Id!\n");scanf_s("%s", acId, 20);pstManNodeFind = FindMan(pstManNodeHead, acId);if (pstManNodeFind == NULL){printf("can;t find!\n");}else//退票{printf("this is your tickets:\n");printf("id number:%s\n", pstManNodeFind->stDate.acID);printf("nmae:%s\n", pstManNodeFind->stDate.acName);printf("sex:%s\n", pstManNodeFind->stDate.acSex);printf("book flight:%s\n", pstManNodeFind->stDate.acBookFilght);printf("book number:%d\n", pstManNodeFind->stDate.iBookNum);printf("do you want to cancel it ?(y/n)");scanf_s("%s", acDecision, 2);getchar();if (strcmp(acDecision, "y") == 0){//找到前驅(qū)for (pstManNodeCur = pstManNodeHead; pstManNodeCur->pstNext != pstManNodeFind;pstManNodeCur = pstManNodeCur->pstNext);//找到該名訂購人的航班記錄pstPlaneNodeFind = FindPlane(pstPlaneNodeHead, pstManNodeFind->stDate.acBookFilght);//退票if (pstPlaneNodeFind != NULL){iNum = pstPlaneNodeFind->stDate.iNum;//機票剩余票數(shù)iBookNum = pstManNodeFind->stDate.iBookNum; //訂購人訂購票數(shù)pstPlaneNodeFind->stDate.iNum = iNum + iBookNum;}//刪除訂票人節(jié)點pstManNodeCur->pstNext = pstManNodeFind->pstNext;printf("successful!\n"); //成功退訂 iSave = 1;free(pstManNodeFind);}}}保存信息
//保存機票信息 void SavePlane(struct PlaneNode* pstPlaneNodeHead) {FILE* pfPlane; // 機票的文件指針struct PlaneNode* pstPlaneNodeCur;int count = 0; //保存信息個數(shù)int iFlag = 1;int error = 0;//pfPlane = fopen("plane.txt", "wb");error = fopen_s(&pfPlane, "plane.txt", "wb");if (error != 0){printf("the file can't be opened!\n");return;}//寫入信息pstPlaneNodeCur = pstPlaneNodeHead->pstNext;while (pstPlaneNodeCur != NULL){if (fwrite(pstPlaneNodeCur, sizeof(struct PlaneNode), 1, pfPlane) == 1){pstPlaneNodeCur = pstPlaneNodeCur->pstNext;count++;}else{iFlag = 0;break;}}//提示保存信息數(shù)目 ISave置為0if (iFlag){printf("you have save %d flights\n", &count);iSave = 0;}//關(guān)閉文件fclose(pfPlane); } //保存訂票人信息 void SaveMan(struct ManNode* pstManNodeHead) {assert(pstManNodeHead != NULL);if (pstManNodeHead == NULL){return;}FILE* pfMan;struct ManNode* pstManNodeCur;int count = 0;int iFlag = 1;int error = 0;//pfMan = fopen("man.txt", "wb");error = fopen_s(&pfMan, "man.txt", "wb");if (error != 0){printf("the file can't be opened!\n");}//寫入信息pstManNodeCur = pstManNodeHead->pstNext;while (pstManNodeCur != NULL){if (fwrite(pstManNodeCur, sizeof(struct ManNode), 1, pfMan) == 1){pstManNodeCur = pstManNodeCur->pstNext;count++;}else{iFlag = 0;break;}if (iFlag){printf("you have save %d man", count);iSave = 0;}fclose(pfMan);} }顯示時間
//顯示當前時間 void NowTime() {time_t curtime;curtime = time(NULL);printf("現(xiàn)在的時間是:%s", ctime(&curtime)); }測試
先進行添加機票功能的測試
將添加機票信息輸入完整,然后輸入-1返回主菜單
然后對查詢機票功能進行測試,輸入剛剛添加的航班號,可以看出已經(jīng)查詢到新添加的機票信息
然后對修改機票信息功能進行測試,我們將目的地修改為beijing
然后返回主菜單,測試顯示所有機票信息的功能
可以看出已經(jīng)成功把1005號航班的目的地修改為beijing
對推薦機票功能進行測試
選擇你要去的地方和你最早可以到達時間,然后會打印符合條件的機票信息
然后對訂票功能進行測試
然后對退票功能進行測試,通過ID可以定位到剛剛訂票的信息,然后選擇退票
總結(jié)
以上是生活随笔為你收集整理的C语言实现飞机订票系统的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 工业控制领域关键技术趋势
- 下一篇: Java 框架、库和软件的精选列表(Aw