(1)建立航班信息和乘客信息,每次航班的信息包括:航班号、起飞城市、到达城市、起飞时间、到达时间、机票价格、机票折扣、机票剩余数量;

每位乘客的信息包括:姓名、身份证号、性别、购买机票数、乘坐航班航班号;

(2)添加模块:可以连续添加多条航班信息;

(3)查找模块:乘客可输入乘坐航班的航班号或目的地来查找已订航班的详细信息;

(4)订票模块:乘客可输入目的地来查看已有航班信息,然后可以选择自己想要预定的航班,然后输入个人信息来预定航班;

(5)修改模块:可通过输入航班的航班号来修改该航班的所有信息;

(6)退票模块:乘客可通过输入个人信息来查看已预订航班,然后可决定是否退票;

(7)显示模块:可一键显示所有航班信息;

(8)推荐模块:乘客可通过输入起飞城市和期望出发时间来获取系统推荐的航班及其详细信息;

(9)保存模块:只要输入信息就会即时自动将信息(航班信息或乘客信息)保存至相应文件夹;

(10)时间模块:实时查询当前时间功能。

一、主模块

#include <stdio.h>
#include <stdlib.h>
#include "airplane.h"
int main(int argc, char *argv[]) {
    int item;
    while(1){
        Menu();
        printf("Please input your choice(0-8): \n");
        scanf("%d",&item);
        switch(item){
            case 1:Insert();
            break;
            case 2:Search();
            break;
            case 3:Book();
            break;
            
            case 4:Modify();
            break;
            case 5:ShowAll();
            break;
            
            case 6: Recommend();
            break;
            
            case 7:Refund();
            break;
            
            case 8: CurrentTime();
            break;
            
            case 0:
            exit(0);
        }
    printf("Please input any key to continue\n");
    system("pause");
    system("cls");
    }
    return 0;
}

二、结构类型定义

#ifndef AIRPLANE_H
#define AIRPLANE_H
struct airplane{
    int fnum;
    char scity[20];
    char acity[20];
    char stime[20];
    char atime[20];
    float price;
    float discount;
    float tnum;
};
struct people{
    char name[20];
    int pid;
    char sex[10];
    int btnum;
    int fnum1;
};
void Menu();
void Insert();
void Search();
void Book();
void Modify();
void ShowAll();
void Recommend();
void Refund();
void CurrentTime();
#endif
三、菜单模块

#include<stdio.h>
void Menu(){
    int i;
    printf("\n\t\tWelcome to the Flight Booking System\n\n");
    printf("********************************************************************\n");
    printf("1.Insert flights\t\t5.Show flights\t\t\n");
    printf("2.Search flights   \t\t6.Recommend flights\t\n");
    printf("---------------\t\t---------------\t\t----------------\n");
    printf("3.Book tickets  \t\t7.Refund tickets  \t0.Exit\n");
    printf("4.Modify flight data\t\t8.Show current time\n");
    printf("********************************************************************\n\n");
   
    
}

四、添加模块

#include<stdio.h>
#include<stdlib.h>
#include"airplane.h"
void Insert(){
    int n,i;
    FILE *fp;
    if((fp=fopen("airplane.dat","ab+"))==NULL){
        printf("Can not open file\n");
        exit(0);
    }
    struct airplane air;
    printf("Please input the number of airplane: ");
    scanf("%d",&n);
    printf("Please input the information as instructed:\n");
    for(i=0;i<n;i++){
        printf("FlightNum(-1-end)||StartCity||ArrivalCity||StartTime(00:00)||ArrivalTime(00:00)||Price||Discount(0-9)||Ticketnum\n");
         scanf("%d     %s     %s     %s     %s     %f     %f     %f",&air.fnum,air.scity,air.acity,air.stime,air.atime,&air.price,&air.discount,&air.tnum);
        fwrite(&air,sizeof(struct airplane),1,fp);
    }
    fclose(fp);
    
    
    
}

五、查询模块

