注册 登录  
 加关注
   显示下一条  |  关闭
温馨提示!由于新浪微博认证机制调整,您的新浪微博帐号绑定已过期,请重新绑定!立即重新绑定新浪微博》  |  关闭

告别迷茫

梦想与现实的差距,就是我们生活的意义。因为我们有差距,我们才会一直积累,在努力。

 
 
 

日志

 
 

短学期 飞机票管理系统----  

2014-09-20 14:21:51|  分类: 短学期程序实践 |  标签: |举报 |字号 订阅

  下载LOFTER 我的照片书  |

#include<stdio.h>
#include<string.h>
#include<stdlib.h>

/*
航班信息:航班号,飞机号,目的地,订票数,余票数
客户信息:姓名,身份证号 航班号,座位号(初始为0)

需要完成的主要功能:
1.航班信息的添加及初始化
2.客户信息的添加
3.订票
4.退票
5.航班和客户信息的更新(添加,删除,修改)
6.输出所有航线和客户的信息
7.航班和客户信息的查询(按不同的方式查询)
8.航班和客户信息的相关统计
*/
struct Flight
{
char FlightNum[20];//航班号,
char PlaneNum[20];//飞机号,
char Destination[50];//目的地,
int TicketNum;//订票数,
int RemainNum;//余票数
}Flightin[200];
struct Custom
{
char Name[20];//姓名,
char ID[20];//身份证号,
char FlightNum[20];//航班号,
int SeatNum;//座位号
}Customin[200];
void AddFlight()
{
FILE *fp;
if((fp=fopen("flight.txt","r") )==NULL)
{
printf("打开文件失败\n");
}
int n=0,i;
int b;
printf("请输入你要增加几个航班的信息:\n");
scanf("%d",&b);
while(!feof(fp))
{
fread(&Flightin[n],sizeof(struct Flight),1,fp);
n++;
}
fclose(fp);

if(n==1)
{
fp=fopen("flight.txt","w");

for(i=0;i<b;i++)
{

printf("请输入航班号:");
scanf("%s",Flightin[i].FlightNum);
printf("请输入飞机号:");
scanf("%s",Flightin[i].PlaneNum);
printf("请输入目的地:");
scanf("%s",Flightin[i].Destination);
printf("请输入订票数:");
scanf("%d",&Flightin[i].TicketNum);
printf("请输入余票数:");
scanf("%d%*c",&Flightin[i].RemainNum);
fwrite(&Flightin[i],sizeof(struct Flight),1,fp);
}
fclose(fp);
system("pause");
return;

}
else
{
fp=fopen("flight.txt","a+");
for(i=n-1;i<b+n-1;i++)
{
printf("请输入航班号:");
scanf("%s",Flightin[i].FlightNum);
printf("请输入飞机号:");
scanf("%s",Flightin[i].PlaneNum);
printf("请输入目的地:");
scanf("%s",Flightin[i].Destination);
printf("请输入订票数:");
scanf("%d",&Flightin[i].TicketNum);
printf("请输入余票数:");
scanf("%d",&Flightin[i].RemainNum);
fwrite(&Flightin[i],sizeof(struct Flight),1,fp);
}
fclose(fp);
system("pause");
return;

}
}
void Addcustom()
{
FILE *fp;
int n=0,i;
int b;
if((fp=fopen("custom.txt","r"))==NULL)
{
printf("增加顾客的信息的时候打开失败\n");
fclose(fp);
system("pause");
return;
}
printf("你要增加几个客户的信息:\n");
scanf("%d",&b);
while(!feof(fp))
{
fread(&Customin[n],sizeof(struct Custom),1,fp);
n++;
}
fclose(fp);

if(n==1)
{
fp=fopen("custom.txt","w");
for(i=0;i<b;i++)
{

printf("请输入客户姓名:");
scanf("%s",Customin[i].Name);
printf("请输入客户省份证号:");
scanf("%s",Customin[i].ID);
printf("请输入客户航班号:");
scanf("%s",Customin[i].FlightNum);
printf("请输入客户座位号:");
scanf("%d%*c",&Customin[i].SeatNum);
fwrite(&Customin[i],sizeof(struct Custom),1,fp);
}
fclose(fp);
system("pause");
return ;

}
else
{
fp=fopen("custom.txt","a+");
for(i=n-1;i<b+n-1;i++)
{
printf("请输入客户姓名:");
scanf("%s",Customin[i].Name);
printf("请输入客户省份证号:");
scanf("%s",Customin[i].ID);
printf("请输入客户航班号:");
scanf("%s",Customin[i].FlightNum);
printf("请输入客户座位号:");
scanf("%d%*c",&Customin[i].SeatNum);
fwrite(&Customin[i],sizeof(struct Custom),1,fp);
}
fclose(fp);
system("pause");
return ;
}

}
void Addticket()
{
FILE *fp,*fp1;
int i;
char feiji[20];
int b=0,flag;
if(((fp=fopen("flight.txt","r"))==NULL))
{
printf("打开文件错误,在定机票的时候\n");//姓名,身份证号 航班号,座位号
fclose(fp);
system("pause");
return;
}
printf("请输入你需要订的航班:\n");
scanf("%s",feiji);
int biaoji=0;
for(i=0;fread(&Flightin[i],sizeof( struct Flight),1,fp)!=NULL;i++)
{
if(strcmp(Flightin[i].FlightNum,feiji)==0&&biaoji==0)
{
if(Flightin[i].RemainNum!=0)
{
biaoji=1;
fclose(fp);
flag=i;
fp=fopen("custom.txt","r");
while(!feof(fp))
{
fread(&Customin[i],sizeof(struct Custom),1,fp);
b++;
}
fclose(fp);
if(b==1)
{
fp=fopen("custom.txt","w");
}
else
{
fp=fopen("custom.txt","a+");
}
printf("请输入乘机人的姓名:\n");
scanf("%s",Customin[b-1].Name);
printf("请输入乘机人的身份证号码:\n");
scanf("%s",Customin[b-1].ID);
// printf("请输入你需要订的航班:\n");
// scanf("%s",Customin[b-1].FlightNum);
strcpy(Customin[b-1].FlightNum,Flightin[i].FlightNum);
printf("请输入乘机人的座位号:\n");
scanf("%d",&Customin[b-1].SeatNum);
fwrite(&Customin[b-1],sizeof(struct Custom),1,fp);
fclose(fp);
fp=fopen("flight.txt","r");
fp1=fopen("flight1.txt","w");
for(i=0;fread(&Flightin[i],sizeof(struct Flight),1,fp)!=NULL;i++)
{
if(i==flag)
{
Flightin[i].RemainNum--;
Flightin[i].TicketNum++;
fwrite(&Flightin[i],sizeof(struct Flight),1,fp1);
continue;
}
fwrite(&Flightin[i],sizeof(struct Flight),1,fp1);
}
fclose(fp);
fclose(fp1);
fp=fopen("flight.txt","w");
fp1=fopen("flight1.txt","r");
for(i=0;fread(&Flightin[i],sizeof(struct Flight),1,fp1)!=NULL;i++)
{
fwrite(&Flightin[i],sizeof(struct Flight),1,fp);
}
fclose(fp);
fclose(fp1);
fp=fopen("flight1.txt","w");
fclose(fp);
printf("定票成功!\n");
system("pause");
return;
}
printf("此航班的余票已经为0了,买另外的吧!\n");
system("pause");
return;
}


}
printf("你查寻的航班不存在!\n");
system("pause");
return;
}

