- 一、项目背景
- 二、设计目的
- 三、项目功能需求
- 1、添加机票信息
- 2、查询可预订的机票信息
- 3、预定机票并输入个人信息
- 4、修改机票信息
- 5、退票
- 6、根据目的地和最早出发时间,系统可以推荐合适的机票信息
- 7、显示当前时间
- 四、系统的功能结构图
- 五、功能模块介绍
- 1、添加模块
- 2、查找模块
- 3、订票模块
- 4、修改模块
- 5、退票模块
- 6、显示模块
- 7、推荐模块
- 8、保存模块
- 9、时间模块
- 六、详细设计
- 1、主函数
- 2、添加模块
- 3、查找模块
- 4、订票模块
- 5、修改模块
- 6、退票模块
- 7、显示模块
- 8、推荐模块
- 9、保存模块
- 10、时间模块
- 七、代码
为了免去在窗口排队买票的麻烦,飞机订票系统应运而生。用户通过该系统可以快速,详细地了解需要的信息,并提供了一个很好的购票渠道。
二、设计目的- 如何合理设计不同数据结构来存储航班信息、旅客信息、订票信息等不同数据
- 如何合理设计不同的链表节点来封装不同的实体信息;
- 如何合理设计多个链表结构来管理不同实体的若干记录;
- 进一步强化学习链表的创建、插入、查找、修改和删除等基本操作;
- 进一步强化学习内存中链表数据和外部文件之间的存取操作;
- 如何利用time.h中的函数获取系统日期时间
- 能够添加机票的航班号、起飞降落时间、目的地、出发地、票价、可定的剩余票数以及折扣信息等。
- 能够根据用户的具体需求即航班号或目的地,查询可定的机票并输出相应的机票信息,支持标准格式输出多条机票信息。
- 查询机票后,根据用户的选择,决定是否订票,并输入信息。
- 能修改已经存在的机票信息。
- 可以连续添加多条航班信息,包括航班号、出发城市、到达城市、出发时间、到达时间、票价、折扣信息、票数
- 用户在订票之前需要先查询满足自己出行需要的机票信息,本功能模块支持按照“航班号”查询和按照“目的地”查询两种方式
- 输入目的地信息,可以输出所有满足该目的地的航班信息,并提示用户是否订票
- 输入需要修改的航班号,可以修改航班信息
- 能支持用户退票操作
- 显示模块可以展示所有航班信息,供旅客查看选择
- 推荐模块的功能是根据旅客输入的目的地信息和最早出发时间,向旅客推荐满足要求的航班信息,帮助旅客快速搜索符合时间要求的航班
- 能将航班信息和旅客订票信息保存到磁盘文件中,再次启动系统时,则可以自动读取文件中的航班信息和旅客订票信息
- 支持实时查询当前时间功能
功能设计
- 主函数用于实现主菜单的显示,并响应用户对菜单项的选择。
- 本系统的主函数主要两大功能:保存信息和菜单选择。
- 某个功能执行完之后,还能按任意键自动回到主菜单,便于用户进行其他操作。
功能设计
- 用于对飞机班次,始发地,目的地,起飞时间,降落时间,票价,折扣以及所剩票数等信息的输入与保存。
添加模块流程图
3、查找模块功能设计
- 用于根据输入的飞机班次或到达城市来进行查找,了解航班的信息。
- 提供了两种查询方式:一是根据飞机班次查询,二是根据到达城市查询。
功能设计
- 用于根据用户输入的城市进行查询,在屏幕上显示满足条件的飞机班次信息。
- 从中选择自己想要预定的机票,并根据提示输入个人信息。
功能设计
- 用于对已添加的飞机班次,时间,地点,票价等信息的修改。
功能设计
- 用于用户对已经预定的飞机票进行退票。
功能设计
- 用于对输入的航班信息和经过修改的航班信息进行整理输出,方便用户查看。
功能设计
- 用于对用户提供的信息,系统检索后提供合适的机票,以便用户选择适合自己时间的班次后进行预订。
功能设计
- 应用文件处理来将航班信息和订票人信息保存到指定的磁盘文件中。
功能设计
- 为了更好地方便用户订票时的实际需求,本系统提供了查询当地时间的功能。
#include#include #include #include #include #define HEAD1 " *************************Airplane Ticket Booking*****************************n" #define HEAD2 " | Flight |Start City| Dest City|DepartureTime|ArrivalTime|price | number |n" #define HEAD3 " |----------|----------|----------|-------------|-----------|-------|--------|n" #define FORMAT " |%-10s|%-10s|%-10s|%-12s |%-10s | %-.2f| %4d |n" #define DATA pst->stData.acFlight,pst->stData.acOrigin,pst->stData.acDest,pst->stData.acTakeOffTime,pst->stData.acReceiveTime,pst->stData.fPrice,pst->stData.iNum int iSave = 0; struct AirPlane { char acFlight[10]; char acOrigin[10]; char acDest[10]; char acTakeOffTime[10]; char acReceiveTime[10]; float fPrice; char acDiscount[4]; int iNum; }; struct Man { char acName[20]; char acID[20]; char acSex[2]; int iBookNum; char acBookFlight[10]; }; struct PlaneNode { struct AirPlane stData; struct PlaneNode *pstNext; }; struct ManNode { struct Man stData; struct ManNode *pstNext; }; void PrintHead() { printf(HEAD1); printf(HEAD2); printf(HEAD3); } void PrintData(struct PlaneNode*stLp) { struct PlaneNode *pst = stLp; printf(FORMAT, DATA); } void Menu() { puts("**************************************************"); puts("* Welcome to the airplane tickets booking system *"); puts("*------------------------------------------------*"); puts("* choose the following operations(0-9); *"); puts("*------------------------------------------------*"); puts("* 1.Insert flights 2.Search flights *"); puts("* 3.Book tickets 4.Modify flight data *"); puts("* 5.Show flights 6.Recommend flights *"); puts("* 7.Refund tickets 8.Show current time *"); puts("* 9.Save to files 0.quit *"); puts("**************************************************"); } void NowTime() { time_t lt; lt = time(NULL); printf("现在的时间是:%sn", ctime(<)); } void Insert(struct PlaneNode* pstPlaneNodeHead) { struct PlaneNode *pstHead,*pstTail, *pstCur, *pstNew; char acFlight[10]; pstHead = pstTail = pstPlaneNodeHead; while (pstTail->pstNext != NULL) { pstTail = pstTail->pstNext; } while (1) { printf("Input the new flight number(-1 to end):"); scanf("%s", acFlight); if (strcmp(acFlight, "-1") == 0) break; pstCur = pstPlaneNodeHead->pstNext; while (pstCur != NULL) { if (strcmp(acFlight, pstCur->stData.acFlight) == 0) { printf("this flight %s exists!n", acFlight); return; } pstCur = pstCur->pstNext; } pstNew = (struct PlaneNode*)malloc(sizeof(struct PlaneNode)); strcpy(pstNew->stData.acFlight, acFlight); printf("Input the Start City:n"); scanf("%s", pstNew->stData.acOrigin); printf("Input the Dest City:n"); scanf("%s", pstNew->stData.acDest); printf("Input the Departure Time (Format 00:00):n"); scanf("%s", pstNew->stData.acTakeOffTime); printf("Input the Arrival Time (Format 00:00):n"); scanf("%s", pstNew->stData.acReceiveTime); printf("Input the price of ticket:n"); scanf("%f", &pstNew->stData.fPrice); printf("Input the discount (Format 0.0):n"); scanf("%s", pstNew->stData.acDiscount); printf("Input the number of the tickets:n"); scanf("%d", &pstNew->stData.iNum); pstNew->pstNext = NULL; pstTail->pstNext = pstNew; pstTail = pstNew; iSave = 1; } } void Search(struct PlaneNode* pstPlaneNodeHead) { struct PlaneNode *pstPlaneNode; int iSel = 0, iCount = 0; char acFlight[10], acDest[10]; pstPlaneNode = pstPlaneNodeHead->pstNext; if (pstPlaneNode == NULL) { printf("No flight record!n"); return; } printf("Choose one way according to:n1.flight number;n2.Dest:n"); scanf("%d", &iSel); if (iSel == 1) { printf("Input the flight number:"); scanf("%s", acFlight); PrintHead(); while (pstPlaneNode != NULL) { if (strcmp(pstPlaneNode->stData.acFlight, acFlight) == 0) { PrintData(pstPlaneNode); break; } else pstPlaneNode = pstPlaneNode->pstNext; } if (pstPlaneNode == NULL) printf("Sorry, no record!n"); } else if (iSel == 2) { printf("Input the Dest City:"); scanf("%s", acDest); PrintHead(); while (pstPlaneNode != NULL) { if (strcmp(pstPlaneNode->stData.acDest, acDest) == 0) { PrintData(pstPlaneNode); iCount++; } pstPlaneNode = pstPlaneNode->pstNext; } if (iCount == 0) printf("Sorry, no record!n"); } else { printf("Sorry, please input right number:1-2n"); return; } } void Book(struct ManNode* pstManNodeHead, struct PlaneNode* pstPlaneNodeHead) { struct PlaneNode *pstPlaneNodeCur, *astPlaneNode[10]; struct ManNode *pstManNodeCur, *pstManNodeTemp = 0; char acDest[10], acID[20], acName[20], acSex[2], acDecision[2], acFlight[10]; int iNum = 0, iRecord = 0, k = 0, iFlag = 0; pstManNodeCur = pstManNodeHead; while (pstManNodeCur->pstNext != NULL) pstManNodeCur = pstManNodeCur->pstNext; printf("Input the Dest City:n"); scanf("%s", acDest); pstPlaneNodeCur = pstPlaneNodeHead->pstNext; while (pstPlaneNodeCur != NULL) { if (strcmp(pstPlaneNodeCur->stData.acDest, acDest) == 0) { astPlaneNode[iRecord++] = pstPlaneNodeCur; } pstPlaneNodeCur = pstPlaneNodeCur->pstNext; } printf("nthere are %d flight you can choose!n", iRecord); PrintHead(); for (k = 0; k < iRecord; k++) PrintData(astPlaneNode[k]); if (iRecord == 0) printf("sorry,no flight you can book!n"); else { printf("do you want to book it ?n"); scanf("%s", acDecision); getchar(); if (strcmp(acDecision, "y") == 0 || strcmp(acDecision, "Y") == 0) { printf("Input your information!n"); pstManNodeTemp = (struct ManNode*)malloc(sizeof(struct ManNode)); printf("Input your name:"); gets(acName); strcpy(pstManNodeTemp->stData.acName, acName); printf("Input your id:"); scanf("%s", acID); strcpy(pstManNodeTemp->stData.acID, acID); printf("Input your sex (M/F):"); scanf("%s", acSex); strcpy(pstManNodeTemp->stData.acSex, acSex); printf("Input the flight number:"); scanf("%s", acFlight); strcpy(pstManNodeTemp->stData.acBookFlight, acFlight); for (k = 0; k stData.acFlight, acFlight) == 0) { if (astPlaneNode[k]->stData.iNum < 1) { printf("no ticket!"); return; } printf("remain %d ticketsn", astPlaneNode[k]->stData.iNum); iFlag = 1; break; } if (iFlag == 0) { printf("error"); return; } printf("Input the book number:"); scanf("%d", &iNum); astPlaneNode[k]->stData.iNum = astPlaneNode[k]->stData.iNum - iNum; pstManNodeTemp->stData.iBookNum = iNum; pstManNodeCur->pstNext = pstManNodeTemp; pstManNodeTemp->pstNext = NULL; pstManNodeCur = pstManNodeTemp; printf("success!n"); iSave = 1; } } } struct ManNode *FindMan(struct ManNode* pstManNodeHead, char acID[20]) { struct ManNode *pstManNodeCur; pstManNodeCur = pstManNodeHead->pstNext; while (pstManNodeCur) { if (strcmp(pstManNodeCur->stData.acID, acID) == 0) { return pstManNodeCur; } pstManNodeCur = pstManNodeCur->pstNext; } return NULL; } struct PlaneNode *FindPlane(struct PlaneNode* pstPlaneNodeHead, char acFlight[10]) { struct PlaneNode *pstPlaneNodeCur; pstPlaneNodeCur = pstPlaneNodeHead->pstNext; while (pstPlaneNodeCur) { if (strcmp(pstPlaneNodeCur->stData.acFlight, acFlight) == 0) { //iMark = 1; return pstPlaneNodeCur; } pstPlaneNodeCur = pstPlaneNodeCur->pstNext; } return NULL; } void Refund(struct ManNode* pstManNodeHead, struct PlaneNode* pstPlaneNodeHead) { struct ManNode *pstManNodeCur, *pstManNodeFind = 0; struct PlaneNode *pstPlaneNodeFind = 0; char acID[20], acDecision[2]; int iNum, iBookNum; printf("nInput your ID:"); scanf("%s", acID); pstManNodeFind = FindMan(pstManNodeHead, acID); if (pstManNodeFind == NULL) printf("can't find!n"); else { printf("ttthis is your tickets:n"); printf("id number:%sn", pstManNodeFind->stData.acID); printf("name:%sn", pstManNodeFind->stData.acName); printf("sex:%sn", pstManNodeFind->stData.acSex); printf("book flight:%sn",pstManNodeFind->stData.acBookFlight); printf("book number:%dn", pstManNodeFind->stData.iBookNum); printf("do you want to cancel it? "); scanf("%s", acDecision); if (strcmp(acDecision, "y") == 0 || strcmp(acDecision, "Y") == 0) { pstManNodeCur = pstManNodeHead; while (pstManNodeCur->pstNext != pstManNodeFind) pstManNodeCur = pstManNodeCur->pstNext; pstPlaneNodeFind = FindPlane(pstPlaneNodeHead, pstManNodeFind->stData.acBookFlight); if (pstPlaneNodeFind != NULL) { iNum = pstPlaneNodeFind->stData.iNum; iBookNum = pstManNodeFind->stData.iBookNum; pstPlaneNodeFind->stData.iNum = iNum + iBookNum; } pstManNodeCur->pstNext = pstManNodeFind->pstNext; free(pstManNodeFind); printf("successful!n"); iSave = 1; } } } void Modify(struct PlaneNode* pstPlaneNodeHead) { struct PlaneNode *pstPlaneNodeCur; char acFlight[10]; pstPlaneNodeCur = pstPlaneNodeHead->pstNext; if (pstPlaneNodeCur == NULL) { printf("no flight to modify!n"); return; } else { printf("Input the flight number you want to modify:"); scanf("%s", acFlight); while (pstPlaneNodeCur != NULL) { if (strcmp(pstPlaneNodeCur->stData.acFlight, acFlight) == 0) break; else pstPlaneNodeCur = pstPlaneNodeCur->pstNext; } if (pstPlaneNodeCur) { printf("Input new Start City:n"); scanf("%s", pstPlaneNodeCur->stData.acOrigin); printf("Input new Dest City:n"); scanf("%s", pstPlaneNodeCur->stData.acDest); printf("Input new Departure Time:n"); scanf("%s", pstPlaneNodeCur->stData.acTakeOffTime); printf("Input new Arrival Time:n"); scanf("%s", pstPlaneNodeCur->stData.acReceiveTime); printf("Input new price of ticket:n"); scanf("%f", &pstPlaneNodeCur->stData.fPrice); printf("Input new discount:n"); scanf("%s", pstPlaneNodeCur->stData.acDiscount); printf("Input new number of the tickets:n"); scanf("%d", &pstPlaneNodeCur->stData.iNum); printf("successful!n"); iSave = 1; return; } else printf("tcan't find your ticket!n"); } } void Show(struct PlaneNode* pstPlaneNodeHead) { struct PlaneNode *pstPlaneNodeCur; pstPlaneNodeCur = pstPlaneNodeHead->pstNext; PrintHead(); if (pstPlaneNodeHead->pstNext == NULL) { printf("no flight ticket!n"); } else { while (pstPlaneNodeCur != NULL) { PrintData(pstPlaneNodeCur); pstPlaneNodeCur = pstPlaneNodeCur->pstNext; } } } void Recommend(struct PlaneNode* pstPlaneNodeHead) { struct PlaneNode *pstPlaneNodeCur; char acDest[10],acTime[10]; int iNum = 0; pstPlaneNodeCur = pstPlaneNodeHead->pstNext; printf("Input your destination:"); scanf("%s", acDest); printf("Input the earliest time you can take:"); scanf("%s",acTime); PrintHead(); while (pstPlaneNodeCur != NULL) { if (strcmp(pstPlaneNodeCur->stData.acDest, acDest) == 0) { if (strcmp(acTime, pstPlaneNodeCur->stData.acTakeOffTime) < 0) { PrintData(pstPlaneNodeCur); iNum++; } } pstPlaneNodeCur = pstPlaneNodeCur->pstNext; } printf("there are %d flight you can take!n", iNum); if (iNum != 0) { printf("please choose 3rd operation to book it!n"); } } void SavePlane(struct PlaneNode* pstPlaneNodeHead) { FILE *pfPlane; struct PlaneNode *pstPlaneNodeCur; int iCount = 0, iFlag = 1; pfPlane = fopen("plane.txt", "wb"); if (pfPlane == NULL) { printf("the file can't be opened!"); return; } pstPlaneNodeCur = pstPlaneNodeHead->pstNext; while (pstPlaneNodeCur != NULL) { if (fwrite(pstPlaneNodeCur, sizeof(struct PlaneNode), 1, pfPlane) == 1) { pstPlaneNodeCur = pstPlaneNodeCur->pstNext; iCount++; } else { iFlag = 0; break; } } if (iFlag) { printf("you have save %d flights!n", iCount); iSave = 0; } fclose(pfPlane); } void SaveMan(struct ManNode* pstManNodeHead) { FILE *pfMan; struct ManNode *pstManNodeCur; int iCount = 0, iFlag = 1; pfMan = fopen("man.txt", "wb"); if (pfMan == NULL) { printf("the file can't bo opened!"); return; } pstManNodeCur = pstManNodeHead->pstNext; while (pstManNodeCur != NULL) { if (fwrite(pstManNodeCur, sizeof(struct ManNode), 1, pfMan) == 1) { pstManNodeCur = pstManNodeCur->pstNext; iCount++; } else { iFlag = 0; break; } } } int main() { FILE *pfPlane, *pfMan; struct PlaneNode *pstPlaneNodeTemp, *pstPlaneNodeHead, *pstPlaneNodeCur; struct ManNode *pstManNodeTemp, *pstManNodeHead, *pstManNodeCur; int iSel = 0; char c1; pstPlaneNodeHead = (struct PlaneNode*)malloc(sizeof(struct PlaneNode)); pstPlaneNodeHead->pstNext = NULL; pstPlaneNodeCur = pstPlaneNodeHead; pstManNodeHead = (struct ManNode*)malloc(sizeof(struct ManNode)); pstManNodeHead->pstNext = NULL; pstManNodeCur = pstManNodeHead; pfPlane = fopen("plane.txt", "ab+"); if (pfPlane == NULL) { printf("can't open plane.txt!"); return 0; } while (!feof(pfPlane)) { pstPlaneNodeTemp = (struct PlaneNode*)malloc(sizeof(struct PlaneNode)); if (fread(pstPlaneNodeTemp, sizeof(struct PlaneNode), 1, pfPlane) == 1) { pstPlaneNodeTemp->pstNext = NULL; pstPlaneNodeCur->pstNext = pstPlaneNodeTemp; pstPlaneNodeCur = pstPlaneNodeTemp; } } free(pstPlaneNodeTemp); fclose(pfPlane); pfMan = fopen("man.txt", "rb+"); if (pfMan == NULL) { printf("can't open man.txt!"); return 0; } while (!feof(pfMan)) { pstManNodeTemp = (struct ManNode*)malloc(sizeof(struct ManNode)); if (fread(pstPlaneNodeHead, sizeof(struct ManNode), 1, pfMan) == 1) { pstManNodeTemp->pstNext = NULL; pstManNodeCur->pstNext = pstManNodeTemp; pstManNodeCur = pstManNodeTemp; } } free(pstManNodeTemp); fclose(pfMan); while (1) { system("cls"); Menu(); printf("Input 0-9 operations:"); scanf("%d", &iSel); getchar(); system("cls"); if (iSel == 0) { if (iSave == 1) { printf("do you want to save? "); scanf("%c", &c1); if (c1 == 'y' || c1 == 'Y') { SaveMan(pstManNodeHead); SavePlane(pstPlaneNodeHead); } } break; } 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:Recommend(pstPlaneNodeHead); break; case 7:Refund(pstManNodeHead, pstPlaneNodeHead); break; case 8:NowTime(); break; case 9:SaveMan(pstManNodeHead); SavePlane(pstPlaneNodeHead); break; case 0:return 0; } printf("nplease press any key to continue.......n"); getch(); } }