#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include"airplane.h"
void Search()
{    FILE *fp;
    if((fp=fopen("airplane.dat","ab+"))==NULL){
        printf("Can not open file\n");
        exit(0);
    }
      long begin,end,lcount;
      fseek(fp,0L,SEEK_SET);
      begin=ftell(fp);
      fseek(fp,0L,SEEK_END);
      end=ftell(fp);
      lcount=(end-begin)/sizeof(struct airplane);//所有文件记录数
      rewind(fp);
     int choice;
     int Fnum;//要输入的航班号
     char Pacity[20];//目的地
     struct airplane air[lcount],*p=air;
     fread(p,sizeof(struct airplane),lcount,fp);
     printf("Please input the search method you want:1.flight number  2.Arrival city\n");
     scanf("%d",&choice);
     if(choice==1){//按照航班号
          printf("Please input your flight number:\n");
          scanf("%d",&Fnum);
          printf("FlightNum || StartCity ||   ArrivalCity ||   StartTime ||   ArrivalTime ||   Price ||   Discount ||   Ticketnum\n");
          printf("----------||-----------||---------------||-------------||---------------||---------||------------||------------||\n");
          while(p!=NULL){
              if(p->fnum==Fnum){
                  printf("%d         %s        %s         %s         %s           %.2f          %.0f          %.0f\n",p->fnum,p->scity,p->acity,p->stime,p->atime,p->price,p->discount,p->tnum);
                  break;
            }else{
                p++;
            }
            if(p==NULL){
                printf("The flight number is not found\n");
                return;
            }
          }
     }else if(choice==2){//按照到达城市
        printf("Please input your destination:\n");
        scanf("%s",Pacity);     
          printf("FlightNum||StartCity||ArrivalCity||StartTime(00:00)||ArrivalTime(00:00)||Price||Discount(0-9)|| Ticketnum\n");
          printf("---------||---------||-----------||----------------||------------------||-----||-------------||----------||\n");
          int i;
          for(i=0;i<lcount;i++){
              if(strcmp(air[i].acity,Pacity)==0){
                  printf("%d     %s       %s        %s              %s             %.2f           %.0f           %.0f\n",air[i].fnum,air[i].scity,air[i].acity,air[i].stime,air[i].atime,air[i].price,air[i].discount,air[i].tnum);
              }
           }
        }else{
            printf("Please input the correct selection!\n");
        }
     
     
 
}

六、预订模块

#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include"airplane.h"
void Book(){
    FILE *fp1;
     if((fp1=fopen("people.dat","ab+"))==NULL){
         printf("can not open file\n");
         exit(0);
     }
     FILE *fp;
     if((fp=fopen("airplane.dat","ab+"))==NULL){
         printf("can not open file\n");
         exit(0);
     }
      long begin,end,lcount;
      fseek(fp,0L,SEEK_SET);
      begin=ftell(fp);
      fseek(fp,0L,SEEK_END);
      end=ftell(fp);
      lcount=(end-begin)/sizeof(struct airplane);//所有文件记录数
      rewind(fp);
     struct airplane air[lcount],*p=air;
     fread(p,sizeof(struct airplane),lcount,fp);
     char Pacity[20];
     printf("Please input your destination:\n");
        scanf("%s",Pacity);    
          printf("There are the flights you can choose:\n"); 
          printf("FlightNum||StartCity||ArrivalCity||StartTime(00:00)||ArrivalTime(00:00)||Price||Discount(0-9)||Ticketnum\n");
          printf("---------||---------||-----------||----------------||------------------||-----||-------------||---------||\n");
          int i,c;
          for(i=0;i<lcount;i++){
              if(strcmp(air[i].acity,Pacity)==0){
                  printf("%d      %s       %s         %s          %s             %.2f        %.0f         %.0f\n",air[i].fnum,air[i].scity,air[i].acity,air[i].stime,air[i].atime,air[i].price,air[i].discount,air[i].tnum);
              }
           }
        int Fnum;
        int choice;
        int m,j;
        printf("Please input the flight number you selsected:\n");//输入选择的航班号
        scanf("%d",&Fnum);
        while(p!=NULL){
              if(p->fnum==Fnum){
                  printf("%d              %s         %s             %s           %s          %.2f       %.0f         %.0f\n",p->fnum,p->scity,p->acity,p->stime,p->atime,p->price,p->discount,p->tnum);
                  printf("Is this your choice?(1.YES/Other Figures.NO)\n");
                  scanf("%d",&choice);
                  if(choice==1){
                      printf("Please input the number of tickets you want book:\n");//输入订票数
                      scanf("%d",&m);
                      if(m>p->tnum){
                          printf("Insufficient number of tickets,Please operate again\n");
                          break;
                      }
                      struct people pe;
                      printf("Please enter the information as instructed:\n");
                      for(j=0;j<m;j++){
                          printf("IDnumber     ||     Sex(M/F)     ||     NAME     ||     Fnumber(-1-end)     ||     BookTicketNumber\n");
                           scanf("%d                     %s                %s                 %d                           %d",&pe.pid,pe.sex,pe.name,&pe.fnum1,&pe.btnum);
                           fwrite(&pe,sizeof(struct people),1,fp1);
                      }
                      fclose(fp1);
                      printf("Success!\n");
                      break;
                  }else{
                      printf("Please operate again\n");
                      break;
                  }
            }else{
                p++;
            }
       }
    }