void tuipiao()
{
FILE *fp,*fp1;
int i;
char feiji[20];
int b=0,flag;
if((fp=fopen("custom.txt","r"))==NULL)
{
printf("打开文件错误,在定机票的时候\n");//姓名,身份证号 航班号,座位号
}
printf("请输入你需要退订的航班:\n");
scanf("%s",feiji);
for(i=0;fread(&Customin[i],sizeof( struct Custom),1,fp)!=NULL;i++)
{
if(strcmp(Customin[i].FlightNum,feiji)==0)
{
fclose(fp);
flag=i;
fp=fopen("custom.txt","r");
fp1=fopen("flight1.txt","w");/*修改客户的储存的信息*/
for(i=0;fread(&Customin[i],sizeof(struct Custom),1,fp)!=NULL;i++)
{
if(i!=flag)
{
fread(&Customin[i],sizeof(struct Custom),1,fp1);
}
}
fclose(fp);
fclose(fp1);
fp=fopen("custom.txt","w");
fp1=fopen("flight1.txt","r");
for(i=0;fread(&Customin[i],sizeof(struct Custom),1,fp1)!=NULL;i++)
{
fread(&Customin[i],sizeof(struct Custom),1,fp);
}
fclose(fp);
fclose(fp1);


/*修改飞机储存的信息*/
fp=fopen("flight.txt","r");
fp1=fopen("flight1.txt","w");
for(i=0;fread(&Flightin[i],sizeof(struct Flight),1,fp)!=NULL;i++)
{
if(i==flag)
{
Flightin[i].RemainNum++;
Flightin[i].TicketNum--;
fwrite(&Flightin[i],sizeof(struct Flight),1,fp1);
continue;
}
fwrite(&Flightin[i],sizeof(struct Flight),1,fp1);
}
fclose(fp);
fclose(fp1);
fp=fopen("flight.txt","w");
fp1=fopen("flight1.txt","r");
for(i=0;fread(&Flightin[i],sizeof(struct Flight),1,fp1)!=NULL;i++)
{
fwrite(&Flightin[i],sizeof(struct Flight),1,fp);
}
fclose(fp);
fclose(fp1);
fp=fopen("flight1.txt","w");
fclose(fp);
printf("退票成功!\n");
system("pause");
return;
}

}
printf("你想退票的航班不存在!\n");
system("pause");
return;
}

