a) 系统以菜单方式工作;b) 航班信息录入功能(航班信息用文件保存)--输入;c) 航班信息浏览功能--输出;d) 查询航线:(至少一种查询方式)--算法;e) 按航班号查询;
#include "stdio.h"
#include "stdlib.h"
#includ
a) 系统以菜单方式工作;b) 航班信息录入功能(航班信息用文件保存)--输入;c) 航班信息浏览功能--输出;d) 查询航线:(至少一种查询方式)--算法;e) 按航班号查询;
#include "stdio.h"
#include "stdlib.h"
#include "string.h"
struct Airport{char start[20];//起点
char end[20];//终点
char name[20];//航班名
char time[20];//航班日期(星期几)
long fnum;//航班号
int num;//预定成员
struct Airport *next;
};
void print(struct Airport*h);//输出
void input(struct Airport*h);//输入航班信息
void del(struct Airport*h);//删除航班信息
void insert(struct Airport*h);//新增航班信息
void find1(struct Airport*h);//按航班号查询
void find2(struct Airport*h);//按航班名查询
void find3(struct Airport*h);//按航班航线查询
void find4(struct Airport*h);//按航班时间查询
struct Airport*head=NULL;
*menu[]{"------------航班订票系统-----------",
"------------[1]输入航班信息--------",
"------------[2]删除航班信息--------",
"------------[3]新增航班信息--------",
"------------[4]显示航班所有信息----",
"------------[5]按航班号查询--------",
"------------[6]按航班名查询--------",
"------------[7]按航班航线查询------",
"------------[8]按航班时间查询------",
"------------[9]退出本系统----------"};//航班系统菜单
struct Airport*input()
{printf("~~~请输入你的航班数\n");
int n;
int i=1;
struct Airport*h=NULL,*p,*q;
scanf("%d",&n);
while(i!=n)
{
printf("请依次输入,航班名,航班号,航班日期,航班预定成员,航班起点,终点,\n");
p=(struct Airport*)malloc(sizeof(struct Airport));
scanf("%s%ld%s%d%s%s",p->name,&p->fnum,p->time,&p->num,p->start,p->end);
if(p=NULL)
{printf("没输入数据");
exit(0);
}
else
q->next=p;
q=p;
i++;
}
q->next=NULL;
return h;
}//航班信息输入函数
struct Airport*print(struct *h)
{printf("所有航班信息:\n");
struct Airport*h=NULL,*p;
if(p=h)
printf("暂无航班信息\n");
else
for(p=h;p!=NULL;p->next)
{printf("%s%ld%s%d%s%s",p->name,&p->fnum,p->time,&p->num,p->start,p->end);
}
}//航班信息
struct Airport*insert(struct *h)
{ int n,i;
struct Airport *p,*q,*r;
s=(struct Airport*)malloc(sizeof(struct Airport));
printf("请输入你想要增加的航班数\n");
scanf("%d",&n);
for(i=1;i
{
printf("清输入第%d个你想要增加的航班信息\n");
scanf("%s%ld%s%d%s%s",r->name,&r->fnum,r->time,&r->num,r->start,r->end);
p=h;
if(p=NULL)
{
h=r;
r->next=NULL;
}else
r->next=p;
}
return h;
}//增加航班信息
struct Airport*del(struct Airport*h)//航号删除
{ struct Airport *p,*q;
int n;
printf("请输入你想要删除的航班号\n");
scanf("%d",&n);
if(h=NULL)
printf("没有航班所能删除\n");
else{
while(p->fnum!=n&&p->fnum!=NULL)
{ q=p;
p=p->next;
}
if(p->fnum=n)
{
if(p=h)
h=p->next;
else
q->next=q->next;
}
else
printf("%d你的航班号输入有误。\n",n);
}
return h;
}
void find1(struct Airport*h)//按航号查询
{
long x;
struct Airport*p;
printf("请输入你要查询的航班号。\n");
scanf("%ld",&x);
if(h=NULL)
printf("没有航班信息\n");
else{
p=h;
while(p)
{
if(p->fnum==x)
printf("%s%ld%s%d%s%s",p->name,&p->fnum,p->time,&r->num,p->start,p->end);
p=p->next;
}
}
}
void find2(struct Airport*h)//按航班名查询
{
char s[20];
struct Airport*p;
printf("请输入你要查询的航班名\n");
scanf("%s",s);
if(h=NULL)
printf("暂无航班");
else
{
p=h;
while(p)
{
if(p->name==s)
printf("%s%ld%s%d%s%s",p->name,&p->fnum,p->time,&p->num,p->start,p->end);
p=p->next;
}
}
}
void find3(struct Airport*h)//按航线查询
{
char ss[20];
struct Airport*p;
if(h=NULL)
printf("没有您查询的航线");
else
{
p=h;
while(p)
{
if(p->name==ss)
printf("%s%ld%s%d%s%s",p->name,&p->fnum,p->time,&r->num,p->start,p->end);
p=p->next;
}
}
}
void find4(struct Airport*h)
{
char t[20];
struct Airport*p;
if(h=NULL)
printf("您输入的时间有误");
else
{
p=h;
while(p)
{
if(p->name==t)
printf("%s%ld%s%d%s%s",p->name,&p->fnum,p->time,&r->num,p->start,p->end);
p=p->next;
}
}
}
int menu()
{
int i;
int j;
for(i=1;i<10;i++)
printf("%s\n",menu[i]);
return i;
}
main()
{ char ch;
while(1)
{
switch(menu){
case 1:head=input();break;
case 2:print(head);break;
case 3:head=insert(head);break;
case 4:head=del(head);break;
case 5:find1(head);break;
case 6:find2(head);break;
case 7:find3(head);break;
case 8:find4(head);break;
case 9:exit(0);}
}
}菜单怎么实现?还有一些问题帮忙指出一下
展开
全部