七、修改模块

#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include"airplane.h"
void Modify()
{
    FILE *fp;
    if((fp=fopen("airplane.dat","ab+"))==NULL){
        printf("Can not open file\n");
        exit(0);
    }
    long begin,end,lcount;
      fseek(fp,0L,SEEK_SET);
      begin=ftell(fp);
      fseek(fp,0L,SEEK_END);
      end=ftell(fp);
      lcount=(end-begin)/sizeof(struct airplane);//所有文件记录数
      rewind(fp);
      int Fnum;
      char Nscity[20],Nacity[20],Nstime[20],Natime[20];
      float Nprice,Ndiscount,Ntnum;
      struct airplane air[lcount],*p=air;
      fread(p,sizeof(struct airplane),lcount,fp);
      fclose(fp);
      if(lcount==0){
          printf("No data to modify\n");
      }else{
          printf("Please input the flight number you want to modify: ");
          int i;
        int pm=0;
          scanf("%d",&Fnum);
      for(i=0;i<lcount;i++,p++){
          if(p->fnum==Fnum){
              pm=1;
              break;
          }
      }
    if(pm==1){
        printf("The information you want to modify is as follow:\n");
        printf("StartCity||ArrivalCity||StartTime(00:00)||ArrivalTime(00:00)||Price||Discount(0-9)||Ticketnum\n");
        printf("%s          %s        %s            %s          %.2f          %.0f             %.0f\n",p->scity,p->acity,p->stime,p->atime,p->price,p->discount,p->tnum);
        printf("Please input the NEW information as instructed:\n");
        printf("Please input the NEW StartCity: ");
        scanf("%s",Nscity);
        strcpy(p->scity,Nscity);
        printf("Please input the NEW ArrivalCity: ");
        scanf("%s",Nacity);
        strcpy(p->acity,Nacity);
        printf("Please input the NEW StartTime: ");
        scanf("%s",Nstime);
        strcpy(p->stime,Nstime);
        printf("Please input the NEW ArrivalTime: ");
        scanf("%s",Natime);
        strcpy(p->atime,Natime);
        printf("Please input the NEW Price: ");
        scanf("%f",&Nprice);
        p->price=Nprice;
        printf("Please input the NEW Discount: ");
        scanf("%f",&Ndiscount);
        p->discount=Ndiscount;
        printf("Please input the NEW TicketNumber: ");
        scanf("%f",&Ntnum);
        p->tnum=Ntnum;
        printf("Modify is ok,New data are as follows: \n");
        printf("StartCity||ArrivalCity||StartTime(00:00)||ArrivalTime(00:00)||Price||Discount(0-9)||Ticketnum\n");
        printf("%s          %s        %s            %s          %.2f          %.0f             %.0f\n",p->scity,p->acity,p->stime,p->atime,p->price,p->discount,p->tnum);
    }else{
        printf("NO Data,please input the right flighg number! \n");
    }
    if((fp=fopen("airplane.dat","wb+"))==NULL){
        printf("Can not open file\n");
        exit(0);
    }
    p=air;
    fwrite(p,sizeof(struct airplane),lcount,fp);
    fclose(fp);
    
}
}

八、显示模块