void Flightmodify()
{
char hangban[30];
printf("请输入你要修改的航班:\n");
scanf("%s",hangban);
FILE *fp,*fp1;
if((fp=fopen("flight.txt","r"))==NULL)
{
printf("你要修改的航班打开文件失败\n") ;
}
int i;
int biaoji=0;
int flag=0;
fp1=fopen("fight1.txt","w");
for(i=0;fread(&Flightin[i],sizeof(struct Flight),1,fp)!=NULL;i++)
{
if(strcmp(Flightin[i].FlightNum ,hangban)==0&&flag==0)
{
biaoji=1;
flag=1;
printf("如下是你将修改的航班的基本信息:\n");
printf("航班号 飞机号 目的地 订票数 余票数\n");
printf("%-15s%-15s%-15s%-15d%d\n",Flightin[i].FlightNum,Flightin[i].PlaneNum,Flightin[i].Destination,Flightin[i].TicketNum,Flightin[i].RemainNum);
printf("下面开始修改\n\n");
printf("航班:\n");
scanf("%s",Flightin[i].FlightNum);
printf("目的地:\n");
scanf("%s",Flightin[i].Destination);
printf("飞机号:\n");
scanf("%s",Flightin[i].PlaneNum);
printf("定票数:\n");
scanf("%d",&Flightin[i].TicketNum);
printf("余票数:\n");
scanf("%d",&Flightin[i].RemainNum);
fp1=fopen("flight1.txt","w");
fwrite(&Flightin[i],sizeof(struct Flight),1,fp1);
continue;
}
fwrite(&Flightin[i],sizeof(struct Flight),1,fp1);
}
fclose(fp);
fclose(fp1);
if(biaoji==0)
{
printf("你要修改的航班不存在\n");
system("pause");
return;
}
fp=fopen("flight.txt","w");
fp1=fopen("flight1.txt","r");
for(i=0;fread(&Flightin[i],sizeof(struct Flight),1,fp1)!=NULL;i++)
{
fwrite(&Flightin[i],sizeof(struct Flight),1,fp);
}
fclose(fp);
fclose(fp1);
fp=fopen("flight1.txt","w");
fclose(fp);
printf("修改成功!\n");
system("pause");
return;

}



void DelCustom()
{
FILE *fp,*fp1,*fp2,*fp3;
char name[20];
int i;
int flag=0;
int x;
printf("请你输入需要删除的客户姓名:\n") ;
scanf("%s",name);
if((fp=fopen("custom.txt","r"))==NULL)
{
printf("打开文件失败\n");
system("pause");
return;
}
fp3=fopen("flight2.txt","w") ;
for(i=0;fread(&Customin[i],sizeof(struct Custom),1,fp)!=NULL;i++)
{
if(strcmp(name,Customin[i].Name)==0)
{
printf("你需要删除的客户存在,可以删除\n");
flag=1;
if((fp1=fopen("flight.txt","r"))==NULL)
{
printf("打开失败\n");
system("pause");
return;
}
fp2=fopen("flight1.txt","w");
for(x=0;fread(&Flightin[x],sizeof(struct Flight),1,fp1)!=NULL;x++)
{
if(strcmp(Flightin[x].FlightNum,Customin[i].FlightNum)==0)
{
Flightin[x].RemainNum++;
Flightin[x].TicketNum--;
fwrite(&Flightin[x],sizeof(struct Flight),1,fp2);
continue;
}
fwrite(&Flightin[x],sizeof(struct Flight),1,fp2);
}
fclose(fp2);
fclose(fp1);
fp1=fopen("flight.txt","w");
fp2=fopen("flight1.txt","r");
for(x=0;fread(&Flightin[x],sizeof(struct Flight),1,fp2)!=NULL;x++)
{
fwrite(&Flightin[x],sizeof(struct Flight),1,fp1);
}
fclose(fp2);
fclose(fp1);
fp1=fopen("flight1.txt","w");
fclose(fp1);
continue;

}
fwrite(&Customin[i],sizeof(struct Custom),1,fp3);
}
fclose(fp3);
fclose(fp);
if(flag==0)
{
printf("你需要删除的客户不存在\n");
system("pause");
return;
}
fp=fopen("custom.txt","w");
fp1=fopen("flight2.txt","r");
for(i=0;fread(&Customin[i],sizeof(struct Custom),1,fp1)!=NULL;i++)
{
fwrite(&Customin[i],sizeof(struct Custom),1,fp);
}
fclose(fp);
fclose(fp1);
fp=fopen("flight2.txt","w");
fclose(fp);
printf("删除客户成功!\n");
system("pause");
return;
}
void DelFlight()
{
printf("请输入你要删除的航班的信息\n\n") ;
printf("航班:\n");
char hangban[30];
scanf("%s",hangban);
FILE *fp,*fp1,*fp2;
fp=fopen("flight.txt","r");
fp1=fopen("flight1.txt","w");
int b;
int flag=0;
int biaoji=0;
int i;
for(b=0;fread(&Flightin[b].FlightNum,sizeof(struct Flight),1,fp)!=NULL;b++)
{
if(strcmp(Flightin[b].FlightNum,hangban)==0&&biaoji==0)/*biaoji主要是用于不要删除相同的航班号*/
{
fp2=fopen("custom.txt","r");
for(i=0;fread(&Customin[i],sizeof(struct Custom),1,fp2)!=NULL;i++)
{
if(strcmp(Customin[i].FlightNum,hangban)==0)
{
printf("你要删除的航班存在旅客,不能删除\n");
system("pause");
return;
}
}
printf("你需要删除的航班找到:\n");
flag=1;
biaoji=1;
continue;
}
fwrite(&Flightin[b],sizeof(struct Flight),1,fp1);
}
fclose(fp);
fclose(fp1);
if(flag==0)
{
printf("你需要删除的航班不存在\n");
system("pause");
return;
}
fp=fopen("flight.txt","w");
fp1=fopen("flight1.txt","r");
for(i=0;fread(&Flightin[i],sizeof(struct Flight),1,fp1)!=NULL;i++)
{
fwrite(&Flightin[i],sizeof(struct Flight),1,fp);
}
fclose(fp);
fclose(fp1);
fp=fopen("flight1.txt","w");
fclose(fp);
printf("删除成功\n");
system("pause");
return;

}

