帮忙看下我修改的程序,谢谢
程序代码:
#include <stdio.h> #include <string.h> #include <stdlib.h> /* 用到exit() */ struct hangban { long int num; char hangbanhao; char qishizhan; char zhongdianzhan; int yushoushu; int yishoushu; int feixingshijian; }; int n=0; struct hangban stu[100]; struct hangban *p; void lr(); void ll(); void cx(); void xg(); void sc(); void main() { int z; printf("+---------------------------+\n"); printf("| 欢迎使用航空订票系统 |\n"); printf("+---------------------------+\n"); printf("提示:为保证您的操作得到保存,请按正常顺序退出系统^_^\n"); do { printf("\n\t\t\t--------------------------------\n"); printf("\t\t\t+ 主菜单 |\n"); printf("\t\t\t--------------------------------\n"); printf("\t\t\t+ [1]----录入 |\n"); printf("\t\t\t+ [2]----显示 |\n"); printf("\t\t\t+ [3]----查询 |\n"); printf("\t\t\t+ [4]----退票 |\n"); printf("\t\t\t+ [5]----修改 |\n"); printf("\t\t\t+ [0]----退出 |\n"); printf("\t\t\t--------------------------------\n"); printf("请输入您的选择:"); scanf("%d", &z); switch(z) { case 0 : exit(0); break; /* 退出系统 */ case 1 :lr();break; case 2 :ll();break; case 3 :cx();break; case 4 :sc();break; case 5 :xg();break; default:printf("\n无效选项!"); break; } } while(z!= 0); } void lr()/*添加函数*/ { int y=1; p=stu; /* 指向第一个空指针,以输入新信息 */ do { printf("--------------------\n"); printf("请输入飞机航班号:"); scanf("%ld",&p->hangbanhao); printf("请输入飞机起始站:"); scanf("%s",p->qishizhan); printf("请输入飞机终点站:"); scanf("%d",&p->zhongdianzhan); printf("输入飞机飞行日期:"); scanf("%s",&p->feixingshijian); printf("请输入预售票总数:"); scanf("%d",&p->yushoushu); printf("请输入已售票总数:"); scanf("%d",&p->yishoushu); n++; p++; printf("\n1.继续输入.\n0.输入完毕.\n"); printf("请选择:"); scanf("%d",&y); } while(y==1); printf("提示:输入完毕!你一共输入%d个\n",n); } void ll()/*显示函数*/ { int i,j; if(n!=0) { printf("航班总数:%d\n", n); printf("航班号\t起始站\t终点站\t飞行时间\t预售票总数\t已售票总数\t\n"); printf("-----------------------------------------------------\n"); for(i=0;i<n;i++) printf("%ld\t%s\t%d\t%s\t%d\t%d\t \n",stu[i].hangbanhao,stu[i].qishizhan,stu[i].zhongdianzhan,stu[i].feixingshijian,stu[i].yushoushu,stu[i].yishoushu); } else printf("提示:无航班数据,请输入数据!"); } void cx()/*查询函数*/ { int c; int w,i,j; char name[20]; if(n!=0) { do{ printf("\n"); printf("+--------------------+\n"); printf("| 起飞城市 请按 1 |\n"); printf("| 抵达城市 请按 2 |\n"); printf("| 取消 请按 0 |\n"); printf("+--------------------+\n"); printf("请输入您的选择:"); scanf("%d", &c); switch(c) { case 0: break; case 1: j=0; printf("请输入起飞城市:"); scanf("%ld", &w); printf("\n"); for(i=0;i<n;i++) if(stu[i].num==w) { printf("航班号\t起始站\t终点站\t飞行时间\t预售票总数\t已售票总数\t\n"); printf("%ld\t%s\t%d\t%s\t%d\t%d\t\n",stu[i].hangbanhao,stu[i].qishizhan,stu[i].zhongdianzhan,stu[i].feixingshijian,stu[i].yushoushu,stu[i].yishoushu); j=1; } if(j==0) printf("提示:没有该航班记录,请核对!"); break; case 2: j=0; printf("请输入抵达城市:"); scanf("%s", name); printf("\n"); for(i=0;i<n;i++) if(strcmp(name,stu[i].hangbanhao)==0) { printf("航班号\t起始站\t终点站\t飞行时间\t预售票总数\t已售票总数\t\n"); j=1; printf("%ld\t%s\t%d\t%s\t%d\t%d\t\n",stu[i].hangbanhao,stu[i].qishizhan,stu[i].zhongdianzhan,stu[i].feixingshijian,stu[i].yushoushu,stu[i].yishoushu); } if(j==0) printf("提示:没有该航班记录,请核对!"); break; default: printf("\n提示:无效选项!"); break; } }while(c!= 0); }else printf("提示:无航班数据,请输入数据!"); } void xg()/*修改函数*/ { long int num; int i,j,c; if(n!=0) { printf("请输入您要修改的飞机航班号:"); scanf("%ld", &num); printf("\n"); for(i=0;i<n;i++) if(stu[i].num==num) j=i; do{ printf("请选择您要修改的航班的信息内容:\n"); printf("+----------------------+\n"); printf("| 航班号 请按 1 |\n"); printf("| 起始站 请按 2 |\n"); printf("| 终点站 请按 3 |\n"); printf("| 飞行时间 请按 4 |\n"); printf("| 预售票总数 请按 5 |\n"); printf("| 已售票总数 请按 6 |\n"); printf("| 取消 请按 0 |\n"); printf("+----------------------+\n"); printf("请输入您的选择:"); scanf("%d", &c); printf("\n"); switch(c) { case 0:break; case 1:printf("请输入航班号:"); scanf("%s",stu[j].hangbanhao); break; case 2:printf("请输入起始站:"); scanf("%d",&stu[j].qishizhan); break; case 3:printf("请输入终点站:"); scanf("%s",stu[j].zhongdianzhan); break; case 4:printf("请输入飞行时间:"); scanf("%ld",&stu[j].feixingshijian); break; case 5:printf("请输入预售票总数:"); scanf("%d",&stu[j].yushoushu); break; case 6:printf("请输入已售票总数:"); scanf("%d",&stu[j].yishoushu); break; default: printf("\n无效选项!"); break; } }while(c!= 0); }else printf("提示:无航班数据,请输入数据!"); } void sc()/*删除函数*/ { long int num; int i,j,e; if(n!=0) { printf("航班号\t起始站\t终点站\t飞行时间\t预售票总数\t已售票总数\t\n"); printf("-----------------------------------------------------\n"); for(i=0;i<n;i++) printf("%ld\t%s\t%d\t%s\t%d\t%d\t\n",stu[i].hangbanhao,stu[i].qishizhan,stu[i].zhongdianzhan,stu[i].feixingshijian,stu[i].yushoushu,stu[i].yishoushu); printf("请输入您要退票的航班号:"); scanf("%ld", &num); printf("\n"); for(i=0;i<n;i++) if(num==stu[i].num) j=i; if(j!=(n-1)) { for(e=i-1;e<n;e++,j++) { stu[j].num=stu[j+1].num; strcpy(stu[j].qishizhan,stu[j+1].qishizhan); strcpy(stu[j].zhongdianzhan,stu[j+1].zhongdianzhan); stu[j].feixingshijian=stu[j+1].feixingshijian; stu[j].yushoushu=stu[j+1].yushoushu; stu[j].yishoushu=stu[j+1].yishoushu; n--; } }else n--; printf("提示:退票成功!"); }else printf("提示:无任何购票记录,请购票!"); }
我自己修改的,输入数据后,
在查询那里查不到,在显示那里显示时也有错误,
请帮忙看下是那里错了,帮忙指出!!