#include<stdio.h>
#include<stdlib.h>
#include"airplane.h"
void ShowAll()
{
    FILE *fp;
     if((fp=fopen("airplane.dat","ab+"))==NULL){
         printf("can not open file\n");
         exit(0);
     }
     struct airplane air;
     fseek(fp,0L,SEEK_SET);
     fread(&air,sizeof(struct airplane),1,fp);
     printf("FlightNum || StartCity ||   ArrivalCity ||   StartTime ||   ArrivalTime ||   Price ||   Discount ||   Ticketnum\n");
     printf("----------||-----------||---------------||-------------||---------------||---------||------------||------------||\n");
     while(!feof(fp)){
     printf("%d             %s          %s       %s          %s             %.2f            %.0f           %.0f\n",air.fnum,air.scity,air.acity,air.stime,air.atime,air.price,air.discount,air.tnum);
        fread(&air,sizeof(struct airplane),1,fp);    
     }
     fclose(fp);
     
}

九、推荐模块

#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include"airplane.h"
void Recommend(){
    FILE *fp;
     if((fp=fopen("airplane.dat","ab+"))==NULL){
         printf("can not open file\n");
         exit(0);
     }
     long begin,end,lcount;
      fseek(fp,0L,SEEK_SET);
      begin=ftell(fp);
      fseek(fp,0L,SEEK_END);
      end=ftell(fp);
      lcount=(end-begin)/sizeof(struct airplane);//所有文件记录数
      rewind(fp);
      struct airplane air[lcount],*p=air;
      fread(p,sizeof(struct airplane),lcount,fp);
      char Pscity[20];
      char Pstime[20];
      printf("Please input your origin: ");
      scanf("%s",Pscity);    
      printf("Please input your take-off time: ");
      scanf("%s",Pstime);
        printf("There are the flights you can choose:\n");
        printf("FlightNum || StartCity ||   ArrivalCity ||   StartTime ||   ArrivalTime ||   Price ||   Discount ||   Ticketnum\n");
        printf("----------||-----------||---------------||-------------||---------------||---------||------------||------------||\n");
        int i;
        for(i=0;i<lcount;i++){
              if(strcmp(air[i].scity,Pscity)==0&&strcmp(Pstime,air[i].stime)<0){
                  printf("%d           %s         %s        %s      %s   %.2f     %.0f         %.0f\n",air[i].fnum,air[i].scity,air[i].acity,air[i].stime,air[i].atime,air[i].price,air[i].discount,air[i].tnum);
              }
              
           }
      
}

十、退票模块

#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include"airplane.h"
extern int iSave;
void Refund()
{
    FILE *fp1;
     if((fp1=fopen("people.dat","ab+"))==NULL){
         printf("can not open file\n");
         exit(0);
     }
     long begin,end,lcount;
      fseek(fp1,0L,SEEK_SET);
      begin=ftell(fp1);
      fseek(fp1,0L,SEEK_END);
      end=ftell(fp1);
      lcount=(end-begin)/sizeof(struct people);//所有文件记录数
      rewind(fp1);
      struct people pe[lcount],*p=pe;
      fread(p,sizeof(struct people),lcount,fp1);
      int Inid;
      printf("Please input your ID: ");
      scanf("%d",&Inid);
      while(p!=NULL){
          if(p->pid==Inid){
          printf("This is your tickets: \n");    
          printf("IDnumber     ||     Sex(M/F)     ||     NAME     ||     Fnumber(-1-end)     ||     BookTicketNumber\n");
          printf("%d                     %s                %s                 %d                           %d\n",p->pid,p->sex,p->name,p->fnum1,p->btnum);
          break;
          }else{
              p++;
          }
      }
      if(p==NULL){
                printf("The flight number is not found\n");
                return;
            }
            int choice;
            printf("Do you want to cancel it?(1.Yes/Other Figures.Exit) :");
            scanf("%d",&choice);
            if(choice==1){
                printf("Cancel Successfully!\n");
            }else{
                printf("Please operate again\n");
            }
        }

十一、时间模块

#include<stdio.h>
#include"airplane.h"
#include<time.h>
void CurrentTime()
{
    time_t Ti;
    Ti=time(NULL);//返回当前日历时间
    printf("The current time is %s \n", ctime(&Ti));//将*Ti中的日历时间转换为当地时间的字符串,并返回指向该字符串指针。
    
}

