航空客运系统代码-课程设计(C语言)

航空客运系统代码-课程设计(C语言)

1.需求分析:

设计一个航空客运系统,该系统能完成的业务活动包括:查询航线、机票预顶和办理退票等。
运行环境:DEV C++;语言:C语言。
(1)、完成的基本要求:
用户层面:查询航线、订购机票、查看所有航班信息。
管理员层面:添加航班、删除航班、查看航班客户订单、查看所有航班信息及退票。
(2)、选做内容:当订票要求不满足时,系统向用户推荐同一目的地的其他航线。
(3)、增加的功能:
1).用户查询根据航班号和姓名查询订单情况。
2).订票时,可输入航班号或者目的地进行查询。
3).根据用户的不同需求提供不同的舱位等级,实行不同的票价。
4).管理员可以查询指定航班的候补乘客人数和名单。
5).管理员进行退票处理时,增加了与用户的交互,符合条件的候补用户可重新选择自己的票数和舱位等级。
6).用随机生成整数的函数,模拟验证码和订单号(经过简单的放大处理)

2.主要流程

航空客运系统代码-课程设计(C语言)_第1张图片

3.代码实现

数据结构

//已订票客户的名单,带头结点双向链表实现 
typedef struct clientNodehaha
{
	char name[MAXSIZE];//姓名
	char ID_num[MAXSIZE];//证件号
	char flight_num[10];//航班号
	char time[MAXSIZE];//起飞时间
	int order_num;//订单号
	int amout;//订票数量
	int rank;//舱位等级 
	struct clientNodehaha *behind;
	struct clientNodehaha *head;
}clientList,*clientListL;
clientList *CLient;


//等待候补的客户名单,带头结点单链表 
typedef struct waitNode{
	char name[MAXSIZE];//姓名
	char ID_num[MAXSIZE];//证件号
	int amout;//订票数量

	//int rank;//舱位等级 
	struct waitNode *next;
}waitNode,*waitPtr;
waitNode *Q; 


//航班总信息链表,带头结点的单链表实现 
typedef struct Flight{
	char destination[MAXSIZE];//终点站 
	char flightId[MAXSIZE];//航班名 ,唯一 
	char planeId[MAXSIZE];//飞机号 
	char time[MAXSIZE];//起飞时间 
	float money;
	int num;//乘员余额 
	int tickets;//余票量
	clientListL CLientc;//已订票客户名单 
	waitPtr wqueue;//等候替补的客户名单 
	struct Flight *next;
}Flight,*flightList;
Flight *flight;

对航班的操作

//初始化航班列表 
Status inItFlight(flightList &F){
	clientListL init_passengerList(clientListL &CLient);
	F = (Flight *)malloc(sizeof(Flight));
	if(NULL==F) return ERROR;
	strcpy(F->destination,"");//复制字符串 
	strcpy(F->flightId,"");
	strcpy(F->planeId,"");
	strcpy(F->time,"");
	F->money = 0.0;
	F->num=0;
	F->tickets=0;
	F->next=NULL;
	return OK;
}
//创建航班结点
flightList creat_Flight(char *des,char *fid,char *pid,char *time,float money,int num,int tickets){
	flightList air;
	air = (Flight*)malloc(sizeof(Flight));
	if(NULL==air) return ERROR;
	strcpy(air->destination,des);
	strcpy(air->flightId,fid);
	strcpy(air->planeId,pid);
	strcpy(air->time,time);
	air->money = money;
	air->num = num;
	air->tickets = tickets;
	//air->clist = NULL;
	//init_waitQueue(air->wqueue);
	air->next = NULL;
	init_passengerList(air->CLientc); 
	init_waitQueue(air->wqueue);
	//air->Clientc->behind = NULL;
	//air->CLientc->head = NULL;
	return air;
}

//在航班总信息链表中插入新航班信息
Status insert_flight(Flight *&h, Flight *p)
{	Flight *f;
	f = h;
	if(NULL == f&&NULL == p) return ERROR;
	p->next = f->next;
	f->next = p;
	return OK;

} 

对乘客的操作

//初始化乘客链表 
Status init_passengerList(clientListL &CLient)
{
	CLient=(clientList *)malloc(sizeof(clientList));//创建头结点
	if(NULL==CLient) return OVERFLOW ;
	CLient->behind=NULL;
	CLient->head=NULL;
	return OK;
}

//创建乘客结点 
clientListL creat_client(char *name,char *ID_num,char *flight_num,char *time,int order_num,int amout,int rank){
	clientListL client;
	client = (clientList*)malloc(sizeof(clientList));
	if(NULL!=client) {
	
	strcpy(client->name,name);
	strcpy(client->ID_num,ID_num);
	strcpy(client->flight_num,flight_num);
	strcpy(client->time,time);

	client->order_num = order_num;
	client->amout = amout;
	client->rank = rank;
	//strcpy(client->rank,rank);
	client->behind = NULL;
	client->head = NULL;}
	//air->clist = NULL;
	//init_waitQueue(air->wqueue);
	return client;	
}
//在乘客链表中插入新结点 
Status insert_clientList(clientListL &totalList,clientListL &cp) {
	clientListL p;
	p = totalList->behind;

	if(cp==NULL) return ERROR;
	if(p==NULL) {
		totalList->behind = cp;
		cp->head = totalList;
	}
	else {
		while(p) {
			if(strcmp(p->name,cp->name)==1 ||strcmp(p->name,cp->name)==0) {
						if(p->head->head == NULL) {
							cp->head = totalList;
							cp->behind = p;
							totalList->behind = cp;
							p->head = cp;
							break;
						}
						else {
							cp->head = p->head;
							cp->behind = p;
							cp->head->behind = cp;
							p->head = cp;
							break; 
						}  }
			
			else{
			
				if(p->behind==NULL) {
					p->behind = cp;
					cp->head = p;
					break;
				}
			}
			p = p->behind;
		} 
	}

	return OK;
}

订票功能

//订票函数  
int booking(clientList *&airCLient,int amount,int sum,int order_num,char *name,char *ID_num,char *flightId,char *time){//把乘客的结点生成并接入乘客链表+接入航班结点里的乘客链表 

	clientListL pessage =  creat_client(name,ID_num,flightId,time,order_num,amount,sum);

		if(insert_clientList(airCLient,pessage) == OK){
		printf("购票成功");return OK;
}
    else {system("cls");
	printf("购票失败,钱款已退回,请联系工作人员购票");}
		}
		

//推荐路线函数		
void recommand(Flight *air,clientList *CLient,char *flightId,char *destination,int amount){
//根据目的地相同,航班号不同,推荐新的航班(有票时)//价格重新计算(机票数不变,舱位不变),也要生成订单号 
	int randx(); 
	flightList p;
	char name[MAXSIZE];//姓名
	char ID_num[MAXSIZE];

	 int order_num;//订单号
	 p = air->next;
	 int mark = 0;
	 if(NULL== p||NULL==air) {printf("没有航班信息");
	 return;}
	 while(p){
	 	/*if(strcmp(destination,p->destination) == 0&&strcmp(flightId,p->flightId) !=0&&amount<=p->tickets&&p->tickets!=0) {
		 printf("%d",p->tickets);
		 printf("有");break;}*/
	 if(strcmp(destination,p->destination) == 0&&strcmp(flightId,p->flightId) !=0&&amount<=p->tickets&&p->tickets!=0)//找到了合适的机票,购买同样的机票
		{
		  printf("请输入你的真实姓名:");
		  scanf("%s",&name);
		  printf("请输入你的手机号码:");
		  scanf("%s",&ID_num);
			int rankx[amount];int g[amount];int sum;float money;//储存舱位拼接后的结果 		 	
			 for(int j=0;j<amount;j++)//将每个票的舱位拼接 
					{printf("请输入第%d张票的舱位等级",j+1);
					 scanf("%d",&rankx[j]);
					 float m = p->money;
					 printf("该票为%d等票,票价为%8.2f\n",rankx[j],m*(3.0/rankx[j]));
					 money += m*(3.0/rankx[j]);//票价总和 
					 g[j] = rankx[j]*pow(10,amount-j-1);
					 sum+=g[j];
					}
				printf("您需要支付%8.2f元\n",money);
				getch();	
				int d = randx();order_num =  d*10+d/2;//对订单号做简单的运算
			 
			 
			 if(OK == booking(p->CLientc,amount,sum,order_num,name,ID_num,p->flightId,p->time))//amout,
			 {printf("你新的航班号是:%s,起飞时间为:%s,订单号为%d",p->flightId,p->time,order_num);
			 p->tickets = p->tickets-amount;mark = 1;}break;
	 	}
	 	p = p->next;
	 }
	 if(mark == 0) printf("没有找到合适航班信息!!!"); 
}



