大家瞧瞧我的:
#include<iostream.h>
#include<stdio.h>
#include<windows.h>
int count=0;
const MAX=10;
//#include<afxwin.h>
//航班时间
typedef struct
{
int year;
int month;
int day;
int hour;
int minute;
}Time;
//航班信息
typedef struct
{
int num; //航班号
Time time[2];//起降时间
char elem[10];//抵达城市
// char * elem;
int price;//航班票价
float f;//票价折扣
int b;//是否仓满 “1”为满 “0”未满
}PLANE[MAX],SKY;
typedef struct ALL
{
PLANE plane;
int count;
}ALL;
//定票信息
typedef struct PP
{
char name[10];//客户姓名
int ID;//客户ID
int num;//定票数量
SKY plane;//航班情况
//int data;//定单编号
struct PP *next;
}*PASSEGER,PS;
void Input_Plane(ALL &all)
{
//char a[10];
//int n;
bool bb=1;
char c;
for(int i=1;i<=10&&bb;i++)
{
all.count++ ;
cout<<"请输入航班信息:\n";
cout<<"航班号:";
cin>>all.plane[all.count].num;
cout<<"航班票价:";
cin>>all.plane[all.count].price;
cout<<"票价折扣:";
cin>>all.plane[all.count].f;
cout<<"是否仓满:(1为仓满,0为未满)";
cin>>all.plane[all.count].b;
cout<<"起飞时间:";
cin>>all.plane[all.count].time[0].year>>all.plane[all.count].time[0].month>>all.plane[all.count].time[0].day>>all.plane[all.count].time[0].hour>>all.plane[all.count].time[0].minute;
cout<<"降落时间:";
cin>>all.plane[all.count].time[1].year>>all.plane[all.count].time[1].month>>all.plane[all.count].time[1].day>>all.plane[all.count].time[1].hour>>all.plane[all.count].time[1].minute;
cout<<"抵达城市:";
for(int i=0;i<10;i++)
{
cin>>all.plane[all.count].elem[i];
if(all.plane[all.count].elem[i]=='#')
break;
}
cout<<"是否继续录入?(Y/N)";
cin>>c;
if(c=='Y')
bb=1;
else
bb=0;
}
}
void Search(ALL all)
{
int haoma;
int j=0;
cout<<"请输入航班号:";
cin>>haoma;
while(all.plane[j].num!=haoma&&j<10)
j++;
if(all.plane[j].num!=haoma)
cout<<"无此航班!";
else
{
cout<<"您所要查询的航班情况如下:\n";
cout<<"航班票价:";
cout<<all.plane[j].price<<'\n';
cout<<"票价折扣:";
cout<<all.plane[j].f<<'\n';
cout<<"是否仓满:";
if(all.plane[j].b==1)
cout<<"仓满"<<'\n';
else
cout<<"未满"<<'\n';
cout<<"起飞时间:";
cout<<all.plane[j].time[0].year<<"年"<<all.plane[j].time[0].month<<"月"<<all.plane[j].time[0].day<<"日"<<all.plane[j].time[0].hour<<"时"<<all.plane[j].time[0].minute<<"分"<<'\n';
cout<<"降落时间:";
cout<<all.plane[j].time[1].year<<"年"<<all.plane[j].time[1].month<<"月"<<all.plane[j].time[1].day<<"日"<<all.plane[j].time[1].hour<<"时"<<all.plane[j].time[1].minute<<"分"<<'\n';
cout<<"抵达城市:";
for(int i=0;i<10;i++)
{
cout<<all.plane[j].elem[i];
if(all.plane[j].elem[i+1]=='#')
break;
}
}
cout<<'\n';
}
void Modify(ALL &all)
{
int num;
int j=0;
bool bb=1;
char c;
while(bb)
{
cout<<"请输入所要修改航班的航班号:";
cin>>num;
while(all.plane[j].num!=num&&j<10)
j++;
if(all.plane[j].num!=num)
cout<<"无此航班!";
else
{
cout<<"您所要查询的航班情况如下:\n";
cout<<"航班票价:";
cout<<all.plane[j].price<<'\n';
cout<<"票价折扣:";
cout<<all.plane[j].f<<'\n';
cout<<"是否仓满:";
if(all.plane[j].b==1)
cout<<"仓满"<<'\n';
else
cout<<"未满"<<'\n';
cout<<"起飞时间:";
cout<<all.plane[j].time[0].year<<"年"<<all.plane[j].time[0].month<<"月"<<all.plane[j].time[0].day<<"日"<<all.plane[j].time[0].hour<<"时"<<all.plane[j].time[0].minute<<"分"<<'\n';
cout<<"降落时间:";
cout<<all.plane[j].time[1].year<<"年"<<all.plane[j].time[1].month<<"月"<<all.plane[j].time[1].day<<"日"<<all.plane[j].time[1].hour<<"时"<<all.plane[j].time[1].minute<<"分"<<'\n';
cout<<"抵达城市:";
for(int i=0;i<10;i++)
{
cout<<all.plane[j].elem[i];
if(all.plane[j].elem[i+1]=='#')
break;
}
cout<<'\n';
cout<<"航班票价:";
cin>>all.plane[j].price;
cout<<"票价折扣:";
cin>>all.plane[j].f;
cout<<"是否仓满:(1为仓满,0为未满)";
cin>>all.plane[j].b;
cout<<"起飞时间:";
cin>>all.plane[j].time[0].year>>all.plane[j].time[0].month>>all.plane[j].time[0].day>>all.plane[j].time[0].hour>>all.plane[j].time[0].minute;
cout<<"降落时间:";
cin>>all.plane[j].time[1].year>>all.plane[j].time[1].month>>all.plane[j].time[1].day>>all.plane[j].time[1].hour>>all.plane[j].time[1].minute;
cout<<"抵达城市:";
for(i=0;i<10;i++)
{
cin>>all.plane[j].elem[i];
if(all.plane[j].elem[i]=='#')
break;
}
cout<<"是否继续修改?(Y/N)";
cin>>c;
if(c=='Y')
bb=1;
else
bb=0;
}
}
}
void D_Ticket(PASSEGER passeger,ALL &all)
{
bool bb,B,cc=0;
char elem[10];
int num;
PASSEGER p,s;
cout<<"请输入您要前往的地点 :";
for(int i=0;i<10;i++)
{
cin>>elem[i];
if(elem[i]=='#')
break;
}
for(int j=0;j<=all.count;j++)
{
bb=1;
for(i=0;i<10;i++)
{
if(all.plane[j].elem[i]!=elem[i])
{
bb=0;
break;
}
else
bb=1;
}
if(bb)
{
cc=1;
cout<<"您所要查询的地点的信息为:\n";
cout<<"航班号:";
cout<<all.plane[j].num<<'\n';
cout<<"航班票价:";
cout<<all.plane[j].price<<'\n';
cout<<"票价折扣:";
cout<<all.plane[j].f<<'\n';
cout<<"是否仓满:";
if(all.plane[j].b==1)
cout<<"仓满"<<'\n';
else
cout<<"未满"<<'\n';
cout<<"起飞时间:";
cout<<all.plane[j].time[0].year<<"年"<<all.plane[j].time[0].month<<"月"<<all.plane[j].time[0].day<<"日"<<all.plane[j].time[0].hour<<"时"<<all.plane[j].time[0].minute<<"分"<<'\n';
cout<<"降落时间:";
cout<<all.plane[j].time[1].year<<"年"<<all.plane[j].time[1].month<<"月"<<all.plane[j].time[1].day<<"日"<<all.plane[j].time[1].hour<<"时"<<all.plane[j].time[1].minute<<"分"<<'\n';
}
}
if(cc)
{
B=1;
while(B)
{
cout<<"请输入您要定票的航班号:";
cin>>num;
j=0;
while(all.plane[j].num!=num)
j++;
if(all.plane[j].b==1)
cout<<"该机已满,请您重新选择航班!\n";
else
B=0;
}
p=passeger;
while(p->next)
p=p->next;
count++;
s=new PS;
cout<<"请输入姓名:";
for(i=0;i<10;i++)
{
cin>>s->name[i];
if(s->name[i]=='#')
break;
}
cout<<"请输入ID:";
cin>>s->ID;
cout<<"请输入定票的数量:";
cin>>s->num;
s->plane.num=num;
p->next=s;
s->next=NULL;
}
else
cout<<"无通往该地点的航班!";
}
void T_Ticket(PASSEGER passeger)
{
int a;
PASSEGER p,q;
bool bb=1;
cout<<"请输入ID:";
cin>>a;
q=p=passeger;
while(p)
{
if(p->ID==a)
{
bb=0;
break;
}
else
{
q=p;
p=p->next;
}
}
if(bb)
cout<<"该用户无定票情况!\n";
else
{
if(p->next==NULL)
q->next=NULL;
else
{
q->next=p->next;
free(p);
}
count--;
cout<<"退票成功!";
}
}
void save_Plane(ALL &all)
{
FILE *fp;
fp=fopen("plane","w");
fwrite(&all,sizeof(struct ALL),1,fp);
fclose(fp);
}
void save_People(PASSEGER passeger,ALL &all)
{
FILE *fp;
PASSEGER p;
p=passeger->next;
fp=fopen("passeger","w");
fwrite(&count,sizeof(int),1,fp);
while(p)
{
fwrite(p,sizeof(struct PP),1,fp);
p=p->next;
}
fclose(fp);
}
void load_Plane(ALL &all)
{
FILE *fp;
if((fp=fopen("plane","r"))==NULL)
cout<<"Can not open the file plane!\n";
else{
fread(&all,sizeof(struct ALL),1,fp);
fclose(fp);
}
}
void load_People(PASSEGER passeger,ALL &all)
{
FILE *fp;
PASSEGER p,s;
int a;
if((fp=fopen("passeger","r"))==NULL)
{
cout<<"Can not open the file passeger!\n";
}
else
{
p=passeger;
fread(&count,sizeof(int),1,fp);
a=count;
while(count)
{
s=new PS;
fread(s,sizeof(struct PP),1,fp);
p->next=s;
p=s;
count--;
}
count=a;
p->next=NULL;
fclose(fp);
}
}
void Search_People(PASSEGER passeger,ALL &all)
{
PASSEGER p;
bool bb=1;
int num;
cout<<"请输入ID:";
cin>>num;
p=passeger;
while(p)
{
if(p->ID==num)
{
bb=0;
break;
}
p=p->next;
}
if(bb)
cout<<"该用户无定票情况!\n";
else
{
cout<<"姓名:";
for(int i=0;i<10;i++)
{
cout<<p->name[i];
if(p->name[i+1]=='#')
break;
}
cout<<'\n';
cout<<"定票数量:"<<p->num<<'\n';
cout<<"所定航班号:"<<p->plane.num<<'\n';
}
}
void main()
{
ALL all;
PASSEGER passeger;
passeger=new PS;
passeger->next=NULL;
all.count=0;
bool b;
int a;
char c;
b=1;
load_Plane(all);
load_People(passeger,all);
while(b)
{
cout<<"********************************************\n";
cout<<" 1.录入 2.查询 3.定票 \n";
cout<<" 4.退票 5.修改 6.查询定票纪录\n";
cout<<"********************************************\n";
cout<<"请选择:";
cin>>a;
switch (a)
{
case 1:Input_Plane(all);break;
case 2:Search(all);break;
case 3:D_Ticket(passeger,all);break;
case 4:T_Ticket(passeger);break;
case 5:Modify(all);break;
case 6:Search_People(passeger,all);break;
}
cout<<"是否继续?(Y/N)";
cin>>c;
if(c=='Y')
b=1;
else
{
b=0;
save_Plane(all);
save_People(passeger,all);
exit(0);
}
}
}