C语言飞机订票系统(数组版)相关推荐

  1. c语言飞机订票信息查询,C语言飞机订票系统

    <C语言飞机订票系统>由会员分享,可在线阅读,更多相关<C语言飞机订票系统(11页珍藏版)>请在人人文库网上搜索. 1.课程设计课程:数据结构专业班级:XX软件工程XX班姓名: ...

  2. c语言飞机订票系统需求分析,c语言编程 飞机订票管理系统(能看懂就行,一定要运行起来的啊!)...

    1.需求分析 航班信息用文件保存,因而要提供文件的输入输出操作:航班信息浏览功能需要提供显示操作:要查询航线需要提供查找功能:另外要提供键盘式选择菜单以实现功能选择. 2.总体设计 该系统设计为航班信 ...

  3. 航班系统C语言程序流程图,飞机订票系统(C语言代码及流程图)

    飞机订票系统(C语言代码及流程图) 目录 第一部分 源程序---------------------------------------------------3 第二部分 函数流程图-------- ...

  4. 飞机订票系统(C语言版)

    目录 飞机订票系统 一.问题描述 二.功能要求 三.算法提示 四.测试数据 五.其它 六.代码段                                          飞机订票系统    ...

  5. 飞机订票系统c语言大作业,C语言知识学习飞机订票系统

    C语言知识学习飞机订票系统 课程设计 课程:数据结构 专业班级:xx软件工程 xx班 姓名:xx 学号:xxx 姓名:xxx 学号:xxx 设计时间:xxx 指导老师:xxx 课程设计题:飞机订票系统 ...

  6. 飞机订票系统程序设计c语言,C语言课程设计——飞机订票系统源代码

    <C语言课程设计--飞机订票系统源代码>由会员分享,可在线阅读,更多相关<C语言课程设计--飞机订票系统源代码(9页珍藏版)>请在人人文库网上搜索. 1.include/标准输 ...

  7. C语言的飞机订票系统

    C语言的飞机订票系统,适合初学者.其中包含文件的输入输出操作,代码便于阅读.与我的另一篇银行的管理有相同的思想. #include<stdio.h> #include<string. ...

  8. Java版飞机订票系统

    数据结构课程设计题目:          [飞机订票系统]            通过此系统可以实现如下功能: 录入:可以录入航班情况(数据存储在一个数据文件中,数据结构和具体数据自定) 查询:可以查 ...

  9. c语言程序设计飞机,C语言程序设计――飞机订票系统

    <C语言程序设计――飞机订票系统>由会员分享,可在线阅读,更多相关<C语言程序设计――飞机订票系统(7页珍藏版)>请在人人文库网上搜索. 1.C语言程序设计飞机订票系统代码如下 ...

最新文章

  1. mysql监控nginx_mysql和nginx服务是否正常监控脚本
  2. 【JS】//将中文逗号转换为英文逗号
  3. web服务器采用的是什么协议,webservice中采用协议Http,它是指什么意思
  4. 字符串数值的比较 java
  5. Java字符串分割到map_如何在Java中按空格分割字符串并以键值形式存储在map中?...
  6. toadstool sql格式化
  7. springboot和springcloud的基本概念理解
  8. 生产环境mysql主主同步主键冲突处理
  9. 5. 卷2(进程间通信)---Posiz 消息队列
  10. QueueUserWorkItem函数
  11. 基于图像识别的火灾检测系统设计思路流程
  12. 2.4G射频电路设计参考(wifi ble)
  13. 小程序开发流程详细,小程序开发教程
  14. 强化学习过程中对产生的无效动作应该如何进行屏蔽处理?(强化学习中可变的动作空间怎么处理)
  15. Android:微信授权登录与微信分享全解析
  16. 使用Audacity软件对清浊音进行时频分析并描述其特点
  17. Eclipse使用入门
  18. lammps教程:平均值输出fix ave/time命令详解
  19. 戴尔 DELL 游戏笔记本电脑 - Windows 10 关闭或开启功能键 (Fn key)
  20. SAP携手“大数据之都” 共推大数据创新

热门文章

  1. Kurento实战之六:云端录制
  2. 计算机函数公式if or,如何使用IF AND OR条件函数
  3. excel公式中某个参数固定
  4. 各种现代方法和技术在储集层研究中的运用
  5. java线程池的面试题_java线程池 面试题(精简)
  6. speedoffice使用方法-word怎么快速添加空白页
  7. 新零售核心是大数据驱动的线上线下融合
  8. Excel如何快速全选所有图片?
  9. 直接插入排序算法C++实现
  10. phpStudy下载(安装)-图文详解(windows)