航空客运订票系统

通过此系统可以实现如下功能:

录入:可以录入航班情况(数据可以存储在一个数据文件中,数据结构、具体数据自定);

查询:可以查询某个航线的情况(如,输入航班号,查询起降时间,起飞抵达城市,航班票价,票价折扣,确定航班是否满仓);可以输入起飞抵达城市,查询飞机航班情况;

订票:(订票情况可以存在一个数据文件中,结构自己设定)可以订票,如果该航班已经无票,可以提供相关可选择航班;

退票:可退票,退票后修改相关数据文件;客户资料有姓名,证件号,订票数量及航班情况,订单要有编号。

修改航班信息:当航班信息改变可以修改航班数据文件

要求:根据以上功能说明,设计航班信息,订票信息的存储结构,设计程序完成功能;

 

#include<stdio.h>
#include<stdlib.h>
#include<math.h>
#include<string.h>
typedef struct plane
{
    char planenum[30];
    char time[20];
    char type[30];
    char arrivepoint[20];
    char  price[4];
    char discount[4];
    char rest[4];
} planeline;
planeline line[1000];
typedef struct buyinfo
{
    char buynum[10];
    char name[20];
    char card[20];
    char planenum[20];
    char count[4];
    char nowstate[10];
} buy;
buy dingdan;
int i;//记录录入航班信息总数
Input()//录入航班信息
{
    FILE*fp;
    if((fp=fopen("F:\\planeline.txt","r"))==NULL)
    {
        printf("cannot open the file\n");
        exit(0);
    }
    i=0;
    while(!feof(fp))
    {
        fscanf(fp,"%s%s%s%s%s%s%s",line[i].planenum,line[i].time,line[i].type,line[i].arrivepoint,line[i].price,line[i].discount,line[i].rest);
        i++;
    }
    i--;
    fclose(fp);
    printf("录入成功!\n");
    return;
}
Find()//查询航班情况
{
    int s;
    while(1)
    {
        printf("***************************************************\n");
        printf("     1、按航班号查询     2、按抵达地点查询\n");
        printf("     0、退出\n");
        printf("***************************************************\n");
        scanf("%d",&s);
        if(s==0)break;
        else if(s==1)
        {
            int j,ok=1;
            char a[30];//记录的航班号
            printf("请输入航班号:");
            scanf("%s",a);
            for(j=0; j<i; j++)
            {
                if(strcmp(a,line[j].planenum)==0)
                {
                    ok=0;
                    printf("***********************************************************************\n");
                    printf("航班号     航班时间        飞机类型     抵达地点 价格 折扣 剩余机票\n");
                    printf("%s    %s     %s     %s   %s  %s     %s\n",line[j].planenum,line[j].time,line[j].type,line[j].arrivepoint,line[j].price,line[j].discount,line[j].rest);
                    printf("***********************************************************************\n");
                }
            }
            if(ok)printf("别捣乱!哪有这个航班\n");
        }
        else if(s==2)
        {
            int j,ok=1;
            char a[30];//记录抵达地点
            printf("请输入抵达地点:");
            scanf("%s",a);
            for(j=0; j<i; j++)
            {
                if(strcmp(a,line[j].arrivepoint)==0)
                {
                    printf("***********************************************************************\n");
                    printf("航班号     航班时间        飞机类型     抵达地点 价格 折扣 剩余机票\n");
                    printf("%s    %s     %s     %s   %s  %s     %s\n",line[j].planenum,line[j].time,line[j].type,line[j].arrivepoint,line[j].price,line[j].discount,line[j].rest);
                    printf("***********************************************************************\n");
                    ok=0;
                }
                if(ok)printf("别捣乱!哪有去这个地方的!\n");
            }
        }
    }
}
Buycard()//订票
{
    int j,k,l;
    FILE *f1;
    FILE *fp;
    printf("请先输入您的真实信息\n");
    printf("姓名:");
    scanf("%s",dingdan.name);
    printf("身份证号:");
    scanf("%s",dingdan.card);
    while(1)
    {
        if((f1=fopen("F:\\customer.txt","a"))==NULL)
        {
            printf("cannot open the file\n");
            exit(0);
        }
        printf("请输入想定的航班号: (并以over结束)");
        scanf("%s",dingdan.planenum);
        if(strcmp(dingdan.planenum,"over")==0)break;
        int ok=1;
        for(j=0; j<i; j++)
        {
            if(strcmp(dingdan.planenum,line[j].planenum)==0)
            {
                ok=0;
                if(line[j].rest[0]!='0')
                {
                    printf("***********************************************************************\n");
                    printf("航班号     航班时间        飞机类型     抵达地点 价格 折扣 剩余机票\n");
                    printf("%s    %s     %s     %s   %s  %s     %s\n",line[j].planenum,line[j].time,line[j].type,line[j].arrivepoint,line[j].price,line[j].discount,line[j].rest);
                    printf("***********************************************************************\n");
                    printf("确定订本航班机票吗?y?n?\n");
                    getchar();
                    if(getchar()=='y')
                    {
                        strcpy(dingdan.nowstate,"成功\0");
                        printf("请输入您要订的机票数量: ");
                        scanf("%s",dingdan.count);
                        printf("订票成功!\n");
                        int l1=strlen(line[j].rest);
                        int l2=strlen(dingdan.count);
                        int y=0;
                        int s=0;
                        int t=1;
                        int x=0;
                        int p;
                        char a[5];
                        for( p=0; p<l1; p++)
                        {
                            s=(int)line[j].rest[p]-48;
                            x=x*10+s;
                        }
                        for( p=0; p<l2; p++)
                        {
                            s=(int)dingdan.count[p]-48;
                            y=y*10+s;
                        }
                        x=x-y;
                        p=0;
                        while(x)
                        {
                            y=x%10+48;
                            a[p]=(char)y;
                            p++;
                            x=x/10;
                        }
                        for(t=p-1; t>=0; t--)
                        {
                            line[j].rest[p-1-t]=a[t];
                        }
                        line[j].rest[p]='\0';
                        for(l=0,k=10; k<=17; l++,k++)
                        {
                            dingdan.buynum[l]=dingdan.card[k];
                        }
                        fprintf(f1,"%s %-6s %s %s %s %-6s\n",dingdan.buynum,dingdan.name,dingdan.card,dingdan.planenum,dingdan.count,dingdan.nowstate);
                        printf("%s %-6s %s %s %s %-6s\n",dingdan.buynum,dingdan.name,dingdan.card,dingdan.planenum,dingdan.count,dingdan.nowstate);
                        if((fp=fopen("F:\\planeline.txt","r+"))==NULL)
                        {
                            printf("cannot open the file\n");
                            exit(0);
                        }
                        fseek(fp,j*49,0);
                        fprintf(fp,"%s %s %s %s %s %s %s ",line[j].planenum,line[j].time,line[j].type,line[j].arrivepoint,line[j].price,line[j].discount,line[j].rest);
                        fclose(fp);

                    }
                    else printf("本订单已取消!\n");
                    break;
                }
                else
                {
                    planeline b[100];
                    int z=0;
                    printf("你来晚了,看看其他的吧\n");
                    printf("***********************************************************************\n");
                    printf("航班号     航班时间        飞机类型     抵达地点 价格 折扣 剩余机票\n");
                    for(k=0; k<i; k++)
                    {
                        if(strcmp(line[k].arrivepoint,line[j].arrivepoint)==0)
                        {
                            if(line[k].rest[0]!='0'&&k!=j)
                            {
                                printf("%s    %s     %s     %s   %s  %s     %s\n",line[k].planenum,line[k].time,line[k].type,line[k].arrivepoint,line[k].price,line[k].discount,line[k].rest);
                                strcpy(b[z].planenum,line[k].planenum);
                                z++;
                            }
                        }
                    }
                    printf("***********************************************************************\n");
                    printf("请输入想要订的机票航班号");
                    scanf("%s",dingdan.planenum);
                    int g=0;
                    for(k=0; k<z; k++)
                    {
                        if(strcmp(b[k].planenum,dingdan.planenum)==0)
                        {
                            g=1;
                            printf("请输入您要订的机票数量\n");
                            scanf("%s",dingdan.count);
                            printf("订票成功!\n");
                            int l1=strlen(line[k].rest);
                            int l2=strlen(dingdan.count);
                            int y=0;
                            int s=0;
                            int t=1;
                            int x=0;
                            int p;
                            char a[5];
                            for( p=0; p<l1; p++)
                            {
                                s=(int)line[k].rest[p]-48;
                                x=x*10+s;
                            }
                            for( p=0; p<l2; p++)
                            {
                                s=(int)dingdan.count[p]-48;
                                y=y*10+s;
                            }
                            x=x-y;
                            p=0;
                            while(x)
                            {
                                y=x%10+48;
                                a[p]=(char)y;
                                p++;
                                x=x/10;
                            }
                            for(t=p-1; t>=0; t--)
                            {
                                line[k].rest[p-1-t]=a[t];
                            }
                            line[k].rest[p]='\0';
                            for(l=0,k=10; k<=18; l++,k++)
                            {
                                dingdan.buynum[l]=dingdan.card[k];
                            }
                            fprintf(f1,"%s %-6s %s %s %s %-6s\n",dingdan.buynum,dingdan.name,dingdan.card,dingdan.planenum,dingdan.count,dingdan.nowstate);
                            printf("%s %-6s %s %s %s %-6s\n",dingdan.buynum,dingdan.name,dingdan.card,dingdan.planenum,dingdan.count,dingdan.nowstate);
                            if((fp=fopen("F:\\planeline.txt","r+"))==NULL)
                            {
                                printf("cannot open the file\n");
                                exit(0);
                            }
                            fseek(fp,j*49,0);
                            fprintf(fp,"%s %s %s %s %s %s %s ",line[i].planenum,line[i].time,line[1].type,line[i].arrivepoint,line[i].price,line[i].discount,line[i].rest);
                            fclose(fp);
                        }
                        if(g==0)printf("你又调皮了!\n");
                    }
                }
            }
        }
        if(ok)printf("这个真没有!\n");
        fclose(f1);
    }
}
Return()//退票
{
    FILE*fp;
    FILE*f1;
    printf("请输入您的订单号:\n");
    char a[30];//记录订单号
    scanf("%s",a);
    int j,k;
    int x;//记录航班在文件里的位置
    int l=0;//记录订单在文件里的位置
    if((f1=fopen("F:\\customer.txt","r+"))==NULL)
    {
        printf("cannot open the file\n");
        exit(0);
    }
    l=0;
    while(!feof(f1))
    {
        fscanf(f1,"%s%s%s%s%s%s",dingdan.buynum,dingdan.name,dingdan.card,dingdan.planenum,dingdan.count,dingdan.nowstate);
        if(strcmp(dingdan.buynum,a)==0)
        {
            printf("确定取消此订单?y?n?\n");
            getchar();
            if(getchar()=='y')
            {
                strcpy(dingdan.nowstate,"已取消");
                printf("取消成功!\n");
                if((fp=fopen("F:\\planeline.txt","r+"))==NULL)
                {
                    printf("cannot open the file\n");
                    exit(0);
                }
                fseek(f1,l*52,0);
                fprintf(f1,"%s %-6s %s %s %s %-6s",dingdan.buynum,dingdan.name,dingdan.card,dingdan.planenum,dingdan.count,dingdan.nowstate);
                fclose(f1);
                x=0;
                while(!feof(fp))
                {
                    fscanf(fp,"%s%s%s%s%s%s%s",line[x].planenum,line[x].time,line[x].type,line[x].arrivepoint,line[x].price,line[x].discount,line[x].rest);
                    if(strcmp(dingdan.planenum,line[x].planenum)==0)
                    {
                        int l1=strlen(line[x].rest);
                        int l2=strlen(dingdan.count);
                        int y=0;
                        int s=0;
                        int t=1;
                        int o=0;
                        int p;
                        for( p=0; p<l1; p++)
                        {
                            s=(int)line[x].rest[p]-48;
                            o=o*10+s;
                        }
                        for( p=0; p<l2; p++)
                        {
                            s=(int)dingdan.count[p]-48;
                            y=y*10+s;
                        }
                        o=o+y;
                        p=0;
                        while(o)
                        {
                            y=o%10+48;
                            a[p]=(char)y;
                            p++;
                            o=o/10;
                        }
                        for(t=p-1; t>=0; t--)
                        {
                            line[x].rest[p-1-t]=a[t];
                        }
                        line[x].rest[p]='\0';
                        fseek(fp,x*49,0);
                        fprintf(fp,"%s %s %s %s %s %s %s\n",line[x].planenum,line[x].time,line[x].type,line[x].arrivepoint,line[x].price,line[x].discount,line[x].rest);
                        fclose(fp);
                        return;
                    }
                    x++;
                }
                printf("订单已经取消\n");
            }
            else
            {
                printf("订单未取消\n");
            }
        }
        l++;
    }
}
Fix()//修改航班信息
{
    FILE*fp;
    int j,k,l,x;
    int s;//记录选项序号
    char a[20];//记录需要修改的航班号
    while(1)
    {
        printf("1、新增航线;2、取消航线;3、修改已有航班信息;0、退出\n");
        if((fp=fopen("F:\\planeline.txt","r+"))==NULL)
        {
            printf("cannot open file\n");
            exit(0);
            return;
        }
            scanf("%d",&s);
            if(s==0)break;
            else if(s==1)
            {
                printf("请输入要添加的航线信息:航班号 航班时间 飞机类型 抵达地点 价格 折扣 剩余机票,最后输入“over”结束\n");
                while(1)
                {
                    scanf("%s",line[i].planenum);
                    if(strcmp(line[i].planenum,"over")!=0)
                    {
                        scanf("%s%s%s%s%s%s",line[i].time,line[i].type,line[i].arrivepoint,line[i].price,line[i].discount,line[i].rest);
                        fprintf(fp,"%s %s %s %s %s %s %-3s\n",line[i].planenum,line[i].time,line[i].type,line[i].arrivepoint,line[i].price,line[i].discount,line[i].rest);
                        i++;
                    }
                    else break;
                }
                printf("增加成功!\n");
            }
            else if(s==2)
            {
                fclose(fp);
                if((fp=fopen("F:\\planeline.txt","w+"))==NULL)
                {
                    printf("cannot open file\n");
                    exit(0);
                    return;
                }
                printf("请输入要取消的航班号:");
                scanf("%s",a);
                for(x=0; x<i; x++)
                {
                    if(strcmp(a,line[x].planenum)!=0)
                    {
                        fprintf(fp,"%s %s %s %s %s %s %s\n",line[x].planenum,line[x].time,line[x].type,line[x].arrivepoint,line[x].price,line[x].discount,line[x].rest);
                    }
                }
                i--;
                printf("取消成功!\n");
                for(x=0;x<i;x++)
                fscanf(fp,"%s%s%s%s%s%s%s",line[x].planenum,line[x].time,line[x].type,line[x].arrivepoint,line[x].price,line[x].discount,line[x].rest);
            }
            else if(s==3)
            {
                while(1)
                {
                    printf("请输入要修改的航班号:以over结束\n");
                    scanf("%s",a);
                    if(strcmp(a,"over")==0)break;
                    for(x=0; x<i; x++)
                    {
                        if(strcmp(a,line[x].planenum)==0)
                        {
                            printf("请输入新的信息。\n");
                            printf("格式为:航班号 航班时间 飞机类型 抵达地点 价格 折扣 剩余机票\n");
                            scanf("%s%s%s%s%s%s%s\n",line[x].planenum,line[x].time,line[x].type,line[x].arrivepoint,line[x].price,line[x].discount,line[x].rest);
                            fseek(fp,x*49,0);
                            fprintf(fp,"%s %s %s %s %s %s %-3s",line[x].planenum,line[x].time,line[x].type,line[x].arrivepoint,line[x].price,line[x].discount,line[x].rest);
                            printf("修改成功!\n");
                        }
                    }
                }
            }
        fclose(fp);
    }
}
int main()
{
    int s;
    while(1)
    {
        printf("***************************************************\n");
        printf("     1、录入航班信息     2、查询航班信息\n");
        printf("     3、订票             4、退票\n");
        printf("     5、修改航班信息     0、退出\n");
        printf("***************************************************\n");
        scanf("%d",&s);
        if(s==0)break;
        switch(s)
        {
        case 1:
            Input();
            break;
        case 2:
            Find();
            break;
        case 3:
            Buycard();
            break;
        case 4:
            Return();
            break;
        case 5:
            Fix();
            break;
        default:
            printf("别捣乱!\n");
        }

    }
}

  • 1
    点赞
  • 25
    收藏
    觉得还不错? 一键收藏
  • 5
    评论
