📄 航空售票系统.cpp
字号:
return TmpPasPoint;
}
TmpPasPoint = TmpPasPoint->link;
}
return NULL;
}
//按飞机航班号查询,第一个参数是飞机信息链表的头节点,第二个是待查询的飞机航班
PlanePoint SearchFightNo(PlanePoint PlaneList, string fightNo)
{
PlanePoint TmpPlanePoint;
TmpPlanePoint = PlaneList->Link;
while(TmpPlanePoint != 0)
//循环比较每个飞机信息中的航班号与参数中的航班号一致,一致的话返回该航班信息链表,否则返回NULL
{
if((TmpPlanePoint->FightNo.compare(fightNo)) == 0)
{
PrintPlane(TmpPlanePoint);
return TmpPlanePoint;
}
TmpPlanePoint = TmpPlanePoint->Link;
}
if(TmpPlanePoint == 0)
{
cout<<"No this fight."<<endl;
return 0;
}
return 0;
}
//订票模块
//用户订票,第一个参数是飞机信息链表的头节点,第二个是航班号,第三个是购买数量
void Bookticket(PlanePoint PlaneList, string fightNo, int ticketAmout)
{
PlanePoint TmpPlanePoint;
TmpPlanePoint = SearchFightNo(PlaneList, fightNo);
PasPoint TmpPasPoint;
char ch;
string name;//姓名
string password;//密码
string idNo;//身份证号
int seatNo;//座位号
int* seatExtra;
int tmp[MAXPASNUMBER];
if (TmpPlanePoint == 0)
return;
else if(TmpPlanePoint->ExtraTicket == 0) //如果没有剩票的话,打印没有剩票
{
cout<<"No ticket left."<<endl;
cout<<"Thank you.Goodbye!"<<endl;
return;
}
else if(TmpPlanePoint->ExtraTicket < ticketAmout)//如果票不够的话,请客户选择购剩余的票还是不购票
{
cout<<"No enough ticket."<<endl;
cout<<"Would you want to book "<<TmpPlanePoint->ExtraTicket<<" ticket(s)?(Y or N)"<<endl;
cin>>ch;
getchar();
while(1)
{
if((ch == 'y') || (ch == 'Y'))
{
ticketAmout = TmpPlanePoint->ExtraTicket;
break;
}
else if((ch == 'n') || (ch == 'N'))
{
cout<<"Thank you.Goodbye!"<<endl;
return;
}
else
{
cout<<"Input Error!Input Y or N!"<<endl;
cin>>ch;
}
}
}
if(TmpPlanePoint->ExtraTicket >= ticketAmout)
{
PrintPlane(TmpPlanePoint);
for (int i = 1; i <= ticketAmout; i++)//请乘客输入本人信息
{
getchar();
cout<<"Please input the name of "<<i<<" passenger:";
getline(cin, name);
getchar();
cout<<"Please input the password of "<<i<<" passenger:";
getline(cin, password);
getchar();
cout<<"Please input the IDNo. of "<<i<<" passenger:";
getline(cin, idNo);
getchar();
cout<<"The seat numbers left:";
seatExtra = PrintExtraSeat(TmpPlanePoint);//打印尚有的座位号,让乘客选择
for(int j = 1;j <= MAXPASNUMBER;j++)
{
tmp[j] = seatExtra[j];
}
cout<<"Please choose one seat!"<<endl;
cout<<"Please input the seatNo. of "<<i<<" passenger:";
cin>>seatNo;
while(tmp[seatNo] == 0)//如果乘客选的座位号已经被订的话,打印已经被订,让乘客重新选择
{
cout<<"The seat has been booked.Please choose another:";
cin>>seatNo;
}
TmpPasPoint = AttachPasMes(TmpPlanePoint,name,password,idNo,seatNo);//订票成功的话将乘客信息链入乘客信息链表
PrintPas(TmpPasPoint);//打印乘客信息
TmpPlanePoint->ExtraTicket--;
TmpPlanePoint->PasNum++;
}
cout<<"Successful.Thank you!"<<endl;
}
}
//退票模块
//用户退票,第一个参数是飞机信息链表的头节点,第二个是航班号,第三个是乘客姓名
void ReturnTicket(PlanePoint PlaneList, string fightNo, string name)
{
PlanePoint TmpPlanePoint;
PasPoint TmpPasPoint;
char password[8];int i = 0,j = 0;
TmpPlanePoint = SearchFightNo(PlaneList, fightNo);//按航班寻找所在飞机信息链表
if(TmpPlanePoint == 0)//没有该飞机时返回
{
return;
}
TmpPasPoint = SearchName(TmpPlanePoint, name);//按姓名搜索所在乘客信息链表的节点
if(TmpPasPoint == 0)//没有找到时返回
{
cout<<"No this passenger."<<endl;
return;
}
cout<<"Please input the password:";
do{
for(i = 0;i < 7; i++)
{
password[i]=getch();
if(password[i] == '\r')
{
password[i] = '\0';
break;
}
cout<<"*";
if(password[i] == '\b')
{
putchar('\b');
putchar('\b');
putchar(' ');
putchar(' ');
putchar('\b');
putchar('\b');
i--;
i--;
}
}
cout<<endl;
if((TmpPasPoint->Password.compare(password)) == 0)
break;
if(j < 2)
cout<<"Password Error!Please input again:"<<endl;
j++;//只能输入3次
}while(j < 3);
if(j == 3)
{
cout<<"Sorry,you are wrong for three times.Goodbye!"<<endl;
return;
}
TmpPlanePoint->ExtraTicket++;
TmpPlanePoint->PasNum--;
DeletePas(TmpPlanePoint, TmpPasPoint);//删除该用户
}
//打印模块
//打印乘客信息,参数是乘客信息节点指针
void PrintPas(PasPoint pasPoint)
{
cout<<"name:"<<pasPoint->Name<<endl;
cout<<"SeatNo:"<<pasPoint->SeatNo<<endl;
cout<<"IDNo:"<<pasPoint->IDNo<<endl;
}
//打印航班信息,参数是航班信息节点指针
void PrintPlane(PlanePoint planePoint)
{
cout<<"FightNo:"<<planePoint->FightNo<<endl;
cout<<"Source:"<<planePoint->Source<<endl;
cout<<"Dest:"<<planePoint->Dest<<endl;
cout<<"TakeUpTime:Week:"<<(planePoint->Takeuptime).week<<endl<<" Time:"
<<(planePoint->Takeuptime).hour<<":"<<(planePoint->Takeuptime).minute<<endl;
cout<<"ExtraTickets:"<<planePoint->ExtraTicket<<endl;
cout<<"PasNum:"<<planePoint->PasNum<<endl;
}
//打印剩余的座位号,参数是航班信息链表节点指针,返回该航班剩余座位号数组
int* PrintExtraSeat(PlanePoint TmpPlanePoint)
{
int UsedSeat[MAXPASNUMBER];
int AllSeat[MAXPASNUMBER];
PasPoint TmpPasPoint = TmpPlanePoint->Dlink;
int i = 1;
int j = 1;
while(TmpPasPoint != 0)
{
UsedSeat[i] = TmpPasPoint->SeatNo;//储存所有有乘客的座位号
TmpPasPoint = TmpPasPoint->link;
i++;
}
for (j = 1; j <= TmpPlanePoint->PasNum + TmpPlanePoint-> ExtraTicket; j++)
{
AllSeat[j] = j;//所有座位号置j
}
for(j = 1; j <= TmpPlanePoint->PasNum; j++)
{
AllSeat[UsedSeat[j]] = 0;//有乘客座的座位置0
}
for(j = 1; j <= TmpPlanePoint->PasNum + TmpPlanePoint-> ExtraTicket; j++)
{
if(AllSeat[j] != 0)
cout<< AllSeat[j]<<" ";//打印不是0的座位号,即没有人坐的座位
}
for(j = TmpPlanePoint->PasNum + TmpPlanePoint-> ExtraTicket + 1; j < MAXPASNUMBER;j++)
{
AllSeat[j] = 0;
}
return &AllSeat[0];
}
//打印所有航班票务
void PrintAllPlaneMeg(PlanePoint PlaneList)
{
PlaneList = PlaneList->Link;
while(PlaneList != 0)//循环打印
{
PrintPlane(PlaneList);
cout<<endl;
PlaneList = PlaneList->Link;
}
}
//链表操作模块
//添加一个新节点保存乘客信息,第一个参数是添加处的航班链表指针,第二个是姓名,依次是密码,ID号,座位号
PasPoint AttachPasMes(PlanePoint planePoint,string name,string password,string idNo, int seatNo)
{
PasPoint TmpPasPoint = new PasMesNode;
TmpPasPoint->Name = name;
TmpPasPoint->Password = password;
TmpPasPoint->IDNo = idNo;
TmpPasPoint->SeatNo = seatNo;
TmpPasPoint->link = planePoint->Dlink;
planePoint->Dlink = TmpPasPoint;
return TmpPasPoint;
}
//删除节点,第一个参数是航班信息链表节点指针,第二个是要删除的乘客信息链表指针
void DeletePas(PlanePoint planePoint, PasPoint pasPoint)
{
PasPoint TmpPasPoint = 0;//临时当前节点
PasPoint HeadPasPoint = 0;//临时前一节点
PasPoint Tmp = 0;//临时节点
if (planePoint->Dlink == 0)
{
cout<<"No this Passenger."<<endl;
return;
}
else
TmpPasPoint = planePoint->Dlink;
if(TmpPasPoint == pasPoint)
{
planePoint->Dlink = TmpPasPoint->link;
delete TmpPasPoint;
cout<<"Successful!"<<endl;
return;
}
while(TmpPasPoint->link != 0)
{
HeadPasPoint = TmpPasPoint;
if(TmpPasPoint->link == pasPoint)
{
HeadPasPoint = TmpPasPoint->link->link;
Tmp = TmpPasPoint->link;
delete Tmp;
cout<<"Successful!"<<endl;
return;
}
TmpPasPoint = TmpPasPoint->link;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -