飞机订票系统

在这里插入图片描述

#include<iostream>
#include<string>
#include<cstring>
#include<cstdio>
using namespace std;

typedef struct _REC
{
	char name[20];//名字
	char ID[20];//身份证
	char seat[20];//座位
}REC;

int Menu()
{
	int choice;
	system("cls");
	cout<<"1:订票"<<endl;
	cout<<"2:查看清单"<<endl;
	cout<<"0:退出"<<endl;
	cout<<"请输入选择:";
	cin>>choice;
	return choice;
}

int FindTick(REC rec[],int n,char s[])
{
	int i;
	for(i=0;i<n;i++)
	{
		if(!strcmp(rec[i].seat,s))
			return i;
	}
	return -1;
}

void int2seat(int x,char ch,char ans[])
{
	int i=0;
	if(x>=10)
	{
		ans[i++]=x/10+'0';
	}
	ans[i++]=(x%10)+'0';
	ans[i++]=ch;
	ans[i]='\0';
}

int SelectAll(REC rec[],int n)
{
	int i,j,ans;
	char seat[20];
	char temp[20];
	system("cls");
	printf("%-4s%-4s%-4s%-4s%-4s\n","","A","B","C","D");
	for(i=1;i<=20;i++)
	{
		printf("%-2d:",i);
		for(j='A';j<='D';j++)
		{
			int2seat(i,j,seat);
			if(FindTick(rec,n,seat)!=-1)
			{
				printf("%-4s","无");
			}
			else
			{
				printf("%-4s","有");
			}
		}
		printf("\n");
	}
	cout<<"是否购买机票?Y/N"<<endl;
	cin>>temp;
	if(!strcmp("Y",temp)||!strcmp("y",temp))
	{
		cout<<"请输入要购买的座位号:";
		cin>>temp;
		ans=FindTick(rec,n,temp);
		if(ans==-1)
		{
			cout<<"请输入购买人姓名:";
			cin>>rec[n].name;
			cout<<"请输入购买人身份证号:";
			cin>>rec[n].ID;
			strcpy(rec[n].seat,temp);
			cout<<"购买成功!"<<endl;
			system("pause");
			return n+1;
		}
		else
		{
			cout<<"该座位已售出!"<<endl;
			system("pause");
			return n;
		}
	}
	else
		return n;
}

int SelectSmoke(REC rec[],int n)
{
	int i,j,ans;
	char seat[20];
	char temp[20];
	system("cls");
	printf("%-4s%-4s%-4s%-4s%-4s\n","","A","B","C","D");
	for(i=19;i<=20;i++)
	{
		printf("%-2d:",i);
		for(j='A';j<='D';j++)
		{
			int2seat(i,j,seat);
			if(FindTick(rec,n,seat)!=-1)
			{
				printf("%-4s","无");
			}
			else
			{
				printf("%-4s","有");
			}
		}
		printf("\n");
	}
	cout<<"是否购买机票?Y/N"<<endl;
	cin>>temp;
	if(!strcmp("Y",temp)||!strcmp("y",temp))
	{
		cout<<"请输入要购买的座位号:";
		cin>>temp;
		ans=FindTick(rec,n,temp);
		if(ans==-1)
		{
			cout<<"请输入购买人姓名:";
			cin>>rec[n].name;
			cout<<"请输入购买人身份证号:";
			cin>>rec[n].ID;
			strcpy(rec[n].seat,temp);
			cout<<"购买成功!"<<endl;
			system("pause");
			return n+1;
		}
		else
		{
			cout<<"该座位已售出!"<<endl;
			system("pause");
			return n;
		}
	}
	else
		return n;
}

int SelectWindow(REC rec[],int n)
{
	int i,j,ans;
	char seat[20];
	char temp[20];
	system("cls");
	printf("%-4s%-4s%-4s%-4s%-4s\n","","A","B","C","D");
	for(i=1;i<=20;i++)
	{
		printf("%-2d:",i);
		for(j='A';j<='D';j++)
		{
			if(j=='B'||j=='C')
			{
				printf("%-4s","");
				continue;
			}
			int2seat(i,j,seat);
			if(FindTick(rec,n,seat)!=-1)
			{
				printf("%-4s","无");
			}
			else
			{
				printf("%-4s","有");
			}
		}
		printf("\n");
	}
	cout<<"是否购买机票?Y/N"<<endl;
	cin>>temp;
	if(!strcmp("Y",temp)||!strcmp("y",temp))
	{
		cout<<"请输入要购买的座位号:";
		cin>>temp;
		ans=FindTick(rec,n,temp);
		if(ans==-1)
		{
			cout<<"请输入购买人姓名:";
			cin>>rec[n].name;
			cout<<"请输入购买人身份证号:";
			cin>>rec[n].ID;
			strcpy(rec[n].seat,temp);
			cout<<"购买成功!"<<endl;
			system("pause");
			return n+1;
		}
		else
		{
			cout<<"该座位已售出!"<<endl;
			system("pause");
			return n;
		}
	}
	else
		return n;
}

int SelectInside(REC rec[],int n)
{
	int i,j,ans;
	char seat[20];
	char temp[20];
	system("cls");
	printf("%-4s%-4s%-4s%-4s%-4s\n","","A","B","C","D");
	for(i=1;i<=20;i++)
	{
		printf("%-2d:",i);
		for(j='A';j<='D';j++)
		{
			if(j=='A'||j=='D')
			{
				printf("%-4s","");
				continue;
			}
			int2seat(i,j,seat);
			if(FindTick(rec,n,seat)!=-1)
			{
				printf("%-4s","无");
			}
			else
			{
				printf("%-4s","有");
			}
		}
		printf("\n");
	}
	cout<<"是否购买机票?Y/N"<<endl;
	cin>>temp;
	if(!strcmp("Y",temp)||!strcmp("y",temp))
	{
		cout<<"请输入要购买的座位号:";
		cin>>temp;
		ans=FindTick(rec,n,temp);
		if(ans==-1)
		{
			cout<<"请输入购买人姓名:";
			cin>>rec[n].name;
			cout<<"请输入购买人身份证号:";
			cin>>rec[n].ID;
			strcpy(rec[n].seat,temp);
			cout<<"购买成功!"<<endl;
			system("pause");
			return n+1;
		}
		else
		{
			cout<<"该座位已售出!"<<endl;
			system("pause");
			return n;
		}
	}
	else
		return n;
}


void BookMenu(REC rec[],int* n)
{
	int choice;
	system("cls");
	do
	{
		system("cls");
		cout<<"1:查看全部余票"<<endl;
		cout<<"2:查看吸烟区余票"<<endl;
		cout<<"3:查看靠窗区余票"<<endl;
		cout<<"4:查看普通区余票"<<endl;
		cout<<"0:返回"<<endl;
		cout<<"请输入选择:";
		cin>>choice;
		switch(choice)
		{
		case 1:
			*n=SelectAll(rec,*n);
			break;
		case 2:
			*n=SelectSmoke(rec,*n);
			break;
		case 3:
			*n=SelectWindow(rec,*n);
			break;
		case 4:
			*n=SelectInside(rec,*n);
			break;
		}
	}while(choice!=0);
}

void PrintAll(REC rec[],int n)
{
	int i;
	system("cls");
	if(n==0)
	{
		cout<<"无订票信息!"<<endl;
		system("pause");
		return;
	}
	printf("%-10s%-20s%-10s\n","姓名","身份证","座位号");
	for(i=0;i<n;i++)
	{
		printf("%-10s%-20s%-10s\n",rec[i].name,rec[i].ID,rec[i].seat);
	}
	system("pause");
}

int main()
{
	int choice;
	REC rec[100];
	int n=0;
	do
	{
		choice=Menu();
		if(choice==1)
		{
			BookMenu(rec,&n);
		}
		else if(choice==2)
		{
			PrintAll(rec,n);
		}
	}while(choice!=0);
	return 0;
}
  • 1
    点赞
  • 7
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
1、问题描述: 航空客运订票的业务包括查询航班、客票预订和办理退票等。试设计一个航空客运订票系统,已使上述业务可以借助计算机完成。 2、功能要求: (1)每条航线所涉及的信息有终点站名、航班号、飞机号、星期几飞行、飞行周日(星期几)、乘员定额、余票量、已订票的客户名单(包括姓名、订票量、舱位等级),以及等候补替补的客户名单(包括姓名、所需票量)。 (2)作为示意系统:全部数据可以只放在内存中。 (3)系统能实现的操作和功能如下: 录入:可以录入航班情况(数据可以存储在一个数据文件中,数据结构、具体数据自定)。 查询航线:根据旅客提出的终点站名输入下列信息:航班号、飞机号、星期几起飞、最近航班的日期和余票量。 承办订票业务:根据客户提出的要求(航班号、订票数额)查询该航班票额情况,若尚有余票,则为客户办理订票手续,输出座位号。若已满员或者余票数少于订票额,则需重新寻味客户要求,若需要,可登记排队候补。 承办退票业务:根据客户提供的情况(日期、航班)为客户办理退票手续,然后查询该航班是否有人排队等候补。首先询问排在第一的客户,若所有退票额能满足他的要求,则为他办理订票手续否则依次询问其他排队候补的客户。 修改航班信息:当航班信息改变可以修改航班数据文件。

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值