void ChaCustomByname()
{
FILE *fp;
char hello[20];
printf("请输入你要查询的客户的名字:\n");
scanf("%s",hello);
if((fp=fopen("custom.txt","r"))==NULL)
{
printf("你打开文件失败\n") ;
}
int i;
for(i=0;fread(&Customin[i],sizeof(struct Custom),1,fp)!=NULL;i++)
{
if(strcmp(Customin[i].Name ,hello)==0)
{
printf("如下是顾客的基本信息:\n");
printf("姓名 身份证号 航班号 座位号\n");
printf("%-15s%-15s%-15s%-15d\n",Customin[i].Name,Customin[i].ID,Customin[i].FlightNum,Customin[i].SeatNum);
fclose(fp);
system("pause");
return;
}
}
printf("没有你要查询的顾客的信息\n");
fclose(fp);
system("pause");
return;
}
void ChaCustomById()
{
FILE *fp;
char hello[20];
printf("请输入你要查询的客户的ID:\n");
scanf("%s",hello);
if((fp=fopen("custom.txt","r"))==NULL)
{
printf("你打开文件失败\n") ;
}
int i;
for(i=0;fread(&Customin[i],sizeof(struct Custom),1,fp)!=NULL;i++)
{
if(strcmp(Customin[i].ID ,hello)==0)
{
printf("如下是顾客的基本信息:\n");
printf("姓名 身份证号 航班号 座位号\n");
printf("%-15s%-15s%-15s%-15d\n",Customin[i].Name,Customin[i].ID,Customin[i].FlightNum,Customin[i].SeatNum);
fclose(fp);
system("pause");
return;
}
}
printf("没有你要查询的顾客的ID信息\n");
fclose(fp);
system("pause");
return;

}
void ChaFlightByFlight()
{
FILE *fp;
fp=fopen("flight.txt","r");
int i;
char hello[20];
printf("输入你要查询的航班号:\n");
scanf("%s",hello);
for(i=0;fread(&Flightin[i],sizeof(struct Flight),1,fp)!=NULL;i++)
{
if(strcmp(hello,Flightin[i].FlightNum)==0)
{
printf("你查询的航班的信息如下:\n");
printf(" 姓名 身份证号 航班号 座位号\n");
printf("%-15s%-15s%-15s%-15d\n",Customin[i].Name,Customin[i].ID,Customin[i].FlightNum,Customin[i].SeatNum);
fclose(fp);
system("pause");
return;
}
}
printf("没有你要查找的航班\n");
fclose(fp);
system("pause");
return;

}
void ChaFlightByPlane()/*通过飞机号查询*/
{
FILE *fp;
fp=fopen("flight.txt","r");
int i;
char hello[20];
printf("输入你要查询的飞机号:\n");
scanf("%s",hello);
for(i=0;fread(&Flightin[i],sizeof(struct Flight),1,fp)!=NULL;i++)
{
if(strcmp(hello,Flightin[i].PlaneNum)==0)
{
printf("你查询的飞机的信息如下:\n");
printf(" 姓名 身份证号 航班号 座位号\n");
printf("%-15s%-15s%-15s%-15d\n",Customin[i].Name,Customin[i].ID,Customin[i].FlightNum,Customin[i].SeatNum);
fclose(fp);
system("pause");
return;
}
}
printf("没有你要查找的飞机\n");
fclose(fp);
system("pause");
return;
}
void ChaFlightByDestination()
{
FILE *fp;
fp=fopen("flight.txt","r");
int i;
char hello[20];
printf("输入你要查询的目的地:\n");
scanf("%s",hello);
for(i=0;fread(&Flightin[i],sizeof(struct Flight),1,fp)!=NULL;i++)
{
if(strcmp(hello,Flightin[i].Destination)==0)
{
printf("你查询的目的地所有的机票的信息如下:\n");
printf("姓名 身份证号 航班号 座位号\n");
printf("%-15s%-15s%-15s%-15d\n",Customin[i].Name,Customin[i].ID,Customin[i].FlightNum,Customin[i].SeatNum);
fclose(fp);
system("pause");
return;
}
}
printf("没有你要去的目的地的飞机票\n");
fclose(fp);
system("pause");
return;

}
void OutFlight()/*输出所有航线*/
{
FILE *fp;
int n=0;
if((fp=fopen("flight.txt","r"))==NULL)
{
printf("打开文件失败\n");
fclose(fp);
return;
}
fread(&Flightin[n],sizeof(struct Flight),1,fp);
while(feof(fp))
{
printf("没有航班的信息\n");
fclose(fp);
system("pause");
return;
}
fclose(fp);
fp=fopen("flight.txt","r");
int i;
printf("全部的航班信息如下:\n");
for(i=0;fread(&Flightin[i],sizeof(struct Flight),1,fp)!=NULL;i++)
{


printf("航班号 飞机号 目的地 订票数 余票数\n");
printf("%-15s%-15s%-15s%-15d%d\n",Flightin[i].FlightNum,Flightin[i].PlaneNum,Flightin[i].Destination,Flightin[i].TicketNum,Flightin[i].RemainNum);
}
printf("一共有%d航班:\n",i);
fclose(fp);
system("pause");
return;

}
void OutCustom()/*输出所有客户的信息*/
{
FILE *fp;
int n=0;
if((fp=fopen("custom.txt","r"))==NULL)
{
printf("打开文件失败\n");
fclose(fp);
return;
}
fread(&Customin[n],sizeof(struct Custom),1,fp);
while(feof(fp))
{
n++;
printf("没有顾客的信息\n");
fclose(fp);
system("pause");
return;
}

fclose(fp);
fp=fopen("custom.txt","r");
int i;
printf("全部的客户信息如下:\n");
for(i=0;fread(&Customin[i],sizeof(struct Custom),1,fp)!=NULL;i++)
{

printf("姓名 身份证号 航班号 座位号\n");
printf("%-15s%-15s%-15s%-15d\n",Customin[i].Name,Customin[i].ID,Customin[i].FlightNum,Customin[i].SeatNum);
}
printf("一共有%d个客户的信息:\n",i);
fclose(fp);
system("pause");
return;

}


void chaall()/**/
{
char ww;
do
{
system("cls");
printf("*******************************\n");
printf("*=========信息查询============*\n");
printf("* 1:输出所有的顾客信息 *\n");
printf("* 2:输出所有的航班信息   *\n");
printf("* 0:返回          *\n");
printf("* 请输入0-2 其他输入非法  *\n");
printf("*******************************\n");
scanf("%s",&ww);
switch(ww)
{
case '1':OutCustom();break;
case '2':OutFlight();break;
case '0':break;
default:printf("输入错误,重新输入\n");
break;
system("pause");
}
}while(ww!='0');
return;
}
void chapartbyflight()/**/
{
char ww;
do
{ system("cls");
printf("*******************************\n");
printf("*=========信息查询============*\n");
printf("* 1:飞机号查询 *\n");
printf("* 2:航班号查询     *\n");
printf("* 0:目的地查询      *\n");
printf("* 请输入0-2 其他输入非法  *\n");
printf("*******************************\n");
scanf("%s",&ww);
switch(ww)
{
case '1': ChaFlightByPlane();break;
case '2':ChaFlightByFlight();break;
case '3':ChaFlightByDestination();break;
case '0':break;
default:printf("输入错误,重新输入\n");
break;
}
}while(ww!='0');
system("pause");
return;
}

void chapartbycustom()/**/
{
char ww;
do
{
system("cls");
printf("******************************");
printf("*=========信息查询============*\n");
printf("* 1:姓名 查询 *\n");
printf("* 2:身份证号查询    *\n");
printf("* 0:返回        *\n");
printf("* 请输入0-2其他输入非法 *\n");
printf("*******************************\n") ;
scanf("%s",&ww);
switch(ww)
{
case '1':ChaCustomByname();break;
case '2':ChaCustomById();break;
case '0':break;
default:printf("输入错误,重新输入\n");
break;
}
}while(ww!='0');
return;
}

void chapart()/**/
{
char ww;
do
{
system("cls");
printf("******************************");
printf("*=========信息查询============*\n");
printf("* 1:单个顾客查询 *\n");
printf("* 2:单个航班查询    *\n");
printf("* 0:返回        *\n");
printf("*请输入0-2 其他输入非法   *\n");
printf("*******************************\n") ;
scanf("%s",&ww);
switch(ww)
{
case '1':chapartbycustom();break;
case '2':chapartbyflight();break;
case '0':break;
default:printf("输入错误,重新输入\n");
break;
}
}while(ww!='0');
return;
}
void Custommodifybyseat()
{
printf("请输入你要修改的顾客信息:\n");
char guke[30];
scanf("%s",guke);
FILE *fp,*fp1;
int flag=0;
int bijiao=0;
if((fp=fopen("custom.txt","r"))==NULL)
{
printf("你要修改的航班打开文件失败\n") ;
}
int i;
int n=0;
while(!feof(fp))
{
fread(&Customin[n],sizeof(struct Custom),1,fp);
n++;
}
fp1=fopen("flight1.txt","w");
for(i=0;i<n-1;i++)
{
if(strcmp(Customin[i].Name ,guke)==0&&flag==0)
{
bijiao=1;
printf("如下是你将修改的顾客的基本信息:\n");
printf("姓名 身份证号 航班号 座位号\n");
printf("%-15s%-15s%-15s%-15d\n",Customin[i].Name,Customin[i].ID,Customin[i].FlightNum,Customin[i].SeatNum);
printf("输入你修改后的座位号:\n");
scanf("%d",&Customin[i].SeatNum);
flag=1;
fwrite(&Customin[i],sizeof(struct Custom),1,fp1);
printf("修改成功!\n");
continue;

}
fwrite(&Customin[i],sizeof(struct Custom),1,fp1);
}
fclose(fp);
fclose(fp1);
if(bijiao==0)
{
printf("你需要的客户不存在\n");
system("pause");
return;
}
fp=fopen("custom.txt","w");
fp1=fopen("flight1.txt","r");
for(i=0;fread(&Customin[i],sizeof(struct Custom),1,fp1)!=NULL;i++)
{
fwrite(&Customin[i],sizeof(struct Custom),1,fp);
}
fclose(fp);
fclose(fp1);
fp1=fopen("flight1","w");
fclose(fp1);
system("pause");
return;
}

void Custommodifybyflight()
{
printf("请输入你要修改的顾客信息:\n");
char guke[30];
scanf("%s",guke);
FILE *fp,*fp1,*fp2;
int bijiao1=0;
int bijiao2=0;
int b;
if((fp=fopen("custom.txt","r"))==NULL)
{
printf("你要修改的航班打开文件失败\n") ;
}
int i;
int n=0;
while(!feof(fp))
{
fread(&Customin[n],sizeof(struct Custom),1,fp);
n++;
}
fclose(fp);
int flag=0;
fp1=fopen("flight1.txt","w");
fp2=fopen("flight2.txt","w");
for(i=0;i<n-1;i++)
{
if(strcmp(Customin[i].Name ,guke)==0&&bijiao1==0)
{
bijiao1=1;
flag=i;
printf("如下是你将修改的顾客的基本信息:\n");
printf("姓名 身份证号 航班号 座位号\n");
printf("%-15s%-15s%-15s%-15d\n",Customin[i].Name,Customin[i].ID,Customin[i].FlightNum,Customin[i].SeatNum);
printf("输入你修改后的航班号:\n");
scanf("%s",Customin[i].FlightNum);
fp=fopen("flight.txt","r");
int x=0;
while(!feof(fp))
{
fread(&Flightin[x].FlightNum,sizeof(struct Flight),1,fp);
x++;
}
for(b=0;b<x-1;b++)
{
if(strcmp(Flightin[b].FlightNum,Customin[i].FlightNum)==0&&bijiao2==0)
{
bijiao2=1;
if(Flightin[b].RemainNum!=0)
{

Flightin[b].RemainNum--;
Flightin[b].TicketNum++;
fwrite(&Flightin[b],sizeof(struct Flight),1,fp1);
fwrite(&Customin[i],sizeof(struct Custom),1,fp2);
printf("修改成功!\n");
}
else
{
printf("此航班的余票不足,不可以修改\n");
system("pause");
return;
}
continue;

}
fwrite(&Flightin[b],sizeof(struct Flight),1,fp1);
}
fclose(fp);
fclose(fp1);
if(bijiao2==0)
{
printf("没有找到你即将修改后的航班\n");
system("pause");
return;
}
fp=fopen("flight.txt","w");
fp1=fopen("flight1.txt","r");
for(b=0;fread(&Flightin[b],sizeof(struct Flight),1,fp1)!=NULL;b++)
{
fwrite(&Flightin[b],sizeof(struct Flight),1,fp);
}
fclose(fp1);
fclose(fp);
continue;
}
fwrite(&Customin[i],sizeof(struct Custom),1,fp2);
}
fclose(fp2);
if(bijiao1==0)
{
printf("没有你需要修改的客户\n");
system("pause");
return;
}
fp=fopen("custom.txt","w");
fp1=fopen("flight2.txt","r");
for(b=0;fread(&Customin[b],sizeof(struct Custom),1,fp1)!=NULL;b++)
{
fwrite(&Customin[b],sizeof(struct Custom),1,fp);
}
fclose(fp1);
fclose(fp);
fp=fopen("flight.txt","r");
fp1=fopen("flight1.txt","w");
for(b=0;fread(&Flightin[b],sizeof(struct Flight),1,fp)!=NULL;b++)
{
if(b==flag)
{
Flightin[b].RemainNum++;
Flightin[b].TicketNum--;
fwrite(&Flightin[b],sizeof(struct Flight),1,fp1);
continue;
}
fwrite(&Flightin[b],sizeof(struct Flight),1,fp1);
}
fclose(fp);
fclose(fp1);
fp=fopen("flight.txt","w");
fp1=fopen("flight1.txt","r");
for(b=0;fread(&Flightin[b],sizeof(struct Flight),1,fp1)!=NULL;b++)
{

fwrite(&Flightin[b],sizeof(struct Flight),1,fp);
}
fclose(fp);
fclose(fp1);
fp=fopen("flight1.txt","w");
fp1=fopen("flight2.txt","w");
fclose(fp);
fclose(fp1);
system("pause");
return;
}

