C語言實(shí)現(xiàn)飛機(jī)訂票系統(tǒng)的完整代碼
題目
本文將設(shè)計(jì)一個(gè)飛機(jī)訂票系統(tǒng),主要包括機(jī)票的添加、修改、查找、訂票、退票、推薦機(jī)票功能,用C語言編程實(shí)現(xiàn),并用鏈表存儲產(chǎn)生的航班信息和訂票信息數(shù)據(jù),最后可以把鏈表中的數(shù)據(jù)保存到文件中。
總體設(shè)計(jì)和需求分析
設(shè)計(jì)目的
1.怎樣去合理的設(shè)計(jì)一個(gè)數(shù)據(jù)結(jié)構(gòu)來存儲訂票信息和航班信息
2.加深對鏈表的增刪改查功能的學(xué)習(xí)和理解
3.學(xué)習(xí)如何鏈表和外部文件之間的讀取和存儲操作
4.學(xué)習(xí)如何將學(xué)到的知識應(yīng)用到實(shí)際的問題中
總體設(shè)計(jì)和功能
此飛機(jī)訂票系統(tǒng)將實(shí)現(xiàn)以下功能:
1.初始化功能
該功能將實(shí)現(xiàn)將航班信息文件和訂票人訂票信息文件中的數(shù)據(jù)讀取到鏈表中。
2.添加機(jī)票信息功能
該功能將實(shí)現(xiàn)添加航班機(jī)票信息,信息包括航班號、出發(fā)地、目的地、起飛時(shí)間、降落時(shí)間、票價(jià)、折扣、剩余票數(shù),然后用鏈表將數(shù)據(jù)保存起來。
3.查詢機(jī)票信息功能
該功能將實(shí)現(xiàn)通過航班號來查詢機(jī)票信息的功能
4.修改機(jī)票信息功能
該功能將通過航班號調(diào)用查找機(jī)票信息功能,定位到要修改的航班信息上,然后通過航班信息子菜單確定要修改的某一項(xiàng)航班信息。
5.顯示機(jī)票信息
該功能將實(shí)現(xiàn)把所有航班信息顯示出來
7.推薦機(jī)票功能
該功能將實(shí)現(xiàn)通過輸入目的地,和乘客最早出發(fā)時(shí)間可以獲得符合條件的航班信息
8.訂票功能
該功能下乘客輸入目的地,并且輸入訂票人的姓名、身份證號碼、性別、購票數(shù)量、訂購航班號以實(shí)現(xiàn)用戶訂票功能
9.退票功能
該功能下乘客可以訂購的機(jī)票進(jìn)行退回。
10.顯示時(shí)間功能
該功能可以顯示實(shí)時(shí)時(shí)間
11.保存信息功能
該功能下可以把鏈表中的信息保存到文件中。
結(jié)構(gòu)體設(shè)計(jì)
我們將定義兩個(gè)結(jié)構(gòu)體,分別為機(jī)票信息結(jié)構(gòu)體和訂票人信息結(jié)構(gòu)體
機(jī)票信息結(jié)構(gòu)體
typedef struct AirPlane { char acFlight[20];//航班號 char acOrigin[10]; //出發(fā)地 char acDest[20]; //目的地 char acTakeOffTime[10]; //起飛時(shí)間 char acReverceTime[10]; //降落時(shí)間 float fPrice; //票價(jià) char acDisscount[4]; //折扣 int iNum; //剩余票數(shù) }AirPlane, * PAirPlane; //定義機(jī)票信息節(jié)點(diǎn)的結(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é)點(diǎn)的結(jié)構(gòu)體 typedef struct ManNode { struct Man stDate; struct ManNode* pstNext; }ManNode, * PManNode;
主函數(shù)的設(shè)計(jì)
在主函數(shù)中,首先將通過初始化函數(shù)把文件中的數(shù)據(jù)讀取到鏈表中,然后可以通過switch選擇用戶在飛機(jī)訂票系統(tǒng)中需要執(zhí)行的操作
//作為數(shù)據(jù)改動(dòng)的標(biāo)志 int iSave = 0; int main() { struct PlaneNode pstPlaneNodeHead; //機(jī)票信息頭結(jié)點(diǎn) pstPlaneNodeHead.pstNext = NULL; struct ManNode pstManNodeHead; //購票信息頭結(jié)點(diǎn) 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("進(jìn)入添加機(jī)票頁面\n"); Insert(&pstPlaneNodeHead); // 添加機(jī)票信息 break; case 2: Search(&pstPlaneNodeHead); //查詢機(jī)票信息 break; case 3: Book(&pstPlaneNodeHead, &pstManNodeHead);//訂票 break; case 4: Modify(&pstPlaneNodeHead); //修改機(jī)票信息 break; case 5: Show(&pstPlaneNodeHead); //顯示機(jī)票信息 break; case 6: Recommend(&pstPlaneNodeHead); //推薦機(jī)票信息 break; case 7: Refund(&pstPlaneNodeHead, &pstManNodeHead);//退票信息 break; case 8: NowTime();//顯示當(dāng)前時(shí)間 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); // 保存機(jī)票信息 } } Destroy(&pstPlaneNodeHead, &pstManNodeHead); return 0; } printf("\nplease press any key to continue...\n"); _getch(); } Destroy(&pstPlaneNodeHead, &pstManNodeHead); return 0; }
各功能代碼的實(shí)現(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) { //先加載飛機(jī)機(jī)票信息 FILE* pfPlane; //定義飛機(jī)機(jī)票信息文件指針 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)) //讀到文件最后一個(gè)數(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); //此時(shí),釋放的是文件讀完后最后一次申請的指針 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; }
添加機(jī)票
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指向最后一個(gè)節(jié)點(diǎn) 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ù) ,則重新建一個(gè)鏈表節(jié)點(diǎn) 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; //如果有新的航班信息,保存標(biāo)準(zhǔn)置為1,若退出需要提示是否保存信息(見主函數(shù)) iSave = 1; } }
查找機(jī)票信息
//查詢機(jī)票信息 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++; //同一個(gè)目的地可能有多個(gè)數(shù)據(jù) } } if (icount == 0) //遍歷完一遍,記錄數(shù)為0,則沒有記錄: { printf("Sorry ,no record!\n"); } } else { printf("sorry please input right number1-2"); } }
修改機(jī)票信息
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"); } } }
顯示機(jī)票信息
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; } } }
推薦機(jī)票信息
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) { //推薦給用用戶合適的機(jī)票 //時(shí)間 地點(diǎn) 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)); //assert printf("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; //移動(dòng)當(dāng)前鏈表指針位置 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;//機(jī)票剩余票數(shù) iBookNum = pstManNodeFind->stDate.iBookNum; //訂購人訂購票數(shù) pstPlaneNodeFind->stDate.iNum = iNum + iBookNum; } //刪除訂票人節(jié)點(diǎn) pstManNodeCur->pstNext = pstManNodeFind->pstNext; printf("successful!\n"); //成功退訂 iSave = 1; free(pstManNodeFind); } } }
保存信息
//保存機(jī)票信息 void SavePlane(struct PlaneNode* pstPlaneNodeHead) { FILE* pfPlane; // 機(jī)票的文件指針 struct PlaneNode* pstPlaneNodeCur; int count = 0; //保存信息個(gè)數(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置為0 if (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); } }
顯示時(shí)間
//顯示當(dāng)前時(shí)間 void NowTime() { time_t curtime; curtime = time(NULL); printf("現(xiàn)在的時(shí)間是:%s", ctime(&curtime)); }
測試
先進(jìn)行添加機(jī)票功能的測試
將添加機(jī)票信息輸入完整,然后輸入-1返回主菜單
然后對查詢機(jī)票功能進(jìn)行測試,輸入剛剛添加的航班號,可以看出已經(jīng)查詢到新添加的機(jī)票信息
然后對修改機(jī)票信息功能進(jìn)行測試,我們將目的地修改為beijing
然后返回主菜單,測試顯示所有機(jī)票信息的功能
可以看出已經(jīng)成功把1005號航班的目的地修改為beijing
對推薦機(jī)票功能進(jìn)行測試
選擇你要去的地方和你最早可以到達(dá)時(shí)間,然后會打印符合條件的機(jī)票信息
然后對訂票功能進(jìn)行測試
然后對退票功能進(jìn)行測試,通過ID可以定位到剛剛訂票的信息,然后選擇退票
總結(jié)
到此這篇關(guān)于C語言實(shí)現(xiàn)飛機(jī)訂票系統(tǒng)的文章就介紹到這了,更多相關(guān)C語言飛機(jī)訂票系統(tǒng)內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
相關(guān)文章
基于C語言實(shí)現(xiàn)學(xué)生管理系統(tǒng)
這篇文章主要為大家詳細(xì)介紹了基于C語言實(shí)現(xiàn)學(xué)生管理系統(tǒng),文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2022-03-03C++虛函數(shù)表與類的內(nèi)存分布深入分析理解
對C++ 了解的人都應(yīng)該知道虛函數(shù)(Virtual Function)是通過一張?zhí)摵瘮?shù)表(Virtual Table)來實(shí)現(xiàn)的。簡稱為V-Table。本文就將詳細(xì)講講虛函數(shù)表的原理與使用,需要的可以參考一下2022-08-08matlab?GUI指紋識別門禁系統(tǒng)介紹及源碼實(shí)現(xiàn)
這篇文章主要為大家介紹了matlab?GUI指紋識別門禁系統(tǒng)的介紹及源碼實(shí)現(xiàn),有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步2022-02-02C++對象內(nèi)存分布詳解(包括字節(jié)對齊和虛函數(shù)表)
下面小編就為大家?guī)硪黄狢++對象內(nèi)存分布詳解(包括字節(jié)對齊和虛函數(shù)表)。小編覺得挺不錯(cuò)的,現(xiàn)在就分享給大家,也給大家做個(gè)參考。一起跟隨小編過來看看吧2016-12-12C語言編程中常見的五種錯(cuò)誤及對應(yīng)解決方案
這篇文章主要給大家分享的是C語言編程中常見的五種錯(cuò)誤及對應(yīng)解決方案,詳細(xì)內(nèi)容就請跟小編一起進(jìn)入下面的文章內(nèi)容吧2021-10-10C/C++ 中sizeof(''a'')對比詳細(xì)介紹
這篇文章主要介紹了C/C++ 中sizeof('a')的值對比詳細(xì)介紹的相關(guān)資料,需要的朋友可以參考下2017-02-02利用C++實(shí)現(xiàn)簡易的.ini配置文件解析器
這篇文章主要為大家詳細(xì)介紹了如何基于C++編寫一個(gè)簡易的.ini配置文件解析器,文中的示例代碼講解詳細(xì),具有一定的借鑒價(jià)值,感興趣的小伙伴可以了解一下2023-03-03