/*****************************************************
* 版权所有(C)2016,王力源
*
*文件名称:A.C 航空售票系统
*文件标识:无
*内容摘要:航空售票系统
*其他说明:无
*当前版本:V1.0
*作者:王力源
*完成日期:2016.12.28
*
******************************************************/
#include
#include
using namespace std;
#include
#include
/*****************************************************
*功能描述:定义客户信息
*输入参数:name,id,line_num,time1,time2,seat_num
*输出参数:client
txt文件
******************************************************/
typedef struct client
{
char name[20];//顾客名
char id[10];//顾客证件号
char line_num[10];//航班号
char time1[10];//起飞时间
char time2[10];//降落时间
int seat_num;//座位号
struct client *next;//下一个结点
} client;
//头结点
typedef struct clienthead
{
int count;
client *next;
} clienthead;
/*****************************************************
*功能描述:定义航班信息
*输入参数:line_num,time1,time2,seat_num,start_place,end_place,total
*输出参数:airline
txt
******************************************************/
typedef struct airline
{
char line_num[10];//航班号
char start_place[20];//起飞地
char end_place[20];//目的地
char time1[10];//起飞时间
char time2[10];//降落时间
int total;//座位总数
int left;//剩余座位
struct airline *next;//下一个结点
} airline;
//头结点
typedef struct airlinehead
{
int count;
airline *next;
} airlinehead;
/*****************************************************
*功能描述:录入航班函数
*输入参数:line_num,start_place,end_place,time1,time2,total,left
*输出参数:第i+1个航班录入
******************************************************/
airlinehead* import(int n,airlinehead *pheadline)//录入航班函数: n为所要录入航班的数量:
{
airline *temp = new airline;
temp->next=NULL;
pheadline->next=temp;
pheadline->count = n;
for(int i=0; i>temp->line_num;
cout<<"请输入第"<>temp->start_place;
cout<<"请输入第"<>temp->end_place;
cout<<"请输入第"<>temp->time1;
cout<<"请输入第"<>temp->time2;
cout<<"请输入第"<>temp->total;
cout<<"本航班的剩余座位数:"<left=temp->total;
cout<<"第"<next = new airline;
if(temp->next == NULL)
{
cout<<"分配内存失败"<next->next=NULL;
temp = temp->next;
}
}
return pheadline;
}
/*****************************************************
*功能描述:查询航班功能
*输入参数:select,1,2
*输出参数:航班号,起飞地,抵达地,起飞时间,降落时间,座位数,剩余座数
*返回值:temp-成功,NULL-失败
******************************************************/
airline* query(airlinehead *phead )//查询航班情况
{
airline *find=NULL;
airline *temp;
cout<<"**********************************"<>select;
cout<>line_num;
temp = phead->next;
while(temp )
{
if(strcmp(temp->line_num,line_num) == 0)
{
find= temp;
//display_line(find);
return temp;
break;
}
else
{
temp = temp->next;
}
}
if(!temp)
{
cout<<"没有找到该航班的信息。"<>start_place;
cout<<"请输入目的地:";
cin>>end_place;
//airline *temp;
temp=phead->next;
while(temp)
{
if(strcmp(temp->start_place,start_place)==0 &&
strcmp(temp->end_place,end_place)==0)
{
find=temp;
//return temp;
break;
}
temp = temp->next;
}
if(!temp)
{
cout<<"没有找到该航班的信息。"<line_num<<"\t\t"
<start_place<<"\t\t"
<end_place<<"\t\t"
<time1<<"\t"
<time2<<"\t"
<total<<"\t"
<left<<"\t"
<next;
if(!node)
{
cout<<"当前没有航班信息"<count<next;
}
}
/******************************************************
*功能描述:修改航班信息
*输入参数:select
*输出参数:无
*返回值:0-正确,1-错误
*******************************************************/
int change_line(airlinehead *headline)//修改航班信息。
{
cout<<"当前所有航班的信息为:"<next;
while(temp)
{
display_line(temp);
t=temp;
temp=temp->next;
}
cout<>select;
cout<3 || select<1)
{
cout<<"输入错误。"<next = (airline*)malloc(sizeof(airline));
temp=new airline;
// temp=temp->next;
cout<<"请输入要增加的航班号: ";
cin>>temp->line_num;
cout<<"请输入航班的起飞地: ";
cin>>temp->start_place;
cout<<"请输入航班的目的地: ";
cin>>temp->end_place;
cout<<"请输入航班的起飞时间:";
cin>>temp->time1;
cout<<"请输入航班的降落时间:";
cin>>temp->time2;
cout<<"请输入航班的座位总数: ";
cin>>temp->total;
t->next=temp;
temp->left=temp->total;
temp->next=NULL;
headline->count++;
cout<<"增加成功。"<>line_num;
airline * delline;
delline = headline->next;
while(delline)
{
if(strcmp(delline->next->line_num, line_num)==0)
{
i=1;
airline *plink;
plink = delline->next->next;
//free(delline->next);
delete delline->next;
delline->next=plink;
headline->count--;
}
delline=delline->next;
}
if(delline == 0&&i!=1)
{
cout<<"没有找到输入的航班号。"<>line_num3;
temp = headline->next;
while(temp)
{
if(strcmp(temp->line_num, line_num3)==0)
{
i=1;
cout<<"请选择要修改的内容??"<next;
}
if(temp==0&&i!=1)
{
cout<<"没有找到输入的航班号。"<name<<"\t\t"
<id<<"\t\t"
<seat_num<<"\t\t"
<time1<<"\t"
<time2<<"\t"
<line_num<<"\t\t"
<next;
if(!node)
{
cout<<"当前没有航班。。";
}
for(; node->left!=node->total; node = node->next)
{
display_line(node);
}
}
/*****************************************************
*功能描述:订票
*输入参数:line_num,id
*输出参数:
*返回值:1-正确,0-错误
******************************************************/
int bookticket(airlinehead * headline,clienthead *headclient)//订票
{
//headclient->count=0;
cout<<"请输入航班号: ";
char line_num[10] ;
cin>>line_num;
airline *temp;
temp=headline->next;
while(temp)
{
if(strcmp(temp->line_num,line_num)==0)
{
break;
}
temp=temp->next;
}
if(!temp)
{
cout<<"未找到该航班"<left==0)
{
cout<<"对不起,该航班票已经售完。"<>custom->id;
cout<>custom->name;
cout<seat_num=temp->total-temp->left+1;
custom->next=NULL;
strcpy(custom->line_num,line_num);
temp->left--;
headclient->count++;
custom->next = headclient->next;
headclient->next = custom;
cout<<"订票成功!祝您旅途愉快~~";
return 1;
}
/*****************************************************
*功能描述:退票
*输入参数:id
*输出参数:
*返回值:1-正确,0-错误
******************************************************/
int returnticket(airlinehead * headline,clienthead *headclient)//退票。
{
cout<<"请输入顾客的证件号码:id: ";
char id[10];
cin>>id;
airline *airlinetemp= headline->next;
client *clienttemp= headclient->next;
if(NULL==airlinetemp)
{
cout<<"当前没有航班信息。"<id,id)==0)//要删除的节点为第一个时。。。
{
strcpy(line_num,clienttemp->line_num);
headclient->next=clienttemp->next;
delete clienttemp;
while(airlinetemp)//修改对票客户所对应的航班的售票信息。
{
if(strcmp(line_num,airlinetemp->line_num)== 0 )
{
airlinetemp->left++;
break;
}
airlinetemp = airlinetemp->next;
}
cout<<"退票成功!希望有机会与您继续合作。";
return 1;
}
while(clienttemp->next)//要删除 的节点不是第一个时。。。
{
if(strcmp(clienttemp->next->id,id)==0)
{
strcpy(line_num,clienttemp->next->line_num);
delnext = clienttemp->next->next;
delete clienttemp->next;
clienttemp->next=delnext;
while(airlinetemp)//修改对票客户所对应的航班的售票信息。
{
if(strcpy(line_num,airlinetemp->line_num)== 0 )
{
airlinetemp->left++;
break;
}
airlinetemp = airlinetemp->next;
}
cout<<"退票成功!有机会继续合作。"<next;
}
cout<<"未找到该客户的信息。"<count<next;
while(linetemp)
{
outline<line_num<<""
<start_place<<""
<end_place<<""
<total<<""
<left<<""
<next;
}
outline.close();
cout<<"航班信息保存成功..."<count<next;
while(clienttemp)
{
outclient<name<<""
<id<<""
<line_num<<""
<seat_num<<""
<next;
}
outclient.close();
cout<<"客户信息保存成功。"<next = NULL;
headclient->next = NULL;
ifstream inair("airline.txt");
if(!inair)
{
cout<<"航班文件不能打开,信息加载失败。。。"<>headline->count;
for(int i = 0; icount; i++)
{
airline *nodeline = new airline;
inair>>nodeline->line_num
>>nodeline->start_place
>>nodeline->end_place
>>nodeline->total
>>nodeline->left;
nodeline->next = headline->next;
headline->next = nodeline;
}
inair.close();
cout<<"航班信息加载完毕"<>headclient->count;
for( i=0; icount; i++)
{
client *nodeline=new client;
inclient>>nodeline->name>>nodeline->id>>nodeline->line_num>>nodeline->seat_num;
nodeline->next=headclient->next;
headclient->next=nodeline;
}
inclient.close();
cout<<"客户信息加载完毕。。。"<count=0;
headline->next=NULL;
clienthead *headclient=new clienthead;
headclient->count=0;
headclient->next=NULL;
while(1)
{
main_menu();
int n;
cout<<"请选择您要进行的操作: ";
cin>>n;
cout<>num;
cout<