//加入候补队列函数 ; 
int wiat(waitPtr &wqueue,int amount){
	// 	char name[MAXSIZE];//姓名char ID_num[MAXSIZE];//证件号int amout;//订票数量int rank;//舱位等级 ,char *n,int amount,char *ID_num,int rank
	char name[MAXSIZE];
	char ID_num[MAXSIZE];
	printf("请输入你的名字:");
	scanf("%s",&name);
	printf("请输入你的手机号码:");
	scanf("%s",&ID_num);
	if(OK == en_waitQueue(wqueue,name,amount,ID_num)) {
	
	system("cls");
	printf("\t\t\t\t*******************************************************\n");
	printf("\t\t\t\t*                 欢迎使用CWJ航空系统                 *\n");
	printf("\t\t\t\t*                你已经成功加入候补名单               *\n");
	printf("\t\t\t\t*               如果您满足条件,管理员将联系您        *\n");
	printf("\t\t\t\t*                 ——————————                *\n"); 
	printf("\t\t\t\t*******************************************************\n");
	}
	else printf("加入失败"); 
} 
	

		
//订票引导函数,引用了订票函数,推荐路线函数,加入候补队列函数  用户功能2 
int bookTickets(flightList &air){
	int randx();
	system("cls");//清屏代码 
	printf("\t\t\t\t*******************************************************\n");
	printf("\t\t\t\t*                                                     *\n");
	printf("\t\t\t\t*                 欢迎进入CWJ航空系统                 *\n");
	printf("\t\t\t\t*                                                     *\n");
	printf("\t\t\t\t*                   当前为 订票窗口                   *\n");
	printf("\t\t\t\t*                                                     *\n");
	printf("\t\t\t\t*******************************************************\n");
	void home();
	Flight *p;p = air->next;//从头结点后一结点开始查询
	Flight *k;k = air->next; 
	char flightId[MAXSIZE];//航班号 
	char flightId1[MAXSIZE];
	char destination[MAXSIZE];//目的地 
	int amount;char i;
	int flag = 0;
	char name[MAXSIZE];//姓名
	char ID_num[MAXSIZE];
	int order_num;int mark = 0;//订单号 
	int markj = 0;
	printf("你可以输入你的目的地(按1)或者航班号(按2)来查询:");
	scanf("%s",&i);
	while(i!='1'&&i!='2'){
		printf("无效输入,请重输:"); 
		scanf("%s",&i);
	}
	if(i=='1'){ 
		printf("请输入目的地:");
		scanf("%s",&destination);
		printf("按任意键后输入票数,系统将为你返回查询信息\n");
		getch();
		printf("请输入要购买的票数:");
		scanf("%d",&amount);
		while(p){
		//&&amount<=p->tickets&&p->tickets!=0 
		if(strcmp(destination,p->destination)==0) flag = 1;
		if(strcmp(destination,p->destination)==0&&amount<=p->tickets&&p->tickets!=0){
			//if(amount<=p->tickets&&p->tickets!=0){
			
			if(strcmp(destination,p->destination)==0) markj = 1;//有到达这个地点的航班 
			
			int rankx[amount];int g[amount];int sum=0;float money = 0.0;//储存舱位拼接后的结果 

				printf("请输入你的真实姓名:");
				scanf("%s",&name);
				printf("请输入你的手机号码:");
				scanf("%s",&ID_num);

				printf("请分别输入你的需要的舱位等级:");
				for(int j=0;j<amount;j++)//将每个票的舱位拼接 
					{printf("请输入第%d张票的舱位等级",j+1);
					 scanf("%d",&rankx[j]);
					 float m = p->money;
					 printf("该票为%d等票,票价为%8.2f",rankx[j],m*(3.0/rankx[j]));
					 money += m*(3.0/rankx[j]);//票价总和 
					 g[j] = rankx[j]*pow(10,amount-j-1);
	
					 sum+=g[j];
		
					}
				printf("您需要支付%8.2f元",money);
				getch();	
				int d = randx();order_num =  d*10+d/2;//对订单号做简单的运算

				if(OK == booking(p->CLientc,amount,sum,order_num,name,ID_num,p->flightId,p->time))
				
				 {
					printf("\n你的航班号是:%s,你的起飞时间为:%s,订单号为%d",p->flightId,p->time,order_num);
				p->tickets = p->tickets-amount;mark = 1;

				}
		
				break;
			}
			if(strcmp(destination,p->destination)==0)
			{
			strcpy(flightId1,p->flightId);
		}
			p = p->next;
		
		}//结束了对航班的遍历
		//printf("%d,flag是",flag);
		if(mark == 0&&flag == 1) {
			//这里flag == 1 ,表明航班链表里面有这个航班 
				printf("我们已经遍历了所有到达 %s 的航班,它们的余票都不满足你的需求!",destination);
				printf("\n请问你想加入到达 %s 的航班 %s 的候补名单吗(?1/2)",destination,flightId1);
		char o;
		printf("\n请输入:");
		scanf("%s",&o);
		while(o!='1'&&o!='2'){
		printf("无效输入,请重输:");
		scanf("%s",&o);
					}

		if(o == '1') {
			while(k){
		if(strcmp(flightId1,k->flightId)==0)
		{
		wiat(k->wqueue,amount) ;break;}
		k = k->next;}
			
			
		}
				//int wiat(waitQueue &wqueue,char *n,int amount,char *ID_num,int rank)
		if(o == '2' ){
		home();
				}
		
		}
	
		}  
	 
	if(i=='2'){//根据航班号得到目的地 
		printf("请输入航班号:");
		scanf("%s",&flightId);
		printf("按任意键后输入票数,系统将为你返回查询信息\n");
		getch();
		printf("请输入要购买的票数:");
		scanf("%d",&amount);
		while(p){
		if(strcmp(flightId,p->flightId)==0){
			flag = 1;
			if(p->tickets>=amount)
			{
			int rankx[amount];int g[amount];int sum = 0;float money = 0.0;//储存舱位拼接后的结果
				printf("请输入你的真实姓名:");
				scanf("%s",&name);
				printf("请输入你的手机号码:");
				scanf("%s",&ID_num);

				printf("请分别输入你的需要的舱位等级:");
				for(int j=0;j<amount;j++)//将每个票的舱位拼接 
					{printf("请输入第%d张票的舱位等级",j+1);
					 scanf("%d",&rankx[j]);
					 float m = p->money;
					 printf("该票为%d等票,票价为%8.2f\n",rankx[j],m*(3.0/rankx[j]));
					 money += m*(3.0/rankx[j]);//票价总和 
					 g[j] = rankx[j]*pow(10,amount-j-1);
					 sum+=g[j];
					}
				printf("您需要支付%8.2f元",money);
				getch();	
				int d = randx();order_num =  d*10+d/2;//对订单号做简单的运算
				if(OK == booking(p->CLientc,amount,sum,order_num,name,ID_num,p->flightId,p->time)){
				printf("\n你的起飞时间为:%s,订单号为%d",p->time,order_num);
				p->tickets = p->tickets-amount;}
			}else if(p->tickets==0)
			{printf("\n该航班已满员,请问是否需要推荐到达 %s 的其他航线?(y/n)\n",p->destination);char f;
			//recommend(air,flightId,destination,amount);
			printf("请输入:");
			scanf("%s",&f);
			while(f!='y'&&f!='n'){
				printf("无效输入,请重输:");
				scanf("%s",&f);
			}
			if(f == 'y') recommand(air,CLient,flightId,p->destination,amount);
			if(f == 'n') {
				printf("请问你想加入航班 %s 的候补队列吗(?1/2)",flightId);char t;
				printf("请输入:");
				scanf("%s",&t);
				while(t!='1'&&t!='2'){
					printf("无效输入,请重输:");
					scanf("%s",&t);
					}
				if(t == '1') wiat(p->wqueue,amount) ;
				//int wiat(waitQueue &wqueue,char *n,int amount,char *ID_num,int rank)
				if(t == '2' ){
				home();//break;
				}
		}
			}else if(p->tickets!=0&&p->tickets<amount){
			printf("抱歉,余票仅剩 %d ,是否推荐到达 %s 的其他航线?(?y/n)",p->tickets,p->destination);char f;
			printf("请输入:");
			scanf("%s",&f);
			while(f!='y'&&f!='n'){
				printf("无效输入,请重输:");
				scanf("%s",&f);}
			if(f == 'y') recommand(air,CLient,p->flightId,p->destination,amount);
			if(f == 'n') {
				printf("请问你想加入航班 %s 的候补队列吗(?1/2)",flightId);char t;
				printf("请输入:");
				scanf("%s",&t);
				while(t!='1'&&t!='2'){
					printf("无效输入,请重输:");
					scanf("%s",&t);
					}
				if(t == '1') wiat(p->wqueue,amount) ; 
				if(t == '2' ){
				home();break;
				}
		}
			}
		break;
		}
		p = p->next;}  
	}
	if(flag==0){printf("\n查询不到该航班!请返回确认\n");
	}
	printf("\n输入1继续购票,输入2返回主页面");
	char l;
	scanf("%s",&l);
	while(l!='1'&&l!='2'){
		printf("无效输入,请重输");
		scanf("%s",&l);
		}
	if(l == '1') bookTickets(flight);
	if(l == '2') home();
	 
	  
	 } 
	 

