#include "public.h"
#ifndef _ticket_cpp
#define _ticket_cpp
extern char ID[6]; //用户名
extern int admin; //权限0 游客 1旅行社 2航班管理
#endif
/*
typedef struct{
char agency[7];
char user[10];
char sex[2]; //0女 1男
char Inc[20]; //单位
char ID[20];//身份证
int grade; //0:头等舱 1:公务舱 2:经济舱
int state; //0没交定金 1交定金 2交钱取票
char name[6]; //航班名称
}Ticket;
*/
void TicketCopy(Ticket &T1,Ticket T2)
{
strcpy(T1.agency,T2.agency);
strcpy(T1.ID,T2.ID);
strcpy(T1.Inc,T2.Inc);
strcpy(T1.name,T2.name);
strcpy(T1.sex,T2.sex);
strcpy(T1.user,T2.user);
T1.grade=T2.grade;
T1.state=T2.state;
}
int usersearch(){
char flightnum[10];
char choice;
FILE *f;
Flight flight[10];
char st[10];
char des[10];
int a,flag=0;
int i,j,tag[10];
if ((f=fopen("Flight.dat","rb"))==NULL)
{
return 0;
}
else
{
fread(&flight,sizeof(flight),1,f);
fclose(f);
}
while(a!=8)
{
system("cls");
cout<<"\n\t############*#############*#############*##############*#####:"<<endl;
cout<<"\n\t\t 查找航班:可选择的查找方式:"<<endl;
cout<<"\n\t\t 1.航班号 2.目的地与出发地 8.退出"<<endl;
cout<<"\n\t###*####***########***#######***#########***######***####***#:"<<endl;
printf("\n\n\t\t你的选择:");
scanf("%d",&a);
flushall();
switch(a){
case 1:
system("cls");
ShowFlight(0,tag);
printf("\n\n\t\t\t请输入航班号");
scanf("%s",&flightnum);
system("cls");
cout<<"*-----------------------------------------------------------------------------*"<<endl;
cout<<"*航班的名称:出发地:目的地: 日期: 时间: 头等舱价格: 公务舱价格: 经济舱价格*"<<endl;
cout<<"*-----------------------------------------------------------------------------*"<<endl;
for(i=0;i<10;i++)
{
if((strcmp(flight[i].name,flightnum))==0)
{flag=1;
cout<<" "<<flight[i].name<<" "<<" "<<flight[i].start<<" "<<flight[i].destination;
cout<<" "<<flight[i].date<<" "<<flight[i].time <<" ";
cout<<" "<<flight[i].price[0]<<" "<<flight[i].price[1]<<" "
<<" "<<flight[i].price[2]<<endl;
cout<<endl<<endl;
printf("你是否要订这航班,确定输y/Y,退出输入n/N:\n");
printf("%c",(choice=getch()));getch();
if(choice=='y'||choice=='Y')
{
return Destine(flight[i].name);
}
else
{
printf("退出预定!\n");
return 0;
}
}
}
if(!flag) printf("没有满足你要查找的航班!\n");
break;
case 2:
system("cls");
printf("*####---------------------------------------------------------------------####*");
printf("\n\n\t\t出发地: ");
scanf("%s",&st);
printf("\t\t目的地: ");
scanf("%s",&des);
system("cls");
cout<<"*-----------------------------------------------------------------------------*"<<endl;
cout<<"*航班的名称:出发地:目的地: 日期: 时间: 头等舱价格: 公务舱价格: 经济舱价格*"<<endl;
cout<<"*-----------------------------------------------------------------------------*"<<endl;
for(i=0;i<10;i++)
{
if((strcmp(flight[i].start,st))==0&&(strcmp(flight[i].destination,des))==0)
{
flag++; j=i;
cout<<" "<<flight[i].name<<" "<<" "<<flight[i].start<<" "<<flight[i].destination;
cout<<" "<<flight[i].date<<" "<<flight[i].time <<" ";
cout<<" "<<flight[i].price[0]<<" "<<flight[i].price[1]<<" "
<<" "<<flight[i].price[2]<<endl;
}
}
cout<<"*-----------------------------------------------------------------------------*"<<endl;
if(!flag) printf("\n\t\t没有满足你要查找的航班!\n");
if(flag==1)
{
printf("\n\t\t你是否要订这航班,确定输y/Y,退出输入n/N:\n");
scanf("%c",&choice);
if(choice=='y'||choice=='Y')
{
return Destine(flight[j].name);
}
else
{
printf("\n\t\t退出预定!\n");
return 0;
}
}
if(flag>1){
printf("输入你要选择的航班名称:");
scanf("%s",flightnum);
Destine(flightnum);
}
default:break;
}
}//while
return 0;
}
int Destine(char flightname[]){
system("cls");
Ticket ticket[10];Flight flight[10];
FILE *f;
int i,j;char ch;
if ((f=fopen("Flight.dat","rb"))==NULL)
{
return 0;
}
else
{
fread(&flight,sizeof(flight),1,f);
}
fclose(f);
for(i=0;i<10;i++)
{
if((strcmp(flight[i].name,flightname))==0) //找到了
{
if ((f=fopen("Ticket.dat","r"))==NULL)
{
return 0;
}
else
{
fread(&ticket,sizeof(ticket),1,f);
}
fclose(f);
j=AvailableTag(1);
printf("\n请输入定票用户姓名:");
scanf("%s",&ticket[j].user);
printf("姓别:");
scanf("%s",&ticket[j].sex);
printf("单位:");
scanf("%s",&ticket[j].Inc);
printf("身份证:");
scanf("%s",&ticket[j].ID);
printf("请选择要乘坐的舱位0:头等舱 1:公务舱 2:经济舱:");
scanf("%d",&ticket[j].grade);
CheckTicket(ticket[j]);
printf("确认定票并交100元定金?(y/n)");
scanf("%s",&ch);
if(ch=='n'||ch=='N')return 0; //退出
if ((f=fopen("Ticket.dat","w+b"))==NULL)
{
return 0;
}
else
{
ticket[j].state=1;
strcpy(ticket[j].name,flight[i].name);
strcpy(ticket[j].agency,ID);
fwrite(&ticket,sizeof(ticket),1,f);
}
fclose(f);
if ((f=fopen("Flight.dat","w+b"))==NULL)
{
return 0;
}
else
{
int tag=2;
flight[i].re_ticket[ticket[j].grade%3]=flight[i].re_ticket[ticket[j].grade%3]-1;
fwrite(&flight,sizeof(flight),1,f);
}
fclose(f);
system("cls");
int money;
printf("\n\t\t\t###############################");
printf("\n\t\t\t# 预定成功! #");
printf("\n\t\t\t###############################");
printf("\n\t\t\t# 旅客信息 #");
printf("\n\t\t\t###############################");
printf("\n\t\t\t 旅客姓名:%.22s",ticket[j].user);
printf("\n\t\t\t 性别:%.26s",ticket[j].sex);
printf("\n\t\t\t 单位:%.20s",ticket[j].Inc);
printf("\n\t\t\t 身份证:%.20s",ticket[j].ID);
printf("\n\t\t\t###############################");
printf("\n\t\t\t# 航班信息 #");
printf("\n\t\t\t###############################");
printf("\n\t\t\t 航班:%.26s",flight[i].name);
printf("\n\t\t\t 出发地:%.23s",flight[i].start);
printf("\n\t\t\t 目的地:%.23s",flight[i].destination);
printf("\n\t\t\t 出发时间:%.10s%.12s ",flight[i].date,flight[i].time);
switch(ticket[j].grade)
{
case 0:printf("\n\t\t\t 舱位:头等舱 ");money=flight[i].price[0];break;
case 1:printf("\n\t\t\t 舱位:公务舱 ");money=flight[i].price[1];break;
case 2:printf("\n\t\t\t 舱位:经济舱 ");money=flight[i].price[2];break;
}
printf("\n\t\t\t 应交金额:%d 已交金额:100",money);
printf("\n\t\t\t 欠交金额:%d",money-100);
printf("\n\t\t\t###############################");
printf("\n\t\t请通知旅客在飞机起飞前一天凭取票通知和帐单交款取票");
return 1;
}
}
printf("系统出错!");
return 0;
}
void CheckTicket(Ticket &ticket){ //定票信息检查
while(strlen(ticket.user)<2||strlen(ticket.user)>10||
strlen(ticket.sex)<2||strlen(ticket.sex)>3||
strlen(ticket.Inc)<2||strlen(ticket.Inc)>19||
strlen(ticket.ID)<18||strlen(ticket.ID)>19||
ticket.grade<0||
ticket.grade>2
)