#include <iostream>
#include <string>
#include<stdio.h>
#include<conio.h>
//<stdio.h><conio.h>两个头文件
//为了使用清屏“system("cls")”
using namespace std;
void password();
//用于密码保护
void FlightInsert();
// 添加一航班
void FlightDelete();
//前条件:已经输入了航班信息
//用于删除某一航班
void FlightLookup();
//查找某一航班
void FlightRework();
//前条件:已经输入了航班信息
//用于修改航班信息
void FlightBuyticket();
//买机票
void FlightCancelticket();
// 前条件:已经输入了航班信息
//退订机票
void Flightclean();
// 前条件:已经输入了航班信息
// 清空输入的信息
void MainMenu();
//主函数
typedef struct Customer //已定票乘客信息
{
char Name[10]; //乘客姓名
int Amount; //定票数量
int Level; //舱位等级
int SeatNum; //飞机座位号
char FlightNum[10]; //所定航班号
struct Customer *next;
}Customer;
typedef struct Replace //替补乘客信息
{
char Name[10]; //姓名
int Amount; //定票数量
int Level; //舱位等级
char FlightNum[10]; //所定航班号
struct Replace *next;
}Replace;
typedef struct Flight //航班信息
{
char Des[10]; //终点站名
char FlightNum[10]; //航班号
char PlaneNum[10]; //飞机号
char Week; //飞行周日
int Ration; //乘员定额(座位数)
int FreeTicket; //剩余票数(座位数-已定票数)
float Price[3]; //舱位等级的价格
int ReplacePas; //候补乘客数
Replace *ReplName; //该航班的候补乘客名单
Customer *CustName; //该航班的已定票乘客名单
struct Flight *next; //指示下一航线结点
}Flight,*PFlight;
int Ration=0; //乘客总数
Flight *head; //建立航线头结点
Flight *rear; //建立航线尾结点
Customer *Cusrear;
Replace *Reprear;
///////////////////////////////////////////////////////////////////////////////
void MainMenu()
{
password();
system("cls");
char i='0';
while (i!='8')
{
cout<<"\n\n\n\t\t\t\t航班管理系统小程序\n\n"<<endl;
cout<<"\t\t**************************************************"<<endl;
cout<<"\t\t* *"<<endl;
cout<<"\t\t* 1、添加航班 5、预订机票 *"<<endl;
cout<<"\t\t* *"<<endl;
cout<<"\t\t* 2、查询航班 6、退订机票 *"<<endl;
cout<<"\t\t* *"<<endl;
cout<<"\t\t* 3、修改航班 7、清空系统 *"<<endl;
cout<<"\t\t* *"<<endl;
cout<<"\t\t* 4、取消航班 8、退出系统 *"<<endl;
cout<<"\t\t* *"<<endl;
cout<<"\t\t**************************************************"<<endl;
cout<<"\n\t\t请选择操作:";
cin>>i;
system("cls");
switch(i)
{
case '1':FlightInsert();break;
case '2':FlightLookup();break;
case '3':FlightRework();break;
case '4':FlightDelete();break;
case '5':FlightBuyticket();break;
case '6':FlightCancelticket();break;
case '7':Flightclean();break;
case '8':;break;
default:
cout<<"\n\t\t\t输入选择错误,请您重新选择操作。\n";break;
}
}
}
/////////////////////////////////////////////////////////////////////////////////////
void password() //密码保护
{
int k=0,i;
char A[]="!@#$%^&*()";
char B[10];
char a;
system("cls");
for(i=0;i<8;i++)
cout<<endl;
while(k<=2)
{
printf("\t请输入管理员密码(提示: !@#$%^&*() ):");
i=0;
while(1)
{
a=getch();
if(a==13)
break;
B[i]=a;
i++;
printf("*");
}
B[i]='\0';
if(strcmp(A,B)==0)
return;
else
{
k++;
cerr<<"\n\n\t\t\t密码输入错误!请重新输入!\n"<<endl;
}
if(k>=3)
{
system("cls");
cerr<<"\n\n\t\t\t输入错误密码超过三次!请按任意键退出.."<<endl;
getch();
system("pause");
}
}
}
///////////////////////////////////////////////////////////////////////////////
void FlightInsert() //航班插入
{
system("cls");
Flight *p;
p=new Flight;
cout<<"\n\n\n"<<endl;
cout<<"\t\t请输入终点站名:";
cin>>p->Des;
cout<<endl;
cout<<"\t\t请输入航班号:";
cin>>p->FlightNum;
cout<<endl;
cout<<"\t\t请输入飞机号:";
cin>>p->PlaneNum;
cout<<endl;
cout<<"\t\t请输入飞行周日:";
cin>>p->Week;
cout<<endl;
cout<<"\t\t请输入乘员定额:";
cin>>p->Ration;
cout<<endl;
p->FreeTicket=p->Ration;
cout<<"\t\t请输入舱位等级的价格: ";
cout<<"1.头等舱价格";
cin>>p->Price[0];
cout<<endl;
cout<<"\t\t\t\t\t2.普通舱价格";
cin>>p->Price[1];
cout<<endl;
cout<<"\t\t\t\t\t3.经济舱价格";
cin>>p->Price[2];
cout<<"\n\n\n"<<endl;
system("cls");
p->ReplName=new Replace;
p->CustName=new Customer;
p->CustName->next=NULL;
p->ReplName->next=NULL;
p->ReplacePas=0;
rear->next=p;
rear=p;
rear->next=NULL;
}
///////////////////////////////////////////////////////////////////////////////
void FlightDelete() //删除航班
{
system("cls");
Flight *p,*q;
char FlightNum[10];
p=head;
int i=0;
while (i!=1)
{
cout<<"\n\n\n\n"<<endl;
cout<<"\t\t请输入需要删除的航班号: ";
cin>>FlightNum;
while (p->next&&strcmp(p->next->FlightNum,FlightNum))
{
p=p->next;
}
q=p->next;
if (q!=NULL)
{
if(q->next==NULL)
{ //当删除rear所指向的结点
rear=p;
}
p->next=p->next->next;
delete q;
cout<<"\n"<<endl;
cout<<"\t\t*********************************"<<endl;;
cout<<"\t\t* 此航班已经被删除 *"<<endl;;
cout<<"\t\t*********************************"<<endl;
}
else
{
cout<<"\n"<<endl;
cout<<"\t\t你所要删除的航班不存在"<<endl;
}
cout<<"\n"<<endl;
cout<<"\n\n\t\t1、退出 2、继续 ";
cin>>i;
}
}
/////////////////////////////////////////////////////////////////////////////////
void FlightLookup() //查询航班
{
system("cls");
Flight *p,*q;
char FlightNum[10];
p=head;
int i=0;
while (i!=1)
{
cout<<"\n\n"<<endl;
cout<<"\t\t请输入需要查询的航班号:";
cin>>FlightNum;
while (p->next&&strcmp(p->next->FlightNum,FlightNum))
{
p=p->next;
}
q=p->next;
if (q==NULL)
{ cout<<"\n\n"<<endl;
cout<<"\t\t*********************************"<<endl;;
cout<<"\t\t* 对不起不存在此航班 *"<<endl;;
cout<<"\t\t*********************************"<<endl;
}
else
{ cout<<"\n"<<endl;
cout<<"\t\t*********************************************"<<endl;
cout<<"\t\t* 航班号: "<<q->FlightNum;
cout<<"\t\t飞机号: "<<q->PlaneNum<<endl;
cout<<"\t\t* "<<endl;
cout<<"\t\t* 目的地: "<<q->Des;
cout<<"\t\t飞行周日: "<<q->Week<<endl;
cout<<"\t\t* "<<endl;
cout<<"\t\t* 成员定额: "<<q->Ration;
cout<<"\t\t剩余票数: "<<q->FreeTicket<<endl;
cout<<"\t\t* "<<endl;
cout<<"\t\t* 候补乘客数: "<<q->ReplacePas;
cout<<"\t头等舱价格: "<<q->Price[0]<<endl;
cout<<"\t\t* "<<endl;
cout<<"\t\t* 普通舱价格: "<<q->Price[1];
cout<<"\t经济舱价格: "<<q->Price[2]<<endl;
cout<<"\t\t*********************************************"<<endl;
}
cout<<"\n"<<endl;
cout<<"\t