回 帖 发 新 帖 刷新版面

主题:放送航空售票系统源代码(已修正错误)

我们老师布置的作业,基本上完成了,现已完成,并修正了部分错误
注意事项,输入字符时不要包含空格,由于本人用的编译器有问题,gets函数不能正常工作,。如果想要输入字符串中包含空格,请自行将部分scanf改为gets.
程序采用链表和顺序表的混合设计
本人初学数据结构,希望与大家多多交流
如有问题请跟帖讨论



功能:可以输入姓名查询自己的航班信息
      可以订票,退票
      可以增加航班(设置了密码)
几个函数功能的描述
void init(flightmange* fl,char fn[][20],int fnum[],int tic[] ) 初始化航班信息
void printall(flightmange* fl,int *length)显示所有航班信息
void welcome()显示主界面
int findflight(flightmange *fl,int n,int *length)查询是否存在此航班号
void printselect(flightmange *fl,int i,int n)显示当前航班信息
void booktic(flightmange *fl,int *length)订票
flightdetail* findname(flightdetail *m,char na[]) 搜索指定用户名
void returntic(flightmange *fl,int *length)退票
void search(flightmange *fl,int *length)搜索指定用户的航班信息
void create(flightmange *fl,int *length)在原有的航班基础上添加新航班


#define N 5
#include "stdio.h"
#include "stdlib.h"
#include "malloc.h"
#include "string.h"
typedef struct flightdetail
{
   char customer[10];
   int num;
   struct flightdetail *next;

}flightdetail;

typedef struct flightmange
{
   char name[20];
   int booked;
   int ticket;
   int flightnum;
   flightdetail *next;
}flightmange;

void init(flightmange* fl,char fn[][20],int fnum[],int tic[] )
{
   int i;
   flightdetail *fd;
   for(i=0;i<N;i++)
   {  fd=(flightdetail *)malloc(sizeof(flightdetail));
      strcpy((fl[i]).name,fn[i]);
      (fl[i]).booked=0;
      (fl[i]).ticket=tic[i];
      (fl[i]).flightnum=fnum[i];
      (fl[i]).next=fd;
      fd->next==NULL;

   }
}
void printall(flightmange* fl,int *length)
{
  int i;
    printf("\tAll Flght Information\n\n");
    printf("Flightname               Flightnum     All     Sold    Rest\n\n");
  for(i=0;i<*length;i++)
  {
    printf("%-20s",(fl[i]).name);
    printf("     %-8d",(fl[i]).flightnum);
    printf("      %-5d",(fl[i]).ticket);
    printf("   %-5d",(fl[i]).booked);
    printf("   %-5d",(fl[i]).ticket-(fl[i]).booked);
    printf("\n");
  }
  printf("\nPress Any Key to Return the System");
  getch();

}
void welcome()
{
   printf("\t\t\tTicket Mange System\n\n");
   printf("\t1.Reset the System  (Password Required)\n");
   printf("\t2.Book Ticket(s)\n");
   printf("\t3.Return Ticket(s)\n");
   printf("\t4.Show All the Flight Information\n");
   printf("\t5.Dispaly My Flights\n");
   printf("\t6.Quit the System");
   printf("\n\nPlease Enter a Num to Select an Item");
   printf("\n\t\t\t\t\t\tDesigned By Yang Rida");

}

回复列表 (共11个回复)

沙发

int findflight(flightmange *fl,int n,int *length)
{
  int i;
  for(i=0;i<*length;i++)
    if (fl[i].flightnum==n) return i;
  return 999;

}
void printselect(flightmange *fl,int i,int n)
{

    printf("\n\t%d Flght Information\n\n",n);
    printf("Flightname               Flightnum     All     Sold    Rest\n\n");
    printf("%-20s",(fl[i]).name);
    printf("     %-8d",(fl[i]).flightnum);
    printf("      %-5d",(fl[i]).ticket);
    printf("   %-5d",(fl[i]).booked);
    printf("   %-5d",(fl[i]).ticket-(fl[i]).booked);
    printf("\n");

}

void booktic(flightmange *fl,int *length)
{
   int i=0,n=0,t=999,nn=0;
   char na[10],key;
   flightdetail *p,*q;
   printf("Welcome to the Booking System\n\n");
   while(1)
   {
     printf("Please Input the Num of the Flight You Want to Book:");
     scanf("%d",&n);
     t=findflight(fl,n,length);
     if(t==999)  {
                printf("\nthe Num of the Flight You Entered Not Find,Press Any Key to Reenter");
                getch();
                system("cls");
                printf("Welcome to the Booking System\n\n");
                continue;
                    }
      printf("\nCorrect!Now Enter Your Name and Tell Us How Many Tickets You want\n ");
      printselect(fl,t,n);
      printf("\nYour Name:");
      scanf("%s",na);
      printf("\nTicket Quantity:");
      scanf("%d",&nn);
      if(nn==0)
      {printf("\nWarning:Illegal Data");
       getch();
       system("cls");
       printf("Welcome to the Booking System\n\n");
       continue;

      }
      if(nn<=(fl[t].ticket-fl[t].booked)&&n>=1)
      {
       q=fl[t].next->next;
       p=(flightdetail *)malloc(sizeof(flightdetail));
       strcpy(p->customer,na);
       p->num=nn;
       p->next=q;
       fl[t].next->next=p;
       fl[t].booked+=nn;
       printf("\nDear %s,You have successfully booked  %s Thanks for Using\n\tPress Any Key to Return",p->customer,fl[t].name);
       getch();
       return;
      }

      else
      {
         printf("\nSorry,We Don't Have Enougth Ticket(s) For You\n\tPress <Y> to Reenter Or Press <N> to Exit");
         do
         {
           key=getch();

         }while(key!='Y'&&key!='y'&&key!='n'&&key!='N');
      }
       if(key=='Y'||key=='y')
       {
                   system("cls");
                printf("Welcome to the Booking System\n\n");
                continue;
       }
       else {
         printf("\nBooking Failed ,Thanks for Using");
         return;
       }
   }
}

板凳

flightdetail* findname(flightdetail *m,char na[])
{
   flightdetail *p=m;
   m=m->next;
   while(m)
   {
     if(strcmp(m->customer,na)==0) return p;
     p=m;
     m=m->next;
   }
   return NULL;
}
void returntic(flightmange *fl,int *length)
{
   int i=0,n=0,t=999,nn=0;
   char na[10],key;
   flightdetail *p,*q;
   printf("Welcome to the Return Ticket System\n\n");
     while(1)
   {
     printf("\nStep1.Please Input the Num of the Flight You Want to return:");
     scanf("%d",&n);
     t=findflight(fl,n,length);
     if(t==999)
     {
         printf("\nthe Num of the Flight You Entered Not Find,\n\tPress <Y> to Reenter Or Press <N> to Exit");

         do
         {
           key=getch();

         }while(key!='Y'&&key!='y'&&key!='n'&&key!='N');

       if(key=='n'||key=='N')
       {
          printf("\n\tOperation Failed ,Thanks for Using");
          getch();
          return;
       }
       else{
             system("cls");
             printf("Welcome to the Booking System\n\n");
             continue;
            }
     }
            printf("\nCorrect Flight Num!\n\n");
            printf("Step2.Tell Us Your Name,We'll Check Our Database:");
            scanf("%s",na);
            p=findname(fl[t].next,na);
         if(p==NULL)
        {
            printf("\nYour Name Not Find,Make Sure You Have Entered Correctly\n\tPress <Y> to Reenter Or Press <N> to Exit");
            do
            {
            key=getch();
            }while(key!='Y'&&key!='y'&&key!='n'&&key!='N');

       if(key=='n'||key=='N')
       {
          printf("\n\tOperation Failed ,Thanks for Using");
          getch();
          return;
       }
       else{
             system("cls");
             printf("Welcome to the Booking System\n\n");
             continue;
            }
     }
     printf("\nFlightName          Yourname    TicketQuantity ");
     printf("\n%-20s%-10s  %-5d",fl[t].name,p->next->customer,p->next->num);
     printf("\nStep3.Now Tell Us How Many Ticket You Want to Retrun:");
     scanf("%d",&nn);
     q=p->next;
     if(nn>q->num||nn<1)
     {
       printf("\nIllegal Data\n\tPress <Y> to Reenter Or Press <N> to Exit");
           do
            {
            key=getch();
            }while(key!='Y'&&key!='y'&&key!='n'&&key!='N');

       if(key=='n'||key=='N')
       {
          printf("\n\tOperation Failed ,Thanks for Using");
          getch();
          return;
       }
       else{
             system("cls");
             printf("Welcome to the Booking System\n\n");
             continue;
            }
     }
      q->num-=nn;
      printf("\nDear %s,You have successfully returned  %d %s Ticket(s) Thanks for Using\n\tPress Any Key to Return",q->customer,nn,fl[t].name);
          if(q->num==0)
     {
      p->next=q->next;
      free(q);
     }
     fl[t].booked-=nn;
     getch();
     break;
     }
}
void search(flightmange *fl,int *length)
{  int ff=0,i;
   char na[10];
   flightdetail *p;
   printf("Enter Your Name:");
    scanf("%s",na);
   printf("\n\nFlightname               Flightnum    Name       Ticket Quantity \n\n");
    for(i=0;i<*length;i++)
   { p=fl[i].next->next;
     while(p)
     {
       if(strcmp(p->customer,na)==0)
          {
           printf("%-20s",(fl[i]).name);
           printf("     %-8d",(fl[i]).flightnum);
           printf("     %-10s",p->customer);
           printf(" %-d\n",p->num);
           ff++;
        }
      p=p->next;
     }
   }
   if(!ff) printf("\n\tNo Match Find");
   getch();

}

3 楼

void create(flightmange *fl,int *length)
{ char na[20],password[]="123456",pa[7],key;
  int m,n,i;
  flightdetail *p;
  printf("Enter Password:");
  while(1)
  {
      for(i=0;i<7;i++)
  {
     pa[i]=getch();
     if(pa[i]=='\r') {pa[i]='\0';break; }
     printf("*");
  }
  if(strcmp(password,pa)==0)
  {
      printf("\n\nPassword Correct!");getch();break;}
  else
  {
      printf("\nPassword Invaild\n\t\tPress <Y> to Retry Or Press <N> to Abort");
  do
            {
            key=getch();
            }while(key!='Y'&&key!='y'&&key!='n'&&key!='N');

       if(key=='n'||key=='N')
       {
          printf("\n\tOperation Failed ,Thanks for Using");
          getch();
          return;
       }
       else{
             system("cls");
             printf("Enter Password:\n\n");
             continue;
            }

  }
  }
system("cls");
  printf("Enter the Flight Name:");
  scanf("%s",na);
  printf("\nEnter the Flight Num:");
  scanf("%d",&n);
  printf("\nEnter the Tickets Quantity:");
  scanf("%d",&m);
  strcpy(fl[*length].name,na);
  fl[*length].flightnum=n;
  fl[*length].ticket=m;
  fl[*length].booked=0;
  p=(flightdetail *)malloc(sizeof(flightdetail));
  p->next=NULL;
  fl[*length].next=p;
  printf("\n\n\n");
  printselect(fl,*length,n);
  (*length)++;
  getch();
}
void main()
{  char fn[N][20]={"Ningbo<->London","Ningbo<->Shanghai","Ningbo<->Beijing","Ningbo<->Tokyo","Ningbo<->New York"};
   int fnum[N]={1001,1002,1003,1004,1005},tic[N]={11,42,32,34,12};
   char key;
   flightmange *fl;
   int size=50,length=N;
   fl=(flightmange *)malloc(size*sizeof(flightmange));
   init(fl,fn,fnum,tic) ;
   system("cls");
   printf("\t\t\t* * * * * * * * * *\n");
   printf("\t\t\tTicket Mange System\n\n\t\t\t\  Programed by Yang Rida\n");
   printf("\t\t\t* * * * * * * * * *\n");

   printf("\nInfo:This Programe was Compiled With Visual C++,\n     And Has Been Tested On TurboC2.0");
   getch();
   printf("\nInitialize Success!\n\Now Press Any Key to Continue");
   getch();
   system("cls");
   welcome();
   while((key=getch())!='6')
   {
      switch(key)
      {   case '1' :system("cls");create(fl,&length);system("cls");welcome();break;
          case '2' :system("cls");booktic(fl,&length);system("cls");welcome();break;
          case '3' :system("cls");returntic(fl,&length);system("cls");welcome();break;
          case '4' :system("cls");printall(fl,&length);system("cls");welcome();break;
          case '5' :system("cls");search(fl,&length);system("cls");welcome();break;
          default :;
      }
      }
}

4 楼

俺去机房试试^_^

5 楼

怎么有错误啊!???
怎么弄的!
什么未定以的错误

6 楼

老大,你好。
我借用了一下你的杰作。
被老师发现,要再添加一项功能:删除航班
在这里,向你求救。。。。

7 楼


哪个实力强的大哥或大姐帮我按以下要求编个啊 我想过个好年 谢谢了

&#61548;     查询航线(航班号查询)
1、当旅客在主菜单输入3并按回车键既选择查询航线后系统就进入查询航线系统。
2、查询航线系统界面设置为一个矩形框,在开头显示WELCOME,下面是一个语句please  input  hangbanhao:  
3、当旅客输入航班库里的一个航班号后再按下回车键,系统就跳转界面显示此航班的航线;若旅客输入有误则系统还是此界面请旅客继续输入。采用循环处理。
4、按0再回车退出此系统返回主菜单。

8 楼


请大侠能不能帮小女子,改一下程序,使能够符合下面的条件,不要用链表,C
真是感激涕淋了,请发到sky10866810@126.com希望能在1月9日晚上之前给我,
真的谢谢拉,有点没完成也不要紧,最好多作些说明.
大家帮帮忙,编一小段也可以,期末考试啊


§    航班座位订票系统,包括以下功能:
&#61611;    查询航班信息
&#61611;    增加航班信息
&#61611;    修改航班信息
&#61611;    购买机票
&#61611;    退票
&#61611;    修改机票信息
&#61611;    退出 


要求
§    1.航班信息包括航班号、目的地、起飞时间、到达时间、票价、座位数量、及座位编号方法等信息,起飞地就是上海。要求可以按照前面三个变量进行航班的查询及修改。要求超过20条以上的航班信息。
§    2.买票时要求记录订票人姓名、身份证、航班号、座位号,其它信息从航班信息中copy过来,座位号为最先买的,为最前面的号,要求所有买票信息能够记录下来,并且机票要求打印(不是用纸打印,而是在屏幕上用较好的格式显示出来)出来。如果该航班已经无票,可以提供相关可选择航班;订单应该编号。
§    3.修改机票可以修改航班号和座位号;
§    4.要求程序格式清晰,尽量多利用函数,程序解释要多;
§    5.同时用结构体和文件者,并且程序正确,并且非抄袭者无条件得满分

9 楼

你好厉害啊  初学者写这么好的程序啊  你QQ多少啊 我是学计算机的 想请教你问题

10 楼


hehekankan

我来回复

您尚未登录,请登录后再回复。点此登录或注册