日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 运维知识 > windows >内容正文

windows

课程设计(飞机订票系统) 超全

發布時間:2023/12/14 windows 28 豆豆
生活随笔 收集整理的這篇文章主要介紹了 课程设计(飞机订票系统) 超全 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

圖書館管理系統(附源碼及操作視頻動圖演示)

搭建思路圖:

操作使用鏈表實現,編譯器使用vs2019

成員框架搭建:

用戶進入操作界面,選擇添加機票信息,包括(飛機航班號,出發地,目的地,起飛時間,降落時間,飛機票價,當日折扣,機票總數)

進入訂票系統,輸入起飛地,目的地,調用查詢函數會打印機票信息到屏幕,若沒有則告知,如果有,訂票人開始訂票。輸入(姓名,身份證號,性別,訂購航班,購票數量)

#define _CRT_SECURE_NO_WARNINGS #include<stdio.h> #include<stdlib.h> #include<conio.h> #include<string.h> #include<time.h>struct AirPlane {char acFlight[10];//航班號char acOrigin[10];//出發地char acDest[10];//目的地char acTakeOffTime[10];//起飛時間char acReverveTime[10];//降落時間float fPrice;//票價char acDiscount[4];//折扣int iNum;//票數 }; struct Man {char acName[20];//姓名char acID[20];//身份證號char acSex[10];//性別int iBookNum;//購票數量char acBookFilight[10];//訂購的航班號 }; //定義機票信息結點的結構體 typedef struct PlaneNode {struct AirPlane data;struct PlaneNode* next; }PlaneNode, * PLNode; //定義訂票人信息結點的結構體 typedef struct ManNode {struct Man data;struct ManNode* next; }ManNode, * MANNode;int iSave = 0;//作為數據是否改動的標志

操作主頁面及主函數:

void Menu() {puts("***********************************************************");puts("****** Welcome to the airplane tickets booking system *****");puts("-----------------------------------------------------------");puts("****** Choose the following operations(0-9) *****");puts("-----------------------------------------------------------");puts("** 1.Insert fligths 2.Search fligths **");puts("** 3.Book fligths 4.Modify fligths **");puts("** 5.Show fligths 6.Recommed fligths **");puts("** 7.Refund fligths 8.NowTime fligths **");puts("** 9.Save Messages 0.Exist **");puts("-----------------------------------------------------------"); } int main() {PlaneNode pstPlaneNodeHead;//機票信息頭結點pstPlaneNodeHead.next = NULL;ManNode pstManNodeHead; //訂票人頭結點pstManNodeHead.next = NULL;int res;res = Init(&pstPlaneNodeHead, &pstManNodeHead);//將文件的數據加載到內存中if (res < 0){return 0;}int iSel;//用于接收用戶對于功能的選擇char c1; //是否保存while(1){system("cls");Menu();printf("Input 0-9 operations:");scanf("%d", &iSel);getchar();system("cls");switch(iSel){case 1://Insert(&pstPlaneNodeHead);//添加機票信息break;case 2://Search(&pstPlaneNodeHead);//查詢機票信息break;case 3://Book(&pstManNodeHead, &pstPlaneNodeHead);//預定機票系統break;case 4://Modify(&pstPlaneNodeHead);//修改機票信息break;case 5://Show(&pstPlaneNodeHead);//顯示所有機票信息break;case 6://Recommed(&pstPlaneNodeHead);//推薦機票信息break;case 7://Refund(&pstManNodeHead, &pstPlaneNodeHead);//退票操作break;case 8://NowTime();//顯示當前時間break;case 9://SaveMan(&pstManNodeHead);//保存訂票人信息//SavePlane(&pstPlaneNodeHead);//保存機票信息case 0:if (iSave == 1){printf("Do you want to save message (y/n)");scanf("%c", &c1);getchar();if (c1 == 'y' || c1 == 'Y'){//SaveMan(&pstManNodeHead);//保存訂票人的信息//SavePlane(&pstPlaneNodeHead);//保存機票信息}}//Destroy(pstManNodeHead,pstPlaneNodeHead);return 0;}printf("please press any key continue...");_getch();}//Destroy(pstManNodeHead,pstPlaneNodeHead);return 0; }

函數實現:

一.添加機票信息

將添加的機票信息文件寫入內存中,之后的每次操作都在內存中進行

int Init(PLNode pstPlaneNodeHead, MANNode pstManNodeHead)//將文件的數據加載到內存中 {//先加載飛機機票信息FILE* pfplane;//定義飛機機票文件指針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{//把文件數據讀入鏈表中while (!feof(pfplane)){pstPlaneNodeTemp = (PlaneNode*)malloc(sizeof(PlaneNode));//申請臨時結點if (fread(pstPlaneNodeTemp, sizeof(PlaneNode), 1, pfplane) == 1){pstPlaneNodeTemp->next = NULL;pstPlaneNodeCur->next = pstPlaneNodeTemp;pstPlaneNodeCur = pstPlaneNodeTemp;}}free(pstPlaneNodeTemp);fclose(pfplane);}//2.再加載訂票人信息FILE* pfman;//定義文件指針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 = (ManNode*)malloc(sizeof(ManNode));//申請臨時結點if (fread(pstManNodeTemp, sizeof(ManNode), 1, pfman) == 1){pstManNodeTemp->next = NULL;pstManNodeCur->next = pstManNodeTemp;pstManNodeCur = pstManNodeTemp;}}free(pstManNodeTemp);fclose(pfman);}return 0; } void Insert(PLNode pstPlaneNodeHead)//添加機票信息 {PlaneNode* pstHead, * pstTail, * pstCur, * pstNew;char acFlight[10];//保存航班號pstHead = pstTail = pstPlaneNodeHead;//找尾巴//讓pstTail指向最后一個結點while (pstTail->next != NULL){pstTail = pstTail->next;}while (1){printf("Input the new flight number(-1 to end):");scanf("%s", acFlight);getchar();if (strcmp(acFlight, "-1") == 0){break;}//判斷航班號是否重復pstCur = pstPlaneNodeHead->next;while (pstCur != NULL){if (strcmp(pstCur->data.acFlight, acFlight) == 0){printf("this flight %s exists!\n", acFlight);return;}pstCur = pstCur->next;}//如果航班號沒有和現有紀錄重復,則新建一個鏈表結點pstNew = (PlaneNode*)malloc(sizeof(PlaneNode));strcpy(pstNew->data.acFlight, acFlight);printf("Input the Start City:");scanf("%s", pstNew->data.acOrigin);printf("Input the Dest City:");scanf("%s", pstNew->data.acDest);printf("Input the Departure time (Format 00:00):");scanf("%s", pstNew->data.acTakeOffTime);printf("Input the Arrival time (Format 00:00):");scanf("%s", pstNew->data.acReverveTime);printf("Input the price of ticket:");scanf("%f", &pstNew->data.fPrice);printf("Input the discount of ticket(Format 0.0):");scanf("%s", pstNew->data.acDiscount);printf("Input the number of tickets:");scanf("%d", &pstNew->data.iNum);pstNew->next = NULL;pstTail -> next = pstNew;pstTail = pstNew;iSave = 1;//有新的航班信息,保存標志為1} }

二.查詢機票信息

選擇航班號查詢,目的地,出發地查詢,可自行添加其他查詢

void Search(PLNode pstPlaneNodeHead)//查詢機票信息 {PlaneNode* pstPlaneNode;int Sel = 0;int count = 0;//計數器char acFlight[10], acDes[10],acstart[10];//航班號和目的地pstPlaneNode = pstPlaneNodeHead->next;if (pstPlaneNode == NULL){printf("is not have data");return;}//按航班號查詢//按目的地查詢//按起始地查詢printf("Choose one way according to:\n1.flight number 2.Dest 3.Start\n");scanf("%d", &Sel);if (Sel == 1){//按航班號查詢printf("input the right flight number:");scanf("%s", acFlight);PrintfHead();//機票信息頭部打印while (pstPlaneNode != NULL){if (strcmp(pstPlaneNode->data.acFlight, acFlight) == 0){PrintData(pstPlaneNode);break;//航班號唯一}else{pstPlaneNode = pstPlaneNode->next;}}//遍歷結束,沒有break,則沒有用戶記錄if (pstPlaneNode == NULL){printf("Sorry,no record!\n");return;}}else if (Sel == 2){//按目的地查詢printf("input the right Dest:");scanf("%s", acDes);PrintfHead();//機票信息頭部打印while (pstPlaneNode != NULL){if (strcmp(pstPlaneNode->data.acDest, acDes) == 0){PrintData(pstPlaneNode);count++;}pstPlaneNode = pstPlaneNode->next;}//遍歷結束,計數器為0,則沒有記錄if (count ==0){printf("Sorry,no record!\n");return;}}else if (Sel == 3){//按起始地查詢printf("input the right Start:");scanf("%s", acstart);PrintfHead();//機票信息頭部打印while (pstPlaneNode != NULL){if (strcmp(pstPlaneNode->data.acOrigin, acstart) == 0){PrintData(pstPlaneNode);count++;}pstPlaneNode = pstPlaneNode->next;}//遍歷結束,計數器為0,則沒有記錄if (count == 0){printf("Sorry,no record!\n");return;}}else{printf("Sorry,please input right number 1-3:\n");return;} }

三.訂票操作

思路:輸入起始地和目的地,顯示是否有票若有,多條航班(存入數據到結構體中)? ? ? ? ? ? ? ? ? ? ??? 訂票:輸入訂票人信息
訂票:選擇航班號

void Book(MANNode pstManNodeHead, PLNode pstPlaneNodeHead)//訂票 {//思路:輸入起始地和目的地,顯示是否有票若有,多條航班(存入數據到結構體中)//訂票:輸入訂票人信息//訂票:選擇航班號PlaneNode * pstPlaneNodeCur,*astPlane[10]; //保存數據臨時結構體數組ManNode* pstManNodeCur,*pstManNodeTemp=NULL;char acOrigin[10], acDest[10], acID[20], acName[20], acSex[10], acDescision[2], acFlight[10];int iNum = 0, Record = 0, k = 0, flg = 0;//接受訂票人信息頭指針pstManNodeCur=pstManNodeHead;while (pstManNodeCur->next != NULL){pstManNodeCur = pstManNodeCur->next;}//將訂票人結構體指向尾巴//輸入起始地和目的地printf("input the start city:");scanf("%s",acOrigin);printf("input the Dest city:");scanf("%s",acDest);//查找起始地和目的地,存入臨時結構體數組中pstPlaneNodeCur = pstPlaneNodeHead->next;while (pstPlaneNodeCur != NULL){if (strcmp(pstPlaneNodeCur->data.acOrigin,acOrigin) == 0&&strcmp(pstPlaneNodeCur->data.acDest,acDest) == 0){astPlane[Record++] = pstPlaneNodeCur;}pstPlaneNodeCur = pstPlaneNodeCur->next;}//打印數據printf("there are %d flights you can choose!\n",Record);PrintfHead();for (k = 0; k < Record; k++){PrintData(astPlane[k]);}if (Record == 0){printf("Sorry,no flights you can book\*/\n");}//訂票else{printf("do you want to book it?(y(Y))/n(N))\n");scanf("%s", acDescision);getchar();if (strcmp(acDescision, "y") == 0 || strcmp(acDescision, "Y") == 0){printf("input your information!\n");pstManNodeTemp = (ManNode*)malloc(sizeof(ManNode));printf("input your name:");scanf("%s", acName);strcpy(pstManNodeTemp->data.acName, acName);printf("input your id:");scanf("%s", acID);strcpy(pstManNodeTemp->data.acID, acID);printf("input your sex(M/W):");scanf("%s", acSex);strcpy(pstManNodeTemp->data.acSex, acSex);printf("input your want to book flight number:");scanf("%s", acFlight);strcpy(pstManNodeTemp->data.acBookFilight,acFlight);for (k = 0; k < Record; k++){if (strcmp(astPlane[k]->data.acFlight, acFlight) == 0){if (astPlane[k]->data.iNum < 1){printf("no ticket!");return;}printf("remain %d tickets!\n", astPlane[k]->data.iNum);flg = 1;break;}}if (flg == 0){printf("error\n");return;}printf("Input the book number:");scanf("%d", &iNum);//訂購幾張票astPlane[k]->data.iNum = astPlane[k]->data.iNum - iNum;pstManNodeTemp->data.iBookNum = iNum;pstManNodeCur->next = pstManNodeTemp;pstManNodeTemp->next = NULL;pstManNodeCur = pstManNodeTemp;//可以不要printf("success!\n");iSave = 1;}} }

四.修改機票信息

為了方便,此處我并未創建新的子菜單,想要更加美觀可以自行創建各個函數的子菜單頁面

void Modify(PLNode pstPlaneNodeHead)//修改機票信息 {PlaneNode* pstPlaneNodeCur;char acFlight[10];pstPlaneNodeCur = pstPlaneNodeHead->next;if (pstPlaneNodeCur == NULL){printf("no flight to be modify!");return;}else{printf("Input the flight number you want to modify!:");scanf("%s", acFlight);while (pstPlaneNodeCur){if (strcmp(pstPlaneNodeCur->data.acFlight, acFlight) == 0){break;}else{pstPlaneNodeCur = pstPlaneNodeCur->next;}}if (pstPlaneNodeCur){printf("input the new start city:");scanf("%s", pstPlaneNodeCur->data.acOrigin);printf("input the new arrval city:");scanf("%s", pstPlaneNodeCur->data.acDest);printf("input the new dicount:");scanf("%s", pstPlaneNodeCur->data.acDiscount);printf("input the new acTakeOffTime:");scanf("%s", pstPlaneNodeCur->data.acTakeOffTime);printf("input the new acReverveTime:");scanf("%s", pstPlaneNodeCur->data.acReverveTime);printf("input the new fPrice:");scanf("%f", &pstPlaneNodeCur->data.fPrice);printf("input the new iNum:");scanf("%d", &pstPlaneNodeCur->data.iNum);printf("modify successful!\n");iSave = 1;//此處可以封裝一個函數,讓這塊代碼不這么冗雜}} }

五.顯示機票信息

void PrintfHead()//打印機票頭部信息 {printf("|------------------------------------------------------------------------------|\n");printf("|***********************************************************************|******|\n");printf("|Flight|StartCity|DseCity|DepertureTime|ArrivalTime|***price***|Discount|number|\n");printf("|******|*********|*******|*************|***********|***********|********|******|\n");printf("|------------------------------------------------------------------------------|\n"); } void PrintData(PLNode pstPlaneNodeCur) {PlaneNode* pst = pstPlaneNodeCur;printf(" %3s%8s%8s%12s%12s%16f%7s%8d\n", pst->data.acFlight, pst->data.acOrigin, pst->data.acDest, pst->data.acTakeOffTime, pst->data.acReverveTime, pst->data.fPrice, pst->data.acDiscount, pst->data.iNum); } void Show(PLNode pstPlaneNodeHead)//顯示所有機票信息 {PlaneNode* pstPlaneNodeCur = pstPlaneNodeHead->next;PrintfHead();if (pstPlaneNodeHead->next == NULL){printf("no flight ticket!\n");}else{while (pstPlaneNodeCur != NULL){PrintData(pstPlaneNodeCur);pstPlaneNodeCur = pstPlaneNodeCur->next;}} }

六.推薦機票信息

根據用戶輸入的出發地,目的地以及用戶可以乘坐最早的時間(系統會給出這個時間后所有符合信息的機票信息)

void Recommed(PLNode pstPlaneNodeHead)//推薦機票信息 {PlaneNode* pstPlaneNodeCur;char acDest[10], acTime[10],acOrigin[10];int iNum=0;pstPlaneNodeCur = pstPlaneNodeHead->next;printf("input your take city:");scanf("%s", acOrigin);printf("input your destination city:");scanf("%s", acDest);printf("input the earlist time you can take:");scanf("%s", acTime);PrintfHead();while (pstPlaneNodeCur != NULL){if (strcmp(pstPlaneNodeCur->data.acOrigin, acOrigin) == 0 && strcmp(pstPlaneNodeCur->data.acDest, acDest) == 0&& strcmp(acTime, pstPlaneNodeCur->data.acTakeOffTime) < 0){PrintData(pstPlaneNodeCur);iNum++;}pstPlaneNodeCur = pstPlaneNodeCur->next;}printf("there are %d flights you can choose!\n", iNum);if (iNum != 0){printf("please choose 3rd operation to book it!\n");} }

七.退票操作

輸入訂票人身份證號,顯示相應的訂票信息,選擇退票

//找到id號相同的訂票人記錄,返回訂票人節點 MANNode FindMan(MANNode pstManNodeHead, char acID[20]) {ManNode* pstManNodeCur = pstManNodeHead->next;while (pstManNodeCur){if (strcmp(pstManNodeCur->data.acID, acID) == 0){return pstManNodeCur;}pstManNodeCur = pstManNodeCur->next;}return NULL; } //找到訂票人信息中的航班號記錄,找到相應機票信息節點 PLNode FindPlane(PLNode pstPlaneNodeHead, char* acBookFlight) {PlaneNode* pstPlaneNodeCur = pstPlaneNodeHead->next;while (pstPlaneNodeCur){if (strcmp(pstPlaneNodeCur->data.acFlight, acBookFlight) == 0){return pstPlaneNodeCur;}pstPlaneNodeCur = pstPlaneNodeCur->next;}return NULL;} void Refund(MANNode pstManNodeHead, PLNode pstPlaneNodeHead)//退票 {ManNode* pstManNodeCur, * pstManNodeFind = NULL;PlaneNode* pstPlaneNodeFind = NULL;char acID[20],acdescison[2];int iNum;//剩余票數int iBooknum;//定了幾個票printf("input your id number :");scanf("%s", acID);//找到訂票人的結構體pstManNodeFind = FindMan(pstManNodeHead, acID);if (pstManNodeFind == NULL){printf("can't find!\n");}else//退票{printf("this is your tickets:\n");printf("id number is :%s\n", pstManNodeFind->data.acID);printf("name is :%s\n", pstManNodeFind->data.acName);printf("sex is :%s\n", pstManNodeFind->data.acSex);printf("book flights :%s\n", pstManNodeFind->data.acBookFilight);printf("book number :%d\n", pstManNodeFind->data.iBookNum);printf("if you want to cancel it (y/n)?: ");scanf("%s", acdescison);if (strcmp(acdescison, "y") == 0 || strcmp(acdescison, "Y") == 0){//找到前驅pstManNodeCur = pstManNodeHead;while (pstManNodeCur->next != pstManNodeFind){pstManNodeCur = pstManNodeCur->next;}//找到該訂票人對應航班記錄pstPlaneNodeFind =FindPlane(pstPlaneNodeHead, pstManNodeFind->data.acBookFilight);//退票if (pstPlaneNodeFind != NULL){iNum = pstPlaneNodeFind->data.iNum;//機票剩余票數iBooknum = pstManNodeFind->data.iBookNum;//訂購人定票數pstPlaneNodeFind->data.iNum = iNum + iBooknum;}//刪除訂票人節點pstManNodeCur->next = pstManNodeFind->next;free(pstManNodeFind);printf("successful refund!\n");iSave = 1;}} }

八.顯示當前時間

void NowTime()//顯示當前時間 {time_t It;It = time(NULL);printf("現在的時間是:%s ", ctime(&It)); }

九.保存機票信息,訂票人信息

如果沒有在操作界面選擇保存信息,在退出系統時,主函數調用該函數,問用戶是否選擇保存剛剛錄入內存的信息

void SaveMan(MANNode pstManNodeHead)//保存訂票人信息 {FILE* pfMan; ManNode* pstManNodeCur;int count = 0; //保存多少條信息int iflg = 1; //是否寫入信息pfMan = fopen("man.txt", "wb");if (pfMan == NULL){printf("the file can't be opened!");return;}pstManNodeCur = pstManNodeHead->next;while (pstManNodeCur != NULL){if (fwrite(pstManNodeCur, sizeof(ManNode), 1, pfMan) == 1){pstManNodeCur = pstManNodeCur->next;count++;}else{iflg = 0;break;}}fclose(pfMan); } void SavePlane(PLNode pstPlaneNodeHead)//保存機票信息 {FILE* pfPlane; //機票文件信息PlaneNode* pstPlaneNodeCur;int count = 0; //保存多少條信息int iflg = 1; //是否寫入信息pfPlane = fopen("plane.txt", "wb");if (pfPlane == NULL){printf("the file can't be opened!");return;}pstPlaneNodeCur = pstPlaneNodeHead->next;while (pstPlaneNodeCur != NULL){if (fwrite(pstPlaneNodeCur,sizeof(PlaneNode) ,1, pfPlane)==1){pstPlaneNodeCur = pstPlaneNodeCur->next;count++;}else{iflg = 0;break;}}if (iflg){printf("you have save %d flights", count);iSave = 0;}fclose(pfPlane); }

覺得前面太啰嗦,完整代碼在這里:

#define _CRT_SECURE_NO_WARNINGS #include<stdio.h> #include<stdlib.h> #include<conio.h> #include<string.h> #include<time.h>struct AirPlane {char acFlight[10];//航班號char acOrigin[10];//出發地char acDest[10];//目的地char acTakeOffTime[10];//起飛時間char acReverveTime[10];//降落時間float fPrice;//票價char acDiscount[4];//折扣int iNum;//票數 }; struct Man {char acName[20];//姓名char acID[20];//身份證號char acSex[10];//性別int iBookNum;//購票數量char acBookFilight[10];//訂購的航班號 }; //定義機票信息結點的結構體 typedef struct PlaneNode {struct AirPlane data;struct PlaneNode* next; }PlaneNode, * PLNode; //定義訂票人信息結點的結構體 typedef struct ManNode {struct Man data;struct ManNode* next; }ManNode, * MANNode;int iSave = 0;//作為數據是否改動的標志int Init(PLNode pstPlaneNodeHead, MANNode pstManNodeHead)//將文件的數據加載到內存中 {//先加載飛機機票信息FILE* pfplane;//定義飛機機票文件指針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{//把文件數據讀入鏈表中while (!feof(pfplane)){pstPlaneNodeTemp = (PlaneNode*)malloc(sizeof(PlaneNode));//申請臨時結點if (fread(pstPlaneNodeTemp, sizeof(PlaneNode), 1, pfplane) == 1){pstPlaneNodeTemp->next = NULL;pstPlaneNodeCur->next = pstPlaneNodeTemp;pstPlaneNodeCur = pstPlaneNodeTemp;}}free(pstPlaneNodeTemp);fclose(pfplane);}//2.再加載訂票人信息FILE* pfman;//定義文件指針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 = (ManNode*)malloc(sizeof(ManNode));//申請臨時結點if (fread(pstManNodeTemp, sizeof(ManNode), 1, pfman) == 1){pstManNodeTemp->next = NULL;pstManNodeCur->next = pstManNodeTemp;pstManNodeCur = pstManNodeTemp;}}free(pstManNodeTemp);fclose(pfman);}return 0; } void Insert(PLNode pstPlaneNodeHead)//添加機票信息 {PlaneNode* pstHead, * pstTail, * pstCur, * pstNew;char acFlight[10];//保存航班號pstHead = pstTail = pstPlaneNodeHead;//找尾巴//讓pstTail指向最后一個結點while (pstTail->next != NULL){pstTail = pstTail->next;}while (1){printf("Input the new flight number(-1 to end):");scanf("%s", acFlight);getchar();if (strcmp(acFlight, "-1") == 0){break;}//判斷航班號是否重復pstCur = pstPlaneNodeHead->next;while (pstCur != NULL){if (strcmp(pstCur->data.acFlight, acFlight) == 0){printf("this flight %s exists!\n", acFlight);return;}pstCur = pstCur->next;}//如果航班號沒有和現有紀錄重復,則新建一個鏈表結點pstNew = (PlaneNode*)malloc(sizeof(PlaneNode));strcpy(pstNew->data.acFlight, acFlight);printf("Input the Start City:");scanf("%s", pstNew->data.acOrigin);printf("Input the Dest City:");scanf("%s", pstNew->data.acDest);printf("Input the Departure time (Format 00:00):");scanf("%s", pstNew->data.acTakeOffTime);printf("Input the Arrival time (Format 00:00):");scanf("%s", pstNew->data.acReverveTime);printf("Input the price of ticket:");scanf("%f", &pstNew->data.fPrice);printf("Input the discount of ticket(Format 0.0):");scanf("%s", pstNew->data.acDiscount);printf("Input the number of tickets:");scanf("%d", &pstNew->data.iNum);pstNew->next = NULL;pstTail -> next = pstNew;pstTail = pstNew;iSave = 1;//有新的航班信息,保存標志為1} } void Menu() {puts("***********************************************************");puts("****** Welcome to the airplane tickets booking system *****");puts("-----------------------------------------------------------");puts("****** Choose the following operations(0-9) *****");puts("-----------------------------------------------------------");puts("** 1.Insert fligths 2.Search fligths **");puts("** 3.Book fligths 4.Modify fligths **");puts("** 5.Show fligths 6.Recommed fligths **");puts("** 7.Refund fligths 8.NowTime fligths **");puts("** 9.Save Messages 0.Exist **");puts("-----------------------------------------------------------"); } void SaveMan(MANNode pstManNodeHead)//保存訂票人信息 {FILE* pfMan; ManNode* pstManNodeCur;int count = 0; //保存多少條信息int iflg = 1; //是否寫入信息pfMan = fopen("man.txt", "wb");if (pfMan == NULL){printf("the file can't be opened!");return;}pstManNodeCur = pstManNodeHead->next;while (pstManNodeCur != NULL){if (fwrite(pstManNodeCur, sizeof(ManNode), 1, pfMan) == 1){pstManNodeCur = pstManNodeCur->next;count++;}else{iflg = 0;break;}}fclose(pfMan); } void SavePlane(PLNode pstPlaneNodeHead)//保存機票信息 {FILE* pfPlane; //機票文件信息PlaneNode* pstPlaneNodeCur;int count = 0; //保存多少條信息int iflg = 1; //是否寫入信息pfPlane = fopen("plane.txt", "wb");if (pfPlane == NULL){printf("the file can't be opened!");return;}pstPlaneNodeCur = pstPlaneNodeHead->next;while (pstPlaneNodeCur != NULL){if (fwrite(pstPlaneNodeCur,sizeof(PlaneNode) ,1, pfPlane)==1){pstPlaneNodeCur = pstPlaneNodeCur->next;count++;}else{iflg = 0;break;}}if (iflg){printf("you have save %d flights", count);iSave = 0;}fclose(pfPlane); } void PrintfHead() {printf("|------------------------------------------------------------------------------|\n");printf("|***********************************************************************|******|\n");printf("|Flight|StartCity|DseCity|DepertureTime|ArrivalTime|***price***|Discount|number|\n");printf("|******|*********|*******|*************|***********|***********|********|******|\n");printf("|------------------------------------------------------------------------------|\n"); } void PrintData(PLNode pstPlaneNodeCur) {PlaneNode* pst = pstPlaneNodeCur;printf(" %3s%8s%8s%12s%12s%16f%7s%8d\n", pst->data.acFlight, pst->data.acOrigin, pst->data.acDest, pst->data.acTakeOffTime, pst->data.acReverveTime, pst->data.fPrice, pst->data.acDiscount, pst->data.iNum); } void Show(PLNode pstPlaneNodeHead)//顯示所有機票信息 {PlaneNode* pstPlaneNodeCur = pstPlaneNodeHead->next;PrintfHead();if (pstPlaneNodeHead->next == NULL){printf("no flight ticket!\n");}else{while (pstPlaneNodeCur != NULL){PrintData(pstPlaneNodeCur);pstPlaneNodeCur = pstPlaneNodeCur->next;}} } void Search(PLNode pstPlaneNodeHead)//查詢機票信息 {PlaneNode* pstPlaneNode;int Sel = 0;int count = 0;//計數器char acFlight[10], acDes[10],acstart[10];//航班號和目的地pstPlaneNode = pstPlaneNodeHead->next;if (pstPlaneNode == NULL){printf("is not have data");return;}//按航班號查詢//按目的地查詢//按起始地查詢printf("Choose one way according to:\n1.flight number 2.Dest 3.Start\n");scanf("%d", &Sel);if (Sel == 1){//按航班號查詢printf("input the right flight number:");scanf("%s", acFlight);PrintfHead();//機票信息頭部打印while (pstPlaneNode != NULL){if (strcmp(pstPlaneNode->data.acFlight, acFlight) == 0){PrintData(pstPlaneNode);break;//航班號唯一}else{pstPlaneNode = pstPlaneNode->next;}}//遍歷結束,沒有break,則沒有用戶記錄if (pstPlaneNode == NULL){printf("Sorry,no record!\n");return;}}else if (Sel == 2){//按目的地查詢printf("input the right Dest:");scanf("%s", acDes);PrintfHead();//機票信息頭部打印while (pstPlaneNode != NULL){if (strcmp(pstPlaneNode->data.acDest, acDes) == 0){PrintData(pstPlaneNode);count++;}pstPlaneNode = pstPlaneNode->next;}//遍歷結束,計數器為0,則沒有記錄if (count ==0){printf("Sorry,no record!\n");return;}}else if (Sel == 3){//按起始地查詢printf("input the right Start:");scanf("%s", acstart);PrintfHead();//機票信息頭部打印while (pstPlaneNode != NULL){if (strcmp(pstPlaneNode->data.acOrigin, acstart) == 0){PrintData(pstPlaneNode);count++;}pstPlaneNode = pstPlaneNode->next;}//遍歷結束,計數器為0,則沒有記錄if (count == 0){printf("Sorry,no record!\n");return;}}else{printf("Sorry,please input right number 1-3:\n");return;} }void Book(MANNode pstManNodeHead, PLNode pstPlaneNodeHead)//訂票 {//思路:輸入起始地和目的地,顯示是否有票若有,多條航班(存入數據到結構體中)//訂票:輸入訂票人信息//訂票:選擇航班號PlaneNode * pstPlaneNodeCur,*astPlane[10]; //保存數據臨時結構體數組ManNode* pstManNodeCur,*pstManNodeTemp=NULL;char acOrigin[10], acDest[10], acID[20], acName[20], acSex[10], acDescision[2], acFlight[10];int iNum = 0, Record = 0, k = 0, flg = 0;//接受訂票人信息頭指針pstManNodeCur=pstManNodeHead;while (pstManNodeCur->next != NULL){pstManNodeCur = pstManNodeCur->next;}//將訂票人結構體指向尾巴//輸入起始地和目的地printf("input the start city:");scanf("%s",acOrigin);printf("input the Dest city:");scanf("%s",acDest);//查找起始地和目的地,存入臨時結構體數組中pstPlaneNodeCur = pstPlaneNodeHead->next;while (pstPlaneNodeCur != NULL){if (strcmp(pstPlaneNodeCur->data.acOrigin,acOrigin) == 0&&strcmp(pstPlaneNodeCur->data.acDest,acDest) == 0){astPlane[Record++] = pstPlaneNodeCur;}pstPlaneNodeCur = pstPlaneNodeCur->next;}//打印數據printf("there are %d flights you can choose!\n",Record);PrintfHead();for (k = 0; k < Record; k++){PrintData(astPlane[k]);}if (Record == 0){printf("Sorry,no flights you can book\*/\n");}//訂票else{printf("do you want to book it?(y(Y))/n(N))\n");scanf("%s", acDescision);getchar();if (strcmp(acDescision, "y") == 0 || strcmp(acDescision, "Y") == 0){printf("input your information!\n");pstManNodeTemp = (ManNode*)malloc(sizeof(ManNode));printf("input your name:");scanf("%s", acName);strcpy(pstManNodeTemp->data.acName, acName);printf("input your id:");scanf("%s", acID);strcpy(pstManNodeTemp->data.acID, acID);printf("input your sex(M/W):");scanf("%s", acSex);strcpy(pstManNodeTemp->data.acSex, acSex);printf("input your want to book flight number:");scanf("%s", acFlight);strcpy(pstManNodeTemp->data.acBookFilight,acFlight);for (k = 0; k < Record; k++){if (strcmp(astPlane[k]->data.acFlight, acFlight) == 0){if (astPlane[k]->data.iNum < 1){printf("no ticket!");return;}printf("remain %d tickets!\n", astPlane[k]->data.iNum);flg = 1;break;}}if (flg == 0){printf("error\n");return;}printf("Input the book number:");scanf("%d", &iNum);//訂購幾張票astPlane[k]->data.iNum = astPlane[k]->data.iNum - iNum;pstManNodeTemp->data.iBookNum = iNum;pstManNodeCur->next = pstManNodeTemp;pstManNodeTemp->next = NULL;pstManNodeCur = pstManNodeTemp;//可以不要printf("success!\n");iSave = 1;}} } void Modify(PLNode pstPlaneNodeHead)//修改機票信息 {PlaneNode* pstPlaneNodeCur;char acFlight[10];pstPlaneNodeCur = pstPlaneNodeHead->next;if (pstPlaneNodeCur == NULL){printf("no flight to be modify!");return;}else{printf("Input the flight number you want to modify!:");scanf("%s", acFlight);while (pstPlaneNodeCur){if (strcmp(pstPlaneNodeCur->data.acFlight, acFlight) == 0){break;}else{pstPlaneNodeCur = pstPlaneNodeCur->next;}}if (pstPlaneNodeCur){printf("input the new start city:");scanf("%s", pstPlaneNodeCur->data.acOrigin);printf("input the new arrval city:");scanf("%s", pstPlaneNodeCur->data.acDest);printf("input the new dicount:");scanf("%s", pstPlaneNodeCur->data.acDiscount);printf("input the new acTakeOffTime:");scanf("%s", pstPlaneNodeCur->data.acTakeOffTime);printf("input the new acReverveTime:");scanf("%s", pstPlaneNodeCur->data.acReverveTime);printf("input the new fPrice:");scanf("%f", &pstPlaneNodeCur->data.fPrice);printf("input the new iNum:");scanf("%d", &pstPlaneNodeCur->data.iNum);printf("modify successful!\n");iSave = 1;}} } void Recommed(PLNode pstPlaneNodeHead)//推薦機票信息 {PlaneNode* pstPlaneNodeCur;char acDest[10], acTime[10],acOrigin[10];int iNum=0;pstPlaneNodeCur = pstPlaneNodeHead->next;printf("input your take city:");scanf("%s", acOrigin);printf("input your destination city:");scanf("%s", acDest);printf("input the earlist time you can take:");scanf("%s", acTime);PrintfHead();while (pstPlaneNodeCur != NULL){if (strcmp(pstPlaneNodeCur->data.acOrigin, acOrigin) == 0 && strcmp(pstPlaneNodeCur->data.acDest, acDest) == 0&& strcmp(acTime, pstPlaneNodeCur->data.acTakeOffTime) < 0){PrintData(pstPlaneNodeCur);iNum++;}pstPlaneNodeCur = pstPlaneNodeCur->next;}printf("there are %d flights you can choose!\n", iNum);if (iNum != 0){printf("please choose 3rd operation to book it!\n");} } //找到id號相同的訂票人記錄,返回訂票人節點 MANNode FindMan(MANNode pstManNodeHead, char acID[20]) {ManNode* pstManNodeCur = pstManNodeHead->next;while (pstManNodeCur){if (strcmp(pstManNodeCur->data.acID, acID) == 0){return pstManNodeCur;}pstManNodeCur = pstManNodeCur->next;}return NULL; } //找到訂票人信息中的航班號記錄,找到相應機票信息節點 PLNode FindPlane(PLNode pstPlaneNodeHead, char* acBookFlight) {PlaneNode* pstPlaneNodeCur = pstPlaneNodeHead->next;while (pstPlaneNodeCur){if (strcmp(pstPlaneNodeCur->data.acFlight, acBookFlight) == 0){return pstPlaneNodeCur;}pstPlaneNodeCur = pstPlaneNodeCur->next;}return NULL;} void Refund(MANNode pstManNodeHead, PLNode pstPlaneNodeHead)//退票 {ManNode* pstManNodeCur, * pstManNodeFind = NULL;PlaneNode* pstPlaneNodeFind = NULL;char acID[20],acdescison[2];int iNum;//剩余票數int iBooknum;//定了幾個票printf("input your id number :");scanf("%s", acID);//找到訂票人的結構體pstManNodeFind = FindMan(pstManNodeHead, acID);if (pstManNodeFind == NULL){printf("can't find!\n");}else//退票{printf("this is your tickets:\n");printf("id number is :%s\n", pstManNodeFind->data.acID);printf("name is :%s\n", pstManNodeFind->data.acName);printf("sex is :%s\n", pstManNodeFind->data.acSex);printf("book flights :%s\n", pstManNodeFind->data.acBookFilight);printf("book number :%d\n", pstManNodeFind->data.iBookNum);printf("if you want to cancel it (y/n)?: ");scanf("%s", acdescison);if (strcmp(acdescison, "y") == 0 || strcmp(acdescison, "Y") == 0){//找到前驅pstManNodeCur = pstManNodeHead;while (pstManNodeCur->next != pstManNodeFind){pstManNodeCur = pstManNodeCur->next;}//找到該訂票人對應航班記錄pstPlaneNodeFind =FindPlane(pstPlaneNodeHead, pstManNodeFind->data.acBookFilight);//退票if (pstPlaneNodeFind != NULL){iNum = pstPlaneNodeFind->data.iNum;//機票剩余票數iBooknum = pstManNodeFind->data.iBookNum;//訂購人定票數pstPlaneNodeFind->data.iNum = iNum + iBooknum;}//刪除訂票人節點pstManNodeCur->next = pstManNodeFind->next;free(pstManNodeFind);printf("successful refund!\n");iSave = 1;}} } void NowTime()//顯示當前時間 {time_t It;It = time(NULL);printf("現在的時間是:%s ", ctime(&It)); } int main() {PlaneNode pstPlaneNodeHead;//機票信息頭結點pstPlaneNodeHead.next = NULL;ManNode pstManNodeHead; //訂票人頭結點pstManNodeHead.next = NULL;int res;res = Init(&pstPlaneNodeHead, &pstManNodeHead);//將文件的數據加載到內存中if (res < 0){return 0;}int iSel;//用于接收用戶對于功能的選擇char c1; //是否保存while(1){system("cls");Menu();printf("Input 0-9 operations:");scanf("%d", &iSel);getchar();system("cls");switch(iSel){case 1:Insert(&pstPlaneNodeHead);//添加機票信息break;case 2:Search(&pstPlaneNodeHead);//查詢機票信息break;case 3:Book(&pstManNodeHead, &pstPlaneNodeHead);//預定機票系統break;case 4:Modify(&pstPlaneNodeHead);//修改機票信息break;case 5:Show(&pstPlaneNodeHead);//顯示所有機票信息break;case 6:Recommed(&pstPlaneNodeHead);//推薦機票信息break;case 7:Refund(&pstManNodeHead, &pstPlaneNodeHead);//退票操作break;case 8:NowTime();//顯示當前時間break;case 9:SaveMan(&pstManNodeHead);//保存訂票人信息SavePlane(&pstPlaneNodeHead);//保存機票信息case 0:if (iSave == 1){printf("Do you want to save message (y/n)");scanf("%c", &c1);getchar();if (c1 == 'y' || c1 == 'Y'){SaveMan(&pstManNodeHead);//保存訂票人的信息SavePlane(&pstPlaneNodeHead);//保存機票信息}}//Destroy(pstManNodeHead,pstPlaneNodeHead);return 0;}printf("please press any key continue...");_getch();}//Destroy(pstManNodeHead,pstPlaneNodeHead);return 0; }

?動圖操作演示 (視頻過長壓縮有限)

?

如有錯誤還望指正!

總結

以上是生活随笔為你收集整理的课程设计(飞机订票系统) 超全的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。