飞机订票系统(c语言)

一、项目背景

​ 为了免去在窗口排队买票的麻烦,飞机订票系统应运而生。用户通过该系统可以快速,详细地了解需要的信息,并提供了一个很好的购票渠道。

二、设计目的

  • 如何合理设计不同数据结构来存储航班信息、旅客信息、订票信息等不同数据
  • 如何合理设计不同的链表节点来封装不同的实体信息;
  • 如何合理设计多个链表结构来管理不同实体的若干记录;
  • 进一步强化学习链表的创建、插入、查找、修改和删除等基本操作;
  • 进一步强化学习内存中链表数据和外部文件之间的存取操作;
  • 如何利用time.h中的函数获取系统日期时间

三、项目功能需求

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、时间模块

功能设计

  • 为了更好地方便用户订票时的实际需求,本系统提供了查询当地时间的功能。

七、代码

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <conio.h>
#include <time.h>
#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("现在的时间是:%s\n", ctime(&lt));
}

/*添加机票函数*/
void Insert(struct PlaneNode* pstPlaneNodeHead)
{
	struct PlaneNode *pstHead,*pstTail, *pstCur, *pstNew;
	char acFlight[10];
	pstHead = pstTail = pstPlaneNodeHead;
	while (pstTail->pstNext != NULL)
	{
		pstTail = pstTail->pstNext;  /*让ptail指向最后一个节点*/
	}
	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;/*有新的航班信息,保存标志置为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;
		}
		/*遍历一遍,均没有中途break,则提示用户没有记录*/
		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)/*如果记录数仍为0,则提示用户没有记录*/
			printf("Sorry, no record!\n");
	}
	else
	{
		printf("Sorry, please input right number:1-2\n");
		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];
	/*iNum表示预定票数,iRecord记录符合要求的航班数*/
	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)/*若记录为0,表示没有符合条件的航班*/
		printf("sorry,no flight you can book!\n");
	else
	{
		printf("do you want to book it<y(Y)/n(N)>?\n");/*提示用户是否预定*/
		scanf("%s", acDecision);
		getchar(); /*提取多余的回车符,否则下面输入姓名的gets函数将获得一个回车符*/
		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);/*由于姓和名中间会有空格,只能用gets函数,不能用scanf结合%s*/
			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<iRecord; k++)
			if (strcmp(astPlaneNode[k]->stData.acFlight, acFlight) == 0)
			{
				if (astPlaneNode[k]->stData.iNum < 1)/*判断是否有剩余的票*/
				{
					printf("no ticket!");
					return;
				}
				printf("remain %d tickets\n", 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("\t\tthis is your tickets:\n");
		printf("id number:%s\n", pstManNodeFind->stData.acID);
		printf("name:%s\n", pstManNodeFind->stData.acName);
		printf("sex:%s\n", pstManNodeFind->stData.acSex);
		printf("book flight:%s\n",pstManNodeFind->stData.acBookFlight);
		printf("book number:%d\n", pstManNodeFind->stData.iBookNum);
		
		printf("do you want to cancel it?<y/n>");
		scanf("%s", acDecision);
		if (strcmp(acDecision, "y") == 0 || strcmp(acDecision, "Y") == 0)
		{
			/*将pstManNodeCur定位到指向pstManNodeFind前面那个节点*/
			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");
			/*航班信息有调整,保存标志置为1,退出系统时提示用户是否保存*/
			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?<y/n>");
				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();
	}
}

  • 87
    点赞
  • 687
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 13
    评论
1、问题描述: 航空客运订票的业务包括查询航班、客票预订和办理退票等。试设计一个航空客运订票系统,已使上述业务可以借助计算机完成。 2、功能要求: (1)每条航线所涉及的信息有终点站名、航班号、飞机号、星期几飞行、飞行周日(星期几)、乘员定额、余票量、已订票的客户名单(包括姓名、订票量、舱位等级),以及等候补替补的客户名单(包括姓名、所需票量)。 (2)作为示意系统:全部数据可以只放在内存中。 (3)系统能实现的操作和功能如下: 录入:可以录入航班情况(数据可以存储在一个数据文件中,数据结构、具体数据自定)。 查询航线:根据旅客提出的终点站名输入下列信息:航班号、飞机号、星期几起飞、最近航班的日期和余票量。 承办订票业务:根据客户提出的要求(航班号、订票数额)查询该航班票额情况,若尚有余票,则为客户办理订票手续,输出座位号。若已满员或者余票数少于订票额,则需重新寻味客户要求,若需要,可登记排队候补。 承办退票业务:根据客户提供的情况(日期、航班)为客户办理退票手续,然后查询该航班是否有人排队等候补。首先询问排在第一的客户,若所有退票额能满足他的要求,则为他办理订票手续否则依次询问其他排队候补的客户。 修改航班信息:当航班信息改变可以修改航班数据文件。
飞机订票系统是一个比较大的系统,需要设计多个模块,包括用户登录、航班查询、订票系统、订单管理、支付系统等等。 以下是一个简单的飞机订票系统C语言代码示例,供参考: ```c #include <stdio.h> #include <stdlib.h> #include <string.h> //定义航班结构体 typedef struct { char number[20]; //航班号 char start[20]; //起点 char dest[20]; //终点 char time[20]; //起飞时间 int price; //价格 int remain; //余票数 } Flight; //定义用户结构体 typedef struct { char name[20]; //姓名 char id[20]; //身份证号 char phone[20]; //手机号 Flight flight; //所选航班 } User; //定义全局变量 Flight flights[10]; //航班列表 int count = 0; //航班数量 //初始化航班列表 void initFlights() { Flight f1 = {"CA123", "北京", "上海", "08:00", 1000, 50}; Flight f2 = {"MU456", "上海", "广州", "10:00", 800, 80}; Flight f3 = {"CZ789", "北京", "广州", "12:00", 1200, 30}; flights[0] = f1; flights[1] = f2; flights[2] = f3; count = 3; } //显示航班列表 void showFlights() { printf("航班号\t起点\t终点\t起飞时间\t价格\t余票数\n"); for(int i = 0; i < count; i++) { Flight f = flights[i]; printf("%s\t%s\t%s\t%s\t%d\t%d\n", f.number, f.start, f.dest, f.time, f.price, f.remain); } } //根据航班号查询航班 Flight findFlight(char number[]) { for(int i = 0; i < count; i++) { if(strcmp(flights[i].number, number) == 0) { return flights[i]; } } Flight f = {"", "", "", "", 0, 0}; return f; } //订票 void bookTicket() { char number[20]; printf("请输入航班号:"); scanf("%s", number); Flight f = findFlight(number); if(strcmp(f.number, "") == 0) { printf("没有找到该航班,请重新输入!\n"); return; } printf("请选择座位数(余票:%d):", f.remain); int num; scanf("%d", &num); if(num > f.remain) { printf("余票不足,请重新选择!\n"); return; } User u; printf("请输入姓名:"); scanf("%s", u.name); printf("请输入身份证号:"); scanf("%s", u.id); printf("请输入手机号:"); scanf("%s", u.phone); u.flight = f; flights[count-1].remain -= num; printf("订票成功!\n"); printf("航班号:%s,起点:%s,终点:%s,起飞时间:%s,价格:%d,座位数:%d\n", f.number, f.start, f.dest, f.time, f.price, num); printf("姓名:%s,身份证号:%s,手机号:%s\n", u.name, u.id, u.phone); } //订单查询 void showOrders() { char id[20]; printf("请输入身份证号:"); scanf("%s", id); printf("航班号\t起点\t终点\t起飞时间\t价格\t订票数\t姓名\t身份证号\t手机号\n"); for(int i = 0; i < count; i++) { Flight f = flights[i]; if(strcmp(f.number, "") != 0) { User u = f.user; if(strcmp(u.id, id) == 0) { printf("%s\t%s\t%s\t%s\t%d\t%d\t%s\t%s\t%s\n", f.number, f.start, f.dest, f.time, f.price, u.num, u.name, u.id, u.phone); } } } } int main() { initFlights(); while(1) { printf("\n1.航班查询 2.订票 3.订单查询 4.退出\n"); int choice; scanf("%d", &choice); switch(choice) { case 1: showFlights(); break; case 2: bookTicket(); break; case 3: showOrders(); break; case 4: exit(0); default: printf("请选择正确的菜单项!\n"); } } return 0; } ``` 注意:这只是一个简单的示例代码,并没有实现完整的飞机订票系统,还需要根据实际需求进行完善和修改。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 13
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

拾亿-唯一

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值