【基本要求】 (1)每条航线所涉及的信息有:终点站名、航班号机号、行周日(星期几)、乘员定额、余票量、已订票的客户名单(包括姓名、订票量、舱位等级1,2或3)以及等候替补的客户名单(包括姓名、所需票量); (2)作为示意系统,全部数据可以只放在内存中; (3)系统能实现的操作和功能如下: ①查询航线:根据旅客提出的终点站名输出下列信息:航班号机号、星期几行,最近一天航班的日期和余票额; ②承办订票业务:根据客户提出的要求(航班号、订票数额)查询该航班票额情况,若尚有余票,则为客户办理订票手续,输出座位号;若已满员或余票额少于订票额,则需重新询问客户要求。若需要,可登记排队候补; ③承办退票业务:根据客户提供的情况(日期、航班),为客户办理退票手续,然后查询该航班是否有人排队候补,首先询问排在第一的客户,若所退票额能满足他的要求,则为他办理订票手续,否则依次询问其他排队候补的客户。 【测试数据】 由读者自行指定。 【实现提示】 两个客户名单可分别由线性表和队列实现。为查找方便,已订票客户的线性表应按客户姓名有序,并且,为插入和删除方便,应以链表作存储结构。由于预约人数无法预计,队列也应以链表作存储结构。整个系统需汇总各条航线的情况登录在一张线性表上,由于航线基本不变,可采用顺序存储结构,并按航班有序或按终点站名有序。每条航线是这张表上的一个记录,包含上述8个域、其中乘员名单域为指向乘员名单链表的头指针,等候替补的客户名单域为分别指向队头和队尾的指针。
航空客运订票系统 特点:超详细的JAVA代码注释,代码保护性,无论输入什么都不会崩溃; 【问题描述】航空客运订票的业务活动包括:查询航线、添加航班,客票预订和办理退票等七大功能,已实现操作文件。试设计一个航空客运订票系统,以使上述业务可以借助计算机来完成。 【基本要求】 (1)每条航线所涉及的信息有:终点站名、航班号机号、行周日(星期几)、乘员定额、余票量、已订票的客户名单(包括姓名、订票量、舱位等级1,2或3)以及等候替补的客户名单(包括姓名、所需票量); (2)系统能实现的操作和功能如下: ①录入:可以录入航班情况,全部数据可以只放在内存中,最好存储在文件中; ②查询航线:根据旅客提出的终点站名输出下列信息:航班号机号、星期几行,最近一天航班的日期和余票额; ③承办订票业务:根据客户提出的要求(航班号、订票数额)查询该航班票额情况,若尚有余票,则为客户办理订票手续,输出座位号;若已满员或余票额少于订票额,则需重新询问客户要求。若需要,可登记排队候补; ④承办退票业务:根据客户提供的情况(日期、航班),为客户办理退票手续,然后查询该航班是否有人排队候补,首先询问排在第一的客户,若所退票额能满足他的要求,则为他办理订票手续,否则依次询问其他排队候补的客户。 【测试数据】由读者自行指定。 【实现提示】两个客户名单可分别由线性表和队列实现。为查找方便,已订票客户的线性表应按客户姓名有序,并且,为插入和删除方便,应以链表作存储结构。由于预约人数无法预计,队列也应以链表作存储结构。整个系统需汇总各条航线的情况登录在一张线性表上,由于航线基本不变,可采用顺序存储结构,并按航班有序或按终点站名有序。每条航线是这张表上的一个记录,包含上述8个域、其中乘员名单域为指向乘员名单链表的头指针,等候替补的客户名单域为分别指向队头和队尾的指针。 【选作内容】当客户订票要求不能满足时,系统可向客户提供到达同一目的地的其他航线情况。读者还可充分发挥自己的想象力,增加你的系统的功能和其他服务项目 I/O流操作时用到了GSON,解压即可看到,如果发现报错,读者可以配置一下Gson的路径,在属性,JAVA构建路径中删除原有的三个GSON库,添加外部,下载的GSON库。如果不用可以将Main类中new ReadFlightLine();注释掉即可。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 5
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值