void Cmodify()/**/
{
char ww;
do
{ system("cls");
printf("*******************************\n");
printf("*=========信息查询============*\n");
printf("* 1:顾客座位修改 *\n");
printf("* 2:顾客航班修改    *\n");
printf("* 请输入0-2其他输入非法 *\n");
printf("*******************************\n");
scanf("%s",&ww);
switch(ww)
{
case '1':Custommodifybyseat();break;
case '2':Custommodifybyflight();break;
case '0':break;
default:printf("输入错误,重新输入\n");
break;
}
}while(ww!='0');
return;
}
void CandFNew()/**/
{
char ww;
do
{ system("cls");
printf("*******************************\n");
printf("*=========信息查询============*\n");
printf("* 1:顾客信息修改 *\n");
printf("* 2:航班信息修改   *\n");
printf("* 3:顾客信息删除    *\n");
printf("* 4:航班信息删除    *\n");
printf("*请输入0-4 其他输入非法   *\n");
printf("*******************************\n");
scanf("%s",&ww);
switch(ww)
{
case '1':Cmodify();break;
case '2':Flightmodify();break;
case '3':DelCustom();break;
case '4':DelFlight();break;
case '0':break;
default:printf("输入错误,重新输入\n");
break;
}
}while(ww!='0');
return;
}

void tongjiflightbydestination()
{
int a[300];
memset(&a,-1,sizeof(a));
FILE *fp;
if((fp=fopen("flight.txt","r"))==NULL)
{
printf("打开文件失败\n");
return;
}
int i;
int j;
int flag;
int n=0;
while(!feof(fp))
{
fread(&Flightin[n],sizeof(struct Flight),1,fp);
n++;
}
for(i=0;i<n-1;i++)
{
if(a[i]!=-1)
{
continue;
}
flag=0;
for(j=i+1;j<n;j++)
{
if(strcmp(Flightin[j].Destination,Flightin[i].Destination)==0)
{
a[j]=0;
if(flag==0)
{
printf("输出目的地为%s的所有的航班:\n",Flightin[i].Destination);
flag=1;
printf("航班号 飞机号 目的地 订票数 余票数\n");
printf("%-15s%-15s%-15s%-15d%d\n",Flightin[i].FlightNum,Flightin[i].PlaneNum,Flightin[i].Destination,Flightin[i].TicketNum,Flightin[i].RemainNum);
}
printf("%-15s%-15s%-15s%-15d%d\n",Flightin[j].FlightNum,Flightin[j].PlaneNum,Flightin[j].Destination,Flightin[j].TicketNum,Flightin[j].RemainNum);


}
}
if(flag==0)
{
printf("目的地为:%s只有一个航班!\n如下\n",Flightin[i].Destination);
printf("航班号 飞机号 目的地 订票数 余票数\n");
printf("%-15s%-15s%-15s%-15d%d\n",Flightin[i].FlightNum,Flightin[i].PlaneNum,Flightin[i].Destination,Flightin[i].TicketNum,Flightin[i].RemainNum);
}

}
fclose(fp);
system("pause");
}
void tongjiflightbyflight()
{
int a[300];
memset(&a,-1,sizeof(a));
FILE *fp;
if((fp=fopen("flight.txt","r"))==NULL)
{
printf("打开文件失败\n");
return;
}
int i,j;
int flag;
int n=0;
while(!feof(fp))
{
fread(&Flightin[n],sizeof(struct Flight),1,fp);
n++;
}
for(i=0;i<n-1;i++)
{
if(a[i]!=-1)
{
continue;
}
flag=0;
for(j=i+1;j<n;j++)
{
if(strcmp(Flightin[j].FlightNum,Flightin[i].FlightNum)==0)
{
a[j]=0;
if(flag==0)
{
printf("输出所有相同的航班号:%s\n",Flightin[i].FlightNum);
flag=1;
printf("航班号 飞机号 目的地 订票数 余票数\n");
printf("%-15s%-15s%-15s%-15d%d\n",Flightin[i].FlightNum,Flightin[i].PlaneNum,Flightin[i].Destination,Flightin[i].TicketNum,Flightin[i].RemainNum);
}
printf("%-15s%-15s%-15s%-15d%d\n",Flightin[j].FlightNum,Flightin[j].PlaneNum,Flightin[j].Destination,Flightin[j].TicketNum,Flightin[j].RemainNum);
}
}
if(flag==0)
{
printf("航班号为:%s只有一个航班!\n如下\n",Flightin[i].FlightNum);
printf("航班号 机号 目的地 订票数 余票数\n");
printf("%-15s%-15s%-15s%-15d%d\n",Flightin[i].FlightNum,Flightin[i].PlaneNum,Flightin[i].Destination,Flightin[i].TicketNum,Flightin[i].RemainNum);

}

}
fclose(fp);
system("pause");
}
void tongjiflight()
{
char ww;
do
{
system("cls");
puts("******************************");
puts("*==========显示信息==========*");
puts("* 1、相同目的地统计 *");
puts("* 2、相同航班统计 *");
puts("* 0、退出 *");
puts("* 请输入0--2,其他输入非法*");
puts("******************************");
printf("请输入你的选择:\n");
scanf("%s",&ww);
switch(ww)
{
case '1':tongjiflightbydestination();break;
case '2':tongjiflightbyflight();break;
case '0':break;
default:printf("无此操作\n");
break;
}
// Sleep(300000000000000);
}while(ww!='0');
//Sleep(300000000000000);
return;
}
void tongjiCustom()
{
int a[300];
memset(&a,-1,sizeof(a));
FILE *fp;
if((fp=fopen("custom.txt","r"))==NULL)
{
printf("打开文件失败\n");
return;
}
int i,j;
int flag;
int n=0;
while(!feof(fp))
{
fread(&Customin[n],sizeof(struct Custom),1,fp);
n++;
}
for(i=0;i<n-1;i++)
{
if(a[i]!=-1)
{
continue;
}
flag=0;
for(j=i+1;j<n;j++)
{
if(strcmp(Customin[j].FlightNum,Customin[i].FlightNum)==0)
{
a[j]=0;
if(flag==0)
{
printf("输出所有客户中乘坐相同的航班号的客户:%s\n",Customin[i].FlightNum);
flag=1;
printf("姓名 身份证号 航班号 座位号\n");
printf("%-15s%-15s%-15s%-15d\n",Customin[i].Name,Customin[i].ID,Customin[i].FlightNum,Customin[i].SeatNum);
}
printf("%-15s%-15s%-15s%-15d\n",Customin[j].Name,Customin[j].ID,Customin[j].FlightNum,Customin[j].SeatNum);
}

}
if(flag==0)
{
printf("只有一个客户乘坐航班:%s\n如下\n",Customin[i].FlightNum);
printf("姓名 身份证号 航班号 座位号\n");
printf("%-15s%-15s%-15s%-15d\n",Customin[i].Name,Customin[i].ID,Customin[i].FlightNum,Customin[i].SeatNum);

}

}
fclose(fp);
system("pause");

}

