You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
hbxxgl/hangbanxinxiguanli.cpp

191 lines
3.3 KiB

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

#include<stdio.h>
#include<stdlib.h>
#include<string.h>
struct hb
{
char hbm[10];
char xm[10];
char sj[20];
char qsd[10];
char mdd[10];
int zks;
int dj;
};
void chaxun(char cxhb[])
{ struct hb cx;
char a[10];
FILE *fp;
int flag=0;
printf("请输入你的姓名:\n");
fp=fopen("chaxun.txt","r+");
rewind(fp);
if(fp==NULL)
{
printf("打开文件失败\n");
exit(1);
}
while(!feof(fp)&&flag==0)
{
scanf("%s",a);
fscanf(fp,"%s%s%s%s%s",cx.hbm,cx.xm,cx.sj,cx.qsd,cx.mdd);
if(strcmp(a,cx.xm)==0)
{
printf("%s%s%s%s%s",cx.hbm,cx.xm,cx.sj,cx.qsd,cx.mdd);
flag=1;
}
}
fclose(fp);
}
struct ckxx
{
char hbh[15];
char sfzhm[25];
char name[10];
char sex[4];
char year[20];
char zuoweihao[10];
};
void dingpiao()
{
struct ckxx dp;
FILE *fp;
int flag=0;
fp=fopen("dingpiao.txt","a+");
rewind(fp);
if(fp==NULL)
{
printf("打开文件失败");
exit(1);
}
printf("请输入需要的航班号\n");
scanf("%s",dp.hbh);
printf("请输入身份证号码\n");
scanf("%s",dp.sfzhm);
printf("请输入姓名\n");
scanf("%s",dp.name);
printf("请输入性别\n");
scanf("%s",dp.sex);
printf("请输入出生年月日\n");
scanf("%s",dp.year);
printf("请输入座位号\n");
scanf("%s",dp.zuoweihao);
fprintf(fp,"%s %s %s %s %s %s\n",dp.hbh,dp.name,dp.sfzhm,dp.sex,dp.year,dp.zuoweihao);
}
struct qx//取消航班
{
char hbm[10];
char qsd[10];
char mdd[10];
char sj[20];
};
void quxiao()
{
struct qx cc;
FILE *fp1,*fp2;
fp1=fopen("hangban.txt","r");
fp2=fopen("hangbanx.txt","w+");
char a[10];
printf("请输入需要取消的航班信息");
scanf("%s",a);
long last,h;
fseek(fp1,0L,SEEK_END);
last=ftell(fp1);
rewind(fp1);
while(h=ftell(fp1)<last-20&&!feof(fp2))
{
fscanf(fp1,"%s%s%s%s",cc.hbm,cc.qsd,cc.mdd,cc.sj);
if(strcmp(a,cc.hbm)==0 )
{
}
else
{
fprintf(fp2,"%s %s %s %s\n",cc.hbm,cc.qsd,cc.mdd,cc.sj);
}
}
fclose(fp1);
fclose(fp2);
remove("hangban.txt");
rename("hangbanx.txt","hangban.txt");
printf("删除航班成功");
}
struct zj //增加航班
{
char hbm[10];
char qsd[10];
char mdd[10];
char sj[20];
};
void zengjia()
{
struct zj zjhb;
FILE *fp;
int x;
printf("请输入您要增加的航班、起始地、目的地、以及时间:\n");
scanf("%s%s%s%s",zjhb.hbm ,zjhb.qsd,zjhb.mdd,zjhb.sj);
printf("您确定增加航班%s起始地为%s目的地为%s时间为%s\n",zjhb.hbm ,zjhb.qsd,zjhb.mdd,zjhb.sj);
printf("输入1确定0退出\n");
scanf("%d",&x);
if(x==1)
{
fp=fopen("hangban.txt","a+");
rewind(fp);
if(fp==NULL)
{
printf("打开文件失败");
exit(1);
}
fprintf(fp,"%s %s %s %s\n",zjhb.hbm ,zjhb.qsd,zjhb.mdd,zjhb.sj);
fclose(fp);
printf("增加成功");
}
}
int main()
{
printf(" *********哈哈哈航空为您服务***************\n");
printf(" 请输入1-4序号选择您所需的服务*************\n");
printf(" 1、********订票服务***********************\n");
printf(" 2、********查询服务***********************\n");
printf(" 3、********取消航班(工作人员选项)*********\n");
printf(" 4、********增加航班(工作人员选项)*******\n");
printf(" 5、**********退出*************************\n");
int x;
scanf("%d",&x);
char hangban[10];
switch(x)
{
case 1:
dingpiao();
break;
case 2:
chaxun(hangban);
break;
case 3:
quxiao();
break;
case 4:
zengjia();
break;
case 5:
break;
}
}