| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 862 人关注过本帖
标题:自己做的飞机订票系统不知道哪里错了。。。一直中断。。
只看楼主 加入收藏
zycz2p
Rank: 2
等 级:论坛游民
帖 子:22
专家分:10
注 册:2013-11-12
结帖率:50%
收藏
已结贴  问题点数:16 回复次数:4 
自己做的飞机订票系统不知道哪里错了。。。一直中断。。
程序代码:
#include<stdio.h>

#include<string.h>
#include<stdlib.h>
typedef struct FLIGHT
{
    char plane_num[10];//航班号
    char city1[20];//起飞城市
    char city2[20];//抵达城市
    char time1[20];
    char time2[20];
    int plane_room;//空座数
    float price;
    float zhekou;
    int sit;//满仓否
    struct FLIGHT *next;
}fly;
typedef struct CUSTOMEER
{
    char name[10];
    char ID[20];
    char flight_num[10];//航班号
    int ticket_num;//票数
    int order_num;//订单号
    struct CUSTOMEER *next;
}cus;
typedef struct costomers
{
    cus *head;
    cus*rear;
}customers;  //储存客户节点的链表
void init_fly(fly *P)
{
    P = (fly*)malloc(sizeof(fly));
    if (P == NULL)exit(0);
    P->next = NULL;
}
void init_customers(customers *Q)
{
    Q = (customers*)malloc(sizeof(customers));
    Q->head = (cus*)malloc(sizeof(cus));
    Q->rear = Q->head;
    Q->rear->order_num = 0;
    Q->head->next = NULL;
}
void insert_flight(fly *P, char *plane_num, char *city1, char *city2, char *time1, char *time2, int plane_room, float price, float zhekou, int sit)
{
    fly *q;
    q = (fly*)malloc(sizeof(fly));
    strcpy_s(q->plane_num, plane_num);
    strcpy_s(q->city1, city1);
    strcpy_s(q->city2, city2);
    strcpy_s(q->time1, time1);
    strcpy_s(q->time2, time2);
    q->plane_room = plane_room;
    q->price = price;
    q->zhekou = zhekou;
    q->sit = sit;
    q->next = NULL;
    P->next = q;
    P = P->next;
}
void insert_customers(fly *P, customers *Q, char *name, char *ID, char *flight_num, int ticket_num)
{
    fly *h = (P)->next;
    for (; h != NULL; h = h->next)
    {
        if (strcmp(flight_num, h->plane_num) == 0)
        {
            h->plane_room = h->plane_room - ticket_num;
            if (h->plane_num == 0)
                h->sit = 1;
        }

    }
    cus *q;
    q = (cus*)malloc(sizeof(cus));
    strcpy_s(q->name, name);
    strcpy_s(q->ID, ID);
    strcpy_s(q->flight_num, flight_num);
    q->ticket_num = ticket_num;
    q->next = NULL;
    Q->rear->next = q;
    q->order_num = Q->rear->next->order_num + 1;//生成订单号
    Q->rear = q;
}
void delate_flight(fly *P)
{
    fly *p, *pr;
    char flight_num[10];
    int mark = 1;
    pr = P;
    p = pr->next;
    printf("请输入你要删除的航班号:");
    scanf_s("%s", flight_num,sizeof(flight_num));
    while (p != NULL)
    {
        if (strcmp(flight_num, p->plane_num) == 0)
        {
            pr->next = p->next;
            free(p);
            printf("删除航班%s成功!\n", flight_num);
            mark = 0;
            p = NULL;
        }
        if (pr->next != NULL)
        {
            pr = pr->next;
            p = pr->next;
        }
        if (mark == 1)
            printf("没有要删除的航班\n");
    }

}
int delate_customer(customers *Q, fly *P, char *name, char *ID)
{
    cus *p, *pr;
    fly *q;
    pr = Q->head;
    p = pr->next;
    while (p != NULL)
    {
        if (strcmp(name, p->name) == 0 && strcmp(ID, p->ID) == 0)
        {
            for (q = P->next; q != NULL; q = q->next)
            {
                if (strcmp(p->flight_num, q->plane_num) == 0)
                {
                    q->plane_room = q->plane_room + p->ticket_num;
                    q->sit = 0;
                    break;
                }
            }
            pr->next = p->next;
            free(p);
            printf("顾客%s,%s退票成功\n", name, ID);
            return 1;
        }
        pr = pr->next;
        p = pr->next;
    }
    printf("没有要操作的客户!\n");
    return 0;
}
void creat_fly(fly *P)
{
    fly *p;
    p=P;
    char plane_num[10], city1[20], city2[20], time1[20], time2[20];
    int plane_room, sit, mark = 1;
    float price, zhekou;
    if (p != NULL)
        p = p->next;
    while (mark == 1)
    {
        printf("请输入航班号:");
        scanf_s("%s", plane_num, sizeof(plane_num));
        printf("请输入出发地:");
        scanf_s("%s",city1,sizeof(city1));
        printf("请输入终点站:");
        scanf_s("%s", city2, sizeof(city2));
        printf("请输入起飞时间:");
        scanf_s("%s",time1,sizeof(time1));
        printf("请输入抵达时间:");
        scanf_s("%s",time2,sizeof(time2));
        printf("请输入票价:");
        scanf_s("%f",&price);
        printf("请输入折扣:");
        scanf_s("%f",&zhekou);
        printf("请输入座位数:");
        scanf_s("%d",&plane_room);
        printf("请输入是否满仓(0表示未满,1表示满仓):"); 
        scanf_s("%d",&sit);
        insert_flight(p, plane_num, city1, city2, time1, time2, plane_room, price, zhekou, sit);
        printf("增加航班成功!\n");
        printf("是否继续增加航班(1表示继续,0表示停止):");
        scanf_s("%d", &mark);
    }
}
int city_chaxun(fly *P, char *city1, char *city2)
{
    fly *p = P;
    int mark = 0;
    printf("%-8s%-12s%-12s%-10s%-10s%-8s%-6s%-10s%-8s\n", "航班号", "起飞城市", "终点城市", "起飞时间", "抵达时间", "价格",
        "折扣", "空座数", "满仓否" );
    for (; p != NULL; p = p->next)
    {
        if (strcmp(p->city1, city1) == 0 && strcmp(p->city2, city2) == 0)
        {
            printf("%-8s%-12s%-12s%-10s%-10s%-8.2f%-6.2f%-10d%-8d\n", p->plane_num, p->city1, p->city2, p->time1, p->time2, p->price, p->zhekou, p->plane_room,
                p->sit);
            mark = 1;
        }
    }
    if (mark == 0)
    {
        printf("抱歉没有找到相应航班信息\n");
        return 0;
    }
    return 1;
}
int num_cahxun(fly *P, char *plane_num)
{
    fly *p = P;
    printf("%-8s%-12s%-12s%-10s%-10s%-8s%-6s%-8s%-10s\n", "航班号", "起飞城市", "终点城市", "起飞时间", "抵达时间", "价格",
        "折扣", "空座数", "满仓否");
    for (; p != NULL; p = p->next)
    {
        if (strcmp(p->plane_num, plane_num) == 0)
        {
            printf("%-8s%-12s%-12s%-10s%-10s%-8.2f%-6.2f%-10d%-8d\n", p->plane_num, p->city1, p->city2, p->time1, p->time2, p->price, p->zhekou, p->plane_room,
                p->sit);
            return 1;
        }
    }
    printf("sorry,没有要查询的航班!\n");
    return 0;
}
void xianshi_plane(fly *P)
{
    fly*p = P;
    int i = 0;
    printf("%-8s%-12s%-12s%-10s%-10s%-8s%-6s%-10s%-8s\n", "航班号", "起飞城市", "终点城市", "起飞时间", "抵达时间", "价格",
        "折扣", "空座数", "满仓否");
    for (; p != NULL; p = p->next)
    {
        printf("%-8s%-12s%-12s%-10s%-10s%-8.2f%-6.2f%-10d%-8d\n", p->plane_num, p->city1, p->city2, p->time1, p->time2, p->price, p->zhekou, p->plane_room,
            p->sit);
        i = 1;
    }
    if (i == 0)
        printf("航班信息为空!\n");
}
int same_plane(fly *P, char *plane_num)
{
    fly *p = P->next, *q = P->next;
    int mark = 0;
    printf("%-8s%-12s%-12s%-10s%-10s%-8s%-6s%-10s%-8s\n", "航班号", "起飞城市", "终点城市", "起飞时间", "抵达时间", "价格",
        "折扣", "空座数", "是否满仓");
    while (p != NULL&&strcmp(p->plane_num,plane_num)!=0)
    {
        p = p->next;
    }
    while (q != NULL)
    {
        if (strcmp(p->city1, q->city1) == 0 && strcmp(p->city2, q->city2) == 0 &&
            strcmp(p->plane_num, q->plane_num) != 0)
        {
            printf("%-8s%-12s%-12s%-10s%-10s%-8.2f%-6.2f%-10d%-8d\n", p->plane_num, p->city1, p->city2, p->time1, p->time2, p->price, p->zhekou, p->plane_room,
                p->sit);
            mark = 1;
        }
        q = q->next;
    }
    if (mark == 0)
    {
        printf("sorry,没有您要找的航班!\n");
        return 0;
    }
    return 1;

}