void tongjiall()
{
char ww;
do
{
system("cls");
puts("*****************************");
puts("*==========显示信息=========*");
puts("* 1、航班 统计 *");
puts("* 2、客户 统计 *");
puts("* 0、退出 *");
puts("* 请输入0-2其他输入非法 *");
puts("*****************************");
scanf("%s",&ww);
switch(ww)
{
case '1':tongjiflight();break;
case '2':tongjiCustom();break;
case '0':break;
default:printf("无此操作\n");
break;
}
}while(ww!='0');
return;
}

void display()
{
system("cls");
printf("*******************************************************\n");
printf("*=====================航空订票系统====================*\n");
printf("* 1、航班信息添加 2、客户信息添加 *\n");
printf("* 3、订票 4、退票 *\n");
printf("* 5、航班-客户信息 删除*修改 *\n");
printf("* 6、输出所有航线和客户的信息 *\n");
printf("* 7、航班-客户信息的查询 *\n");
printf("* 8、航班顾客信息统计 *\n");
printf("* 0、退出 *\n");
printf("* 请输入0--8,其他输入非法 *\n");
printf("*******************************************************\n\n\n");
printf("请输入您的选择:\n");

}

int main()
{
int choice;
display();
while(scanf("%d%*c",&choice)!=EOF)
{

switch(choice)
{
case 1:AddFlight();break;//航班信息的添加及初始化
case 2:Addcustom();break;//客户信息的添加
case 3:Addticket();break;//订票
case 4:tuipiao();//退票
case 5:CandFNew();break;//航班和客户信息的更新(删除,修改)
case 6:chaall();break;//输出所有航线和客户的信息
case 7:chapart();//航班和客户信息的查询(按不同的方式查询)
case 8:tongjiall();break;//航班和客户信息的相关统计
case 0:
printf("谢谢使用!\n");
exit(1);
return 0;
default:printf("Wrong Choice! Exit...\n");return 0;
}
display();
}
system("pause");
return 0;
}


  评论这张
 
阅读(5)| 评论(0)
推荐 转载

历史上的今天

在LOFTER的更多文章

评论

<#--最新日志,群博日志--> <#--推荐日志--> <#--引用记录--> <#--博主推荐--> <#--随机阅读--> <#--首页推荐--> <#--历史上的今天--> <#--被推荐日志--> <#--上一篇,下一篇--> <#-- 热度 --> <#-- 网易新闻广告 --> <#--右边模块结构--> <#--评论模块结构--> <#--引用模块结构--> <#--博主发起的投票-->
 
 
 
 
 
 
 
 
 
 
 
 
 
 

页脚

网易公司版权所有 ©1997-2017