首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > C语言 >

【航班信息管理的课程设计】,该怎么处理

2012-03-19 
【航班信息管理的课程设计】问题描述:飞机航班系统的数据包括两部分:① 航班信息:航班号、最大载客数、起飞地点

【航班信息管理的课程设计】
问题描述:
飞机航班系统的数据包括两部分:
① 航班信息:航班号、最大载客数、起飞地点、起飞时间、降落地点、降落时间,单价;
② 乘客信息:航班号、身份证号码、姓名、性别、出生年月、座位号。
乘客订票的主要方式是:乘客提出航班号、起飞地点、起飞时间、降落地点、订票数等订票要求,根据事先保存的航班数据决定乘客能否订票?只有全部满足了乘客的订票要求并且所订航班有足够的未订座位之后才能完成订票处理,并且修改该航班的未订座位数(每个航班的未订座位数的初始值就是该航班的最大载客数);否则,订票失败,并且给出不能订票的原因。
要求将航班数据保存在数据文件中,在处理时按航班的起飞地点建立不同的链表。
功能要求 :
⑴ 增加航班记录。将新的航班记录增加到原有的航班数据文件中。在进行处理时必须检查所要增加的航班记录是否存在,如果已经存在,应给出提示信息后停止增加;
⑵ 航班取消。如果某次航班的乘客数太少(已订票的少于本次航班最大载客数的10%),将取消该航班,但该航班的记录仍然保存在原有的航班数据文件中;
⑶ 航班查询。应该有以下几种基本的查询方式:按航班号、按起飞地点和起飞时间、按降落地点,按起飞地点和降落地点;
⑷ 航班订票。按上述问题描述中的乘客订票方式完成航班订票处理。
⑸ 设计一个菜单,至少具有上述操作要求的基本功能。  



以下是带有错误的程序雏形:【请各位看看,多加指点,不甚感恩!】




/* 飞机航班系统的数据包括两部分:
① 航班信息:航班号、最大载客数、起飞地点、起飞时间、降落地点、降落时间,单价;
② 乘客信息:航班号、身份证号码、姓名、性别、出生年月、座位号。*/
#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_select[] 

"------------航班订票系统-----------",
  "------------[1]输入航班信息--------",
  "------------[2]删除航班信息--------",
  "------------[3]新增航班信息--------",
  "------------[4]显示航班所有信息----",
  "------------[5]按航班号查询--------",
  "------------[6]按航班名查询--------",
  "------------[7]按航班航线查询------",
  "------------[8]按航班时间查询------",
  "------------[9]退出本系统----------",
};//航班系统菜单
struct Airport *input()
{
  int n;
  int i=1;
  struct Airport *h=NULL,*p,*q;
  printf("~~~请输入你的航班数\n");
  scanf("%d",&n);
  for(i=1;i<=n;i++)  
{
  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;
  r=(struct Airport*)malloc(sizeof(struct Airport));
  printf("请输入你想要增加的航班数\n");
  scanf("%d",&n);
  for(i=1;i<n;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,&p->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,&p->num,p->start,p->end);
  p=p->next;
}
}
}
int menu_select()  
{  
  int i,s;  
  char c[3];  
  for(i=0;i<10;i++)  
  printf("%s\n",menu[i]);  
  do  
{  
  scanf("%s",c);  
  s=atoi(c);  
}while(s<0||s>9);  
  return s;  
}  


main()

for(;;)
  switch(menu_select())
{
  case 1:head=input();break;  
  case 2:print(head);break;  
  case 3:head=insert(head);break; /*这个switch()菜单没怎么弄明白 为什么有的要加head这个头指针而不是直接*/
  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);
}

 



[解决办法]

C/C++ code
#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);//输入航班信息struct Airport * del(struct Airport *h);//删除航班信息struct Airport * 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;char *menu[] ={     "------------航班订票系统-----------",    "------------[1]输入航班信息--------",    "------------[2]删除航班信息--------",    "------------[3]新增航班信息--------",    "------------[4]显示航班所有信息----",    "------------[5]按航班号查询--------",    "------------[6]按航班名查询--------",    "------------[7]按航班航线查询------",    "------------[8]按航班时间查询------",    "------------[9]退出本系统----------",};//航班系统菜单struct Airport *input(){    int n;    int i=1;    struct Airport *h=NULL,*p,*q;    printf("~~~请输入你的航班数\n");    scanf("%d",&n);    for(i=1;i<=n;i++)      {        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;}//航班信息输入函数void print(struct Airport *h){    printf("所有航班信息:\n");    struct Airport *p=NULL;    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 Airport *h){     int n,i;    struct Airport *p,*q,*r;    r=(struct Airport*)malloc(sizeof(struct Airport));    printf("请输入你想要增加的航班数\n");    scanf("%d",&n);    for(i=1;i<n;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,&p->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,&p->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,&p->num,p->start,p->end);            p=p->next;        }    }}int select_menu()  {      int i,s;      char c[3];      for(i=0;i<10;i++)          printf("%s\n",menu[i]);      do      {          scanf("%s",c);          s=atoi(c);      }while(s<0||s>9);      return s;  }  int main(){     for(;;)    switch(select_menu())    {        case 1:head=input();break;          case 2:head=del(head);break;        // 这个是因为有返回值,所以返回了        case 3:head=insert(head);break;         case 4:print(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);    }    return 0;} 


[解决办法]
2L你的程序中,那个input函数返回的h指针,你没有赋值,就会一直是NULL,这样print函数能起到作用吗?
[解决办法]
要学会自己调试

热点排行