要求:
添加飞机票信息,航班信息遍历,追加航班记录,按航班号查询并可选择修改已售票数,按起始站与终点站查询飞机票,
从文件读入数据,保存数据到文件,用户登录时入用户名及密码由起飞时间、降落时间自计算出飞行时间,删除已售空飞机票相应记录。
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<windows.h>
struct fjp{
char hbh[20];
char qsz[30];
char zdz[30];
int qfsj[2];
int jlsj[2];
int fxsc;
int yusps;
int yisps;
struct fjp *next;
};
struct yh{
char yhm[20];
char mm[20];
};
struct fjp*xj();
struct fjp*zj(struct fjp*head);
struct fjp*sc(struct fjp*head);
struct fjp*xg(struct fjp*head);
void bl(struct fjp*head);
int main()
{
struct fjp *head=NULL,*p;
char hbh[20],qsz[30],zdz[30];
int qfsj[2],jlsj[2],fxsc,yusps,yisps,x;
int size=sizeof(struct fjp);
do{
printf("| 1:新建航班信息 | 2:追加航班信息 | 3:删除售空航班信息 | 4:按航班号修改已出售票数 | 5:遍历 | 0:退出 |\n");
system("color 9F");
scanf("%d",&x);
switch(x){
case 1:MessageBox(0,"欢迎使用飞机票查询系统(客户系统)\n版本:1.0.0\n指导老师:刘凌霞\n制作人:张鹏184804060 谢庆翔184804019 任化振184804002\n联系方式:电话 123456789 QQ 123456789\n日期:2019年4月3日\n版权所有:张鹏 谢庆翔 任化振。保留所有权利。","飞机票查询系统(客户系统)",0);
head=xj();break;
case 2:head=zj(head);break;
case 3:head=sc(head);break;
case 4:head=xg(head);break;
case 5:bl(head);break;
case 0:break;
}
}while(x!=0);
printf("请输入用户信息\n请输入要录入的信息个数:");
FILE *fp;
struct yh y[100];
int i=0,n;
scanf("%d",&n);
if((fp=fopen("用户文档.txt","w+"))==NULL)
{
printf("程序出错!\n");
exit(0);
}
while(i<n){
scanf("%s%s",y[i].yhm,y[i].mm);
fprintf(fp,"%s %s\n",y[i].yhm,y[i].mm);
i++;
}
if(fclose(fp)){
printf("程序出错!\n");
exit(0);
}
system("cls");
struct fjp *p1;
FILE *fp1;
char yhm[40],mm[20],x1[40],m;
int check=0;
printf("请输入用户名\n");
scanf("%s",yhm);
printf("请输入密码(6~16位)\n");
int e=0;
while((m=getch())!='\r'){
if(m=='\b'){
printf("\b \b");
e=e-1;
mm[e]='\0';
}
else{
mm[e++]=m;
printf("*");
}
}
mm[e]='\0';
while(e<6||e>16){
printf("\n您输入的密码不合法!\n请重新输入密码(6~16位)\n");
e=0;
while((m=getch())!='\r'){
if(m=='\b'){
printf("\b \b");
e=e-1;
mm[e]='\0';
}
else{
mm[e++]=m;
printf("*");
}
}
mm[e]='\0';
}
strcat(yhm," ");strcat(yhm,mm);strcat(yhm,"\n");
if((fp1=fopen("用户文档.txt","r"))==NULL){
printf("程序出错!\n");
exit(0);
}
while(!feof(fp1)){
fgets(x1,40,fp1);
if(strcmp(yhm,x1)==0){
check=1;break;
}
}
if(fclose(fp1)){
printf("系统出错!\n");
exit(0);
}
int i1;i=1;
if(check==0){
for(i1=1;i1<=3;i1++){
printf("\n用户名或密码错误!(您还有%d次机会)\n",3-i1);
printf("请重新输入用户名\n");
scanf("%s",yhm);
printf("请输入密码(6~16位)\n");
int e=0;
while((m=getch())!='\r'){
if(m=='\b'){
printf("\b \b");
e=e-1;
mm[e]='\0';
}
else{
mm[e++]=m;
printf("*");
}
}
mm[e]='\0';
while(e<6||e>16){
printf("\n您输入的密码不合法!\n请重新输入密码(6~16位)\n");
e=0;
while((m=getch())!='\r'){
if(m=='\b'){
printf("\b \b");
e=e-1;
mm[e]='\0';
}
else{
mm[e++]=m;
printf("*");
}
}
mm[e]='\0';
}
strcat(yhm," ");strcat(yhm,mm);strcat(yhm,"\n");
if((fp1=fopen("用户文档.txt","r"))==NULL){
printf("程序出错!\n");
exit(0);
}
while(!feof(fp1)){
fgets(x1,40,fp1);
if(strcmp(yhm,x1)==0){
check=1;break;
}
}
if(fclose(fp1)){
printf("系统出错!\n");
exit(0);
}
if(check==1)
break;
else
i++;
if(check==0&&i==3){
printf("\n您已输错三次!\n强制退出");
break;
}
}
}
if(check==1){
printf("\n登录成功\n");
system("color 5F");
MessageBox(0,"欢迎使用飞机票查询系统(客户系统)\n版本:1.0.0\n指导老师:刘凌霞\n制作人:张鹏184804060 谢庆翔184804019 任化振184804002\n联系方式:电话 123456789 QQ 123456789\n日期:2019年4月3日\n版权所有:张鹏 谢庆翔 任化振。保留所有权利。","飞机票查询系统(客户系统)",0);
int n;char qs[30],zd[30];
do{
printf("1:查询全部航班|2:按起始站查询航班|3:按终点站查询航班|0:退出\n");
scanf("%d",&n);
switch(n){
case 1:
printf("航班号|起始站|终点站|起飞时间|降落时间|飞行时长|预售票数|已售票数\n");
for(p1=head;p1!=NULL;p1=p1->next)
printf(" %s | %s | %s | %02d:%02d | %02d:%02d | %03d分钟| %d张 | %d张\n",p1->hbh,p1->qsz,p1->zdz,p1->qfsj[0],p1->qfsj[1],p1->jlsj[0],p1->jlsj[1],p1->fxsc,p1->yusps,p1->yisps);
break;
case 2:
printf("请输入要查询的起始站\n");
scanf("%s",qs);
int r1=0;
for(p1=head;p1!=NULL;p1=p1->next){
if(strcmp(p1->qsz,qs)==0){
printf("%s航班|%s到%s|起飞时间:%02d:%02d|降落时间:%02d:%02d|飞行时长:%d分钟|预售%d张|已售%d张\n",p1->hbh,p1->qsz,p1->zdz,p1->qfsj[0],p1->qfsj[1],p1->jlsj[0],p1->jlsj[1],p1->fxsc,p1->yusps,p1->yisps);
r1++;
}
}
if(r1==0)
printf("没有查到您想要的航班信息!\n");
break;
case 3:
printf("请输入要查询的终点站\n");
scanf("%s",zd);
int r2=0;
for(p1=head;p1!=NULL;p1=p1->next){
if(strcmp(p1->zdz,zd)==0){
printf("%s航班|%s到%s|起飞时间:%02d:%02d|降落时间:%02d:%02d|飞行时长:%3d分钟|预售%d张|已售%d张\n",p1->hbh,p1->qsz,p1->zdz,p1->qfsj[0],p1->qfsj[1],p1->jlsj[0],p1->jlsj[1],p1->yusps,p1->yisps);
r2++;
}
}
if(r2==0)
printf("没有查到您想要的航班信息!\n");
break;
case 0:
break;
}
}while(n!=0);
}
return 0;
}
struct fjp*xj()
{
char hbh[20],qsz[30],zdz[30];
int qfsj[2],jlsj[2],fxsc,yusps,yisps,n;
struct fjp *head,*str,*p;
head=str=NULL;
printf("添加航班信息数量:");
scanf("%d",&n);
while(n--)
{
getchar();
scanf("%s %s %s %d:%d %d:%d %d %d",hbh,qsz,zdz,&qfsj[0],&qfsj[1],&jlsj[0],&jlsj[1],&yusps,&yisps);
p=(struct fjp*)malloc(sizeof(struct fjp));
strcpy(p->hbh,hbh);
strcpy(p->qsz,qsz);
strcpy(p->zdz,zdz);
p->qfsj[0]=qfsj[0];
p->qfsj[1]=qfsj[1];
p->jlsj[0]=jlsj[0];
p->jlsj[1]=jlsj[1];
p->yusps=yusps;
p->yisps=yisps;
int x;
x=jlsj[0]*60+jlsj[1]-qfsj[0]*60-qfsj[1];
p->fxsc=x;
p->next=NULL;
if(head==NULL)
head=p;
else
str->next=p;
str=p;
}
return head;
}
struct fjp*zj(struct fjp *head)
{
char hbh[20],qsz[30],zdz[30];
int qfsj[2],jlsj[2],fxsc,yusps,yisps,n;
struct fjp *str1,*str2,*p;
str2=head;
while(str2->next!=NULL){
str2=str2->next;
}
printf("追加航班信息数量:");
scanf("%d",&n);
while(n--)
{
scanf("%s %s %s %d:%d %d:%d %d %d",hbh,qsz,zdz,&qfsj[0],&qfsj[1],&jlsj[0],&jlsj[1],&yusps,&yisps);
p=(struct fjp*)malloc(sizeof(struct fjp));
strcpy(p->hbh,hbh);
strcpy(p->qsz,qsz);
strcpy(p->zdz,zdz);
p->qfsj[0]=qfsj[0];
p->qfsj[1]=qfsj[1];
p->jlsj[0]=jlsj[0];
p->jlsj[1]=jlsj[1];
p->yusps=yusps;
p->yisps=yisps;
int x;
x=jlsj[0]*60+jlsj[1]-qfsj[0]*60-qfsj[1];
p->fxsc=x;
p->next=NULL;
if(head==NULL)
head=p;
else{
str2->next=p;
str2=p;
}
}
return head;
}
struct fjp*xg(struct fjp*head)
{
struct fjp *str;
int gai;
char a[20];
printf("输入要修改的航班号:");
scanf("%s",a);
for(str=head;str!=NULL;str=str->next){
if(strcmp(a,str->hbh)==0){
printf("输入你要修改的已售票数:");
scanf("%d",&gai);
str->yisps=gai;
break;
}
}
if(str==NULL)
printf("未查找到你输入需要修改的航班号\n");
return head;
}
void bl(struct fjp*head)
{
struct fjp *str;
if(head==NULL){
printf("你还没有添加任何航班信息\n");
return ;
}
else{
FILE *ff;
int i=0;
if((ff=fopen("航班信息.txt","w+"))==NULL)
{
printf("程序出错!\n");
exit(0);
}
for(str=head;str!=NULL;str=str->next){
printf("%s %s %s %02d:%02d %02d:%02d %3d分钟 %d %d\n",str->hbh,str->qsz,str->zdz,str->qfsj[0],str->qfsj[1],str->jlsj[0],str->jlsj[1],str->fxsc,str->yusps,str->yisps);
fprintf(ff,"%s %s %s %02d:%02d %02d:%02d %3d分钟 %d %d\n",str->hbh,str->qsz,str->zdz,str->qfsj[0],str->qfsj[1],str->jlsj[0],str->jlsj[1],str->fxsc,str->yusps,str->yisps);
}
if(fclose(ff)){
printf("程序出错!\n");
exit(0);
}
}
}
struct fjp*sc(struct fjp*head)
{
struct fjp *p,*str,*ptr;
while(head!=NULL&&head->yisps==head->yusps){
head=head->next;
}
ptr=head;
str=head->next;
while(str!=NULL){
if(str->yisps==str->yusps){
ptr->next=str->next;
}
else
ptr=str;
str=str->next;
}
return head;
}