退票

//退票 功能6 
int refund(flightList &air){
	void adminhome();
	system("cls");
	printf("\t\t\t\t*******************************************************\n");
	printf("\t\t\t\t*                 欢迎使用CWJ航空系统                 *\n");
	printf("\t\t\t\t*            ———————————————           *\n");
	printf("\t\t\t\t*           | !!高级权限,请谨慎操作!!|           *\n");
	printf("\t\t\t\t*            ———————————————           *\n");
	printf("\t\t\t\t*                  当前为退票窗口                     *\n");
	printf("\t\t\t\t*******************************************************\n");
	char flightId[MAXSIZE];
	int am;
	char name[MAXSIZE];
	printf("请输入你的名字:");
	scanf("%s",name);
	printf("请输入航班号:");
	scanf("%s",flightId);
	printf("请输入你要退订的票数:");
	scanf("%d",&am);
	flightList p = air->next;//从头结点的下一个结点开始 
	int flag = 0;
	clientListL totaList;
	clientListL totaList1;
	while(p){
		if(strcmp(p->flightId,flightId) == 0){//找到该航班结点 
			totaList = p->CLientc;//从该头结点的下一位开始
			totaList1 = p->CLientc->behind; 
		while(totaList){
			if(strcmp(totaList->name,name) == 0){//找到了该乘客结点 
				
				if(am<totaList->amout){
					totaList->amout = totaList->amout-am;//只是修改乘客结点的票数 
					p->tickets = p->tickets+am;//票数变化
					printf("\n退票成功!退款金额已经成功原路返回您的账号\n");
					show(p,p->wqueue);
				}
				else if(am == totaList->amout){//全部退票,要删除整一个结点 
					if(OK==delete_clientList(totaList1,totaList)) 
					{totaList->amout = totaList->amout-am;
					p->tickets = p->tickets+am;//票数变化
					printf("\n退票成功!退款金额已经成功原路返回您的账号\n");
					printf("现在票数为%d",p->tickets);
					show(p,p->wqueue);} 
				}
				else printf("你购买的票数没有这么多,请重新确认");
				flag = 1;
				break;
				}
			totaList = totaList->behind;
				
			}
			
		break;
		}
		p = p->next;
	}
	if(flag == 0){
		printf("找不到该订单,退票失败");
	
	}
	printf("\n输入1继续操作退票,输入2返回管理员页面:");
	char l;
	scanf("%s",&l);
	while(l!='1'&&l!='2'){
		printf("无效输入,请重输");
		scanf("%s",&l);
		}
	if(l == '1') refund(flight); 
	if(l == '2') adminhome();
	
	return flag;
	
}

由于边幅有限,对候补乘客的操作,查询航线,修改航线信息,查询订单以及普通用户和管理员UI页面的设计等内容的全部可运行代码放到了公众号里,关注并回复100901可获得全部代码
航空客运系统代码-课程设计(C语言)_第2张图片

你可能感兴趣的:(课程设计,C语言)