int dingpiao(fly *P, customers *Q)
{
    char name[10];
    char ID[20];
    char flight_num[10];
    char city1[20];
    char city2[20];
    int ticket_num;
    int i;
    fly *p = P->next;
    printf("请输入信息:\n");
    printf("请输入起飞城市:");
    scanf_s("%s", city1,sizeof(city1));
    printf("请输入终点城市:");
    scanf_s("%s", city2, sizeof(city2));
    if (city_chaxun(P, city1, city2) == 1)
    {
        printf("请选择航班号:\n");
        printf("航班号:");
        scanf_s("%s",flight_num,sizeof(flight_num));
        getchar();
        while (flight_num == NULL);
        {
            printf("航班号不能为空!\n");
            printf("请重新输入航班号:");
            scanf_s("%s", flight_num,sizeof(flight_num));
        }
        while (p != NULL)
        {
            if (strcmp(p->plane_num, flight_num) == 0)
            {
                printf("请输入:\n");
                printf("       姓名:");
                scanf_s("%s", name,sizeof(name));
                printf("       证件号码:");
                scanf_s("%s", ID,sizeof(ID));
                printf("       订票数量:");
                scanf_s("%d", &ticket_num);
                while (name == NULL)
                {
                    printf("对不起,名字不能为空!\n");
                    printf("       姓名:");
                    scanf_s("%s", name,sizeof(name));
                }
                while (ID == NULL)
                {
                    printf("对不起,证件号不能为空!\n");
                    printf("       证件号码:");
                    scanf_s("%s", ID,sizeof(ID));
                }
                while (ticket_num == 0)
                {
                    printf("对不起,订票数量不能为0!\n");
                    printf("       订票数量:");
                    scanf_s("%d", &ticket_num);
                }
                if (p->plane_room > 0 && p->plane_room >= ticket_num)
                {
                    insert_customers(P, Q, name, ID, flight_num, ticket_num);
                    printf("你应该支付 %6.2f 元\n", p->price*p->zhekou*ticket_num);
                    printf("恭喜!订票成功!\n");
                    return 1;
                }
                else
                {
                    printf("sorry,该航班已满!\n");
                    printf("若选择其他航班请输入1,取消则输入0\n");
                    scanf_s("%d", &i);
                    if (i == 1)
                    {
                        if (same_plane(P, flight_num) == 1)
                        {
                            printf("请输入您选择的航班:");
                            scanf_s("%s", flight_num,sizeof(flight_num));
                            insert_customers(P, Q, name, ID, flight_num, ticket_num);
                            printf("恭喜!订票成功!\n");
                            return 1;
                        }
                    }
                }
            }
            else
                p = p->next;
        }
        if (p == NULL)
            printf("对不起,您输入的航班不存在!\n");
    }
    return 0;
}
void plane_chaxun(fly *P)
{
    fly *p = P->next;
    char plane_num[10], city1[20], city2[20];
    int a;
    printf("请选择查询方式:\n");
    printf("               1.航班号查询:\n");
    printf("               2.起飞抵达城市查询:\n");
    printf("               3.显示所有信息:\n");
    printf("请选择查询方式:");
    scanf_s("%d",&a);
    getchar();
    if (a == 1)
    {
        printf("请输入航班号:");
        scanf_s("%s", plane_num,sizeof(plane_num));
        getchar();
        num_cahxun(p, plane_num);
    }
    else if (a == 2)
    {
        printf("请输入出发地:");
        scanf_s("%s", city1,sizeof(city1));
        printf("请输入终点站:");
        scanf_s("%s", city2, sizeof(city2));
        getchar();
        city_chaxun(p, city1, city2);
    }
    else if (a == 3)
        xianshi_plane(p);
    else if (a != 1 && a != 2 && a != 3)
        return;
}
void xiugai_plane(fly *P, customers *Q)
{
    fly *p = P->next;
    char plane_num[10], time1[20], time2[20];
    int a;
    printf("\n*------------------------------*\n");
    printf("*-------航线信息修改:----------  *\n");
    printf("*        1. 增加航班号            *\n");
    printf("*        2. 删除航班号            *\n");
    printf("*        3. 修改起飞抵达时间      *\n");
    printf("*        4. 退出航线修改          *\n");
    printf("*------------------------------  *\n");
    printf("请选择: ");
    scanf_s("%d", &a);
    getchar();
    if (a ==1)
        creat_fly(P);
    else if (a ==2)
        delate_flight(P);
    else if (a ==3)
    {
        printf("请输入要修改的航班号:");
        scanf_s("%s", plane_num,sizeof(plane_num));
        if (num_cahxun(p, plane_num) == 1)
        {
            printf("请输入修改后的起飞时间");
            scanf_s("%s", time1,sizeof(time1));
            printf("请输入修改后的抵达时间:");
            scanf_s("%s", time2,sizeof(time2));
            while (p)
            {
                p = p->next;
                if (strcmp(p->plane_num, plane_num) == 0)
                {
                    strcpy_s(p->time1, time1);
                    strcpy_s(p->time2, time2);
                    printf("修改成功!\n");
                }
            }
        }
    }
    else if (a ==4)
    {
        return;
    }
}
int name_id_chaxun(customers *Q, char *name, char *ID)
{
    cus *p = Q->head->next;
    int mark = 0;
    printf("%-8s%-20s%-20s%-10s%-8s", "订单号", "姓名", "证件号码", "航班号",
        "订票数");
    while (p)
    {
        p = p->next;
        if (strcmp(p->ID, ID) == 0 && strcmp(p->name, name) == 0)
        {
            printf("%-8s%-20s%-20s%-10s%-8d\n", p->order_num, p->name, p->ID,
                p->flight_num, p->ticket_num);
            mark = 1;
        }
    }
    if (mark == 0)
    {
        printf("sorry,没有您的订单信息!\n");
        return 0;
    }
    return 1;
}
int order_num_chaxun(customers *Q, int order_num)
{
    cus *p = Q->head->next;
    printf("%-8s%-20s%-20s%-10s%-8s", "订单号", "姓名", 
        "证件号码", "航班号", "订票数");
    for (; p != NULL; p = p->next)
    {
        if (p->order_num == order_num)
        {
            printf("%-8s%-20s%-20s%-10s%-8d\n", p->order_num, p->name, p->ID,
                p->flight_num, p->ticket_num);
            return 1;
        }
    }
    printf("sorry,没有该订单信息!\n");
    return 0;
}
void xianshi_dingdan(customers *Q)
{
    cus *p = Q->head->next;
    int i = 0;
    printf("%-8s%-20s%-20s%-10s%-8s", "订单号", "姓名",
        "证件号码", "航班号", "订票数");
    for (; p != NULL; p = p->next)
    {
        printf("%-8s%-20s%-20s%-10s%-8d\n", p->order_num, p->name, p->ID,
            p->flight_num, p->ticket_num);
        i = 1;
    }
    if (i == 0)
        printf("当前没有订单!\n");
}
void customer_chaxun(customers *Q)
{
    char name[20], ID[20];
    int order_num, a;
    printf("\n*------------------------------*\n");
    printf("*-------查询方式:----------*\n");
    printf("*        1. 按客户姓名和证件号查询:     *\n");
    printf("*        2. 按订单号查询:     *\n");
    printf("*        3. 查看全部订单信息:     *\n");
    printf("*        4. 退出查询        *\n");
    printf("*------------------------------*\n");
    printf("请选择: ");
    scanf_s("%d", &a);
    if (a == 1)
    {
        printf("请输入姓名:");
        scanf_s("%s", name,sizeof(name));
        printf("请输入证件号码:");
        scanf_s("%s", ID,sizeof(ID));
        name_id_chaxun(Q, name, ID);
    }
    else if (a == 2)
    {
        printf("请输入您的订单号:");
        scanf_s("%d",&order_num);
        order_num_chaxun(Q, order_num);
    }
    else if (a == 3)
    {
        xianshi_dingdan(Q);
    }
    else if (a == 4)
        return;
}
void tuipiao(customers *Q, fly *P)
{
    char name[20], ID[20];
    printf("请输入姓名:");
    scanf_s("%s", name,sizeof(name));
    printf("请输入证件号码:");
    scanf_s("%s", ID,sizeof(ID));
    delate_customer(Q, P, name, ID);
}
int menu()
{
    int a;
    do
    {
        system("cls");
        printf("********飞机订票系统********\n");
        printf("****************************\n");
        printf("*      1. 录入信息         *\n");
        printf("*      2. 订    票         *\n");
        printf("*      3. 退    票         *\n");
        printf("*      4. 查询航班         *\n");
        printf("*      5. 查询订单         *\n");
        printf("*      6. 修改航班         *\n");
        printf("*      0. 退     出        *\n");
        printf("****************************\n");
        printf("请选择:");
        scanf_s("%d", &a);        
    } while (a<0 || a>6);
    return a;
}
void main()
{
    fly *P;
    customers *Q;
    P = (fly*)malloc(sizeof(fly));
    Q = (customers*)malloc(sizeof(customers));
    init_fly(P);
    init_customers(Q);
    for (;;)
    {
        switch (menu())
        {
        case 1:
            creat_fly(P);
            getchar();
            break;
        case 2:
            dingpiao(P, Q);
            getchar();
            break;
        case 3:
            tuipiao(Q, P);
            getchar();
            break;
        case 4:
            plane_chaxun(P);
            getchar();
            break;
        case 5:
            customer_chaxun(Q);
            getchar();
            break;
        case 6:
            xiugai_plane(P, Q);
            getchar();
            break;
        case 0:
            getchar();
            printf("谢谢使用!再见!\n");
            exit(0);
        }
    }
}

    
搜索更多相关主题的帖子: color 订票 
2014-08-16 18:25
zycz2p
Rank: 2
等 级:论坛游民
帖 子:22
专家分:10
注 册:2013-11-12
收藏
得分:0 
一开始输入航班模块没问题,订票模块提示     [下面的框架可能不正确和/或缺失,没有为 kernel32.dll 加载符号],后来出去了一下,朋友不知道那里给我动了一下。。输入也出bug了,好像是两个insert哪里值传递有问题。。。也可能其他。。。弄了好久了,,,不会弄了。。。快崩溃了。。。
2014-08-16 18:27
zycz2p
Rank: 2
等 级:论坛游民
帖 子:22
专家分:10
注 册:2013-11-12
收藏
得分:0 
0x00852D3D 处有未经处理的异常(在 飞机订票系统.exe 中):  0xC0000005:  写入位置 0xCDCDCE39 时发生访问冲突。这个是中断以后的错误代码
2014-08-16 18:29
kaimi1
Rank: 1
等 级:新手上路
帖 子:3
专家分:8
注 册:2014-8-18
收藏
得分:8 
做飞机,这么高端的产品,羡慕中……
2014-08-18 00:28
wp231957
Rank: 20Rank: 20Rank: 20Rank: 20Rank: 20
来 自:神界
等 级:贵宾
威 望:423
帖 子:13688
专家分:53332
注 册:2012-10-18
收藏
得分:8 
还是逐个模块调试吧  接近600行代码 看着都头疼

DO IT YOURSELF !
2014-08-18 14:56
快速回复:自己做的飞机订票系统不知道哪里错了。。。一直中断。。
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.030048 second(s), 9 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved