| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 465 人关注过本帖
标题:求高手修改程序,这个程序有点小错误。谢谢了
只看楼主 加入收藏
胡山权
Rank: 1
等 级:新手上路
帖 子:3
专家分:0
注 册:2012-9-7
结帖率:0
收藏
已结贴  问题点数:20 回复次数:3 
求高手修改程序,这个程序有点小错误。谢谢了
#include  <stdio.h>
#include  <stdio.h>
#include  <string.h>


typedef struct customer                //客人结构体
{
    char name[15];
    int age;
    int sex;
    int lv;
    int bed_num;
    int year;
    int month;
    int day;
    struct cusyomer* next;
   
}cus;


typedef struct hotel_lv                    //宾馆结构体
{
    int lv_num;
    struct hotel_lv *next;
    struct fangjian *fj_next;

}hotel_lv;


typedef struct fangjian                         //房间结构体
{
    int fj_num;
    int max;
    int mem_num;
    struct fangjian *next;
    struct customer *cus_next;
}fangjian;

void Init(hotel_lv *L)                    //初始化函数
{
    int i,j,k,l;
    hotel_lv *p,*q;
    fangjian *p1, *p2,*p3;
    printf ("请输入房间分为几个等级:\n");
    scanf ("%d",&j);                      //输入房间分为几个等级
    q=L;
    for (i=1;i<j;i++)
    {
        p= (hotel_lv*) malloc (sizeof(hotel_lv));
        q->next=p;
        p->lv_num=i;                                //给房间等级赋值
        printf ("请输入房间等级为%d的房间个数:\n",p->lv_num);
        scanf ("%d",&l);                             //输入该等级房间的数目
        if (l==0)
            continue;
        else                                        //初始化该房间的床位
        {
            p2= (fangjian*)malloc(sizeof(fangjian));
            p2->fj_num=1;
            printf ("请输入房间等级为%d房间号为l的床位个数的最大值:\n",p->lv_num,k);
            scanf ("%d",&(p2->max));             //输入房间l的床位数目
            p2->mem_num=0;                       //该房间内当前人数赋值为0
            p->fj_next=p2;
            p3=p2;
            for (k=2;k<=1;k++)
            {
                p1=(fangjian*)malloc(sizeof(fangjian));
                p3->next=p1;
                p1->fj_num=k;
                printf ("请输入房间等级为%d房间号为%d的床位的个数的最大值;\n",p->lv_num,k);
                scanf ("%d",&(p1->max));              //输入房间K的床位数目
                p1->mem_num=0;                        //该房间内的当前人数赋值为0
                p3=p1;

            }
            p3->next=NULL;                    //房间链表尾指针为空

        }
        q=q->next;
    }
    q->next=NULL;                                //等级链表尾指针域为空
    system ("pause");

}

int full (hotel_lv *L)                     //判断是否客满
{
    hotel_lv *l;
    l=L->next;
    fangjian *f;
    while (l!=NULL)
    {
        f=l->fj_next;
        while (f!=NULL)
        {
            if (f->mem_num!=f->max)             //如果有房间的当前人数不等于房间的最大人数,则返回0
                return 0;
            else
                f=f->next;
        }
        l=l->next;
    }
    if (!l)                          //否则返回1
        return 1;
}


void Pr_divide(cus *p,fangjian *q)                      //打印客人信息
{
    printf ("************************************************************\n\n");
    printf ("                      宾馆房间分配系统                      \n\n");
    printf ("************************************************************\n\n");
    printf ("| 姓名 | 性别 | 年龄 | 等级号 | 房间号 | 床位号 | 入住时间 |\n");
    printf ("| %12s | %d | %2d | %2d | %2d | %2d |  %4d-%2d-%2d | \n",
        p->name,p->sex,p->age,p->lv,q->fj_num,p->bed_num,p->year,p->month,p->day);
    printf ("*************************************************************\n");
printf ("\n");
system ("pause");


}

void input (hotel_lv *L)                 //入住函数
{
    char c;
    cus *s,*p2,*p3;
    hotel_lv *l;
    l=L->next;
    fangjian *p1;
    int i,lv;
    if (full (L))                      //判断是否客满
    {
        printf ("房间已满,不能入住。\n");
        system ("pause");
    }
    else
    {
        printf ("请输入旅客所需的房间等级:");
            scanf ("%d",&lv);
        while (l!=NULL)                         //等级不为空时
        {
            if (l->lv_num!=lv)
                l=l->next;
            else                                //有此等级时
            {
                p1=l->fj_next;
                while (p1!=NULL)                //房间不为空
                {
                    if (p1->mem_num==p1->max)      //是否有空床位
                    {
                        p1=p1->next;
                        if (p1==NULL)
                        {
                            getchar ();
                            printf ("此等级为%d的所有房间均无空位\n是否愿意更好等级[y/n]",lv);
                            scanf ("%c",&c);          //选择
                            if (c=='y')
                                input (L);
                            else
                            return;

                        }
                    }
                    else                     //客人信息登记
                    {                         //因为床位没有设置头结点,所以对于第一个结点要特别判断
                        if(p1->mem_num==0)
                        {
                            s=(cus*)malloc(sizeof(cus));
                            printf ("\n---------------------------------\n");
                            printf ("\n      入住客人信息:");
                            printf("\n       请输入客人的姓名:");
                            scanf ("%s",s->name);
                            printf("\n       请输入客人年龄:");
                            scanf ("%d",&(s->age));
                            printf ("\n       请输入客人的性别(如:男1;女0):");
                            scanf ("%d",&(s->sex));
                            printf ("\n        请输入客人入住的时间(如:1990 10 11):");
                            scanf ("%d %d %d",&s->year,&s->month,&s->day);
                            s->lv=lv;                      //指针修改
                            p1->cus_next=s;
                            p1->mem_num++;                 //房间当前最大人数加1
                            s->bed_num=1;
                            s->next=NULL;                  //尾指针设置为空
                            Pr_divide (s,p1);               //打印房间分配表
                            system ("cls");
                            break;
                        }
                        else
                        {
                            p2=p1->cus_next;
                            p3=p2;
                            i=1;
                            while (i<=p1->mem_num)
                            {
                                if (i==p3->bed_num)
                                {
                                    p3=p3->next;
                                    i++;
                                }
                                else
                                {
                                    i++;
                                    break;
                                }
                            }
                            if (p3==NULL)
                            {
                                s=(cus*)malloc(sizeof(cus));
                                printf("\n--------------------------------------\n");
                                    printf ("\n      入住客人信息:");
                            printf("\n       请输入客人的姓名:");
                            scanf ("%s",s->name);
                            printf("\n       请输入客人年龄:");
                            scanf ("%d",&(s->age));
                            printf ("\n       请输入客人的性别(如:男1;女0):");
                            scanf ("%d",&(s->sex));
                            printf ("\n        请输入客人入住的时间(如:1990 10 11):");
                            scanf ("%d %d %d",&s->year,&s->month,&s->day);
                            s->lv=lv;
                            while (p2->next!=p3)
                                p2=p2->next;
                            p2->next=s;
                            p1->mem_num++;
                                s->bed_num=i;
                                s->next=NULL;
                            Pr_divide (s,p1);
                            system("cls");
                            break;

                            }
                            else
                            {
                                while(p2->bed_num==i)
                                    p2=p2->next;
                                s=(cus*)malloc(sizeof(cus));
                                printf("\n--------------------------------------\n");
                                    printf ("\n      入住客人信息:");
                            printf("\n       请输入客人的姓名:");
                            scanf ("%s",s->name);
                            printf("\n       请输入客人年龄:");
                            scanf ("%d",&(s->age));
                            printf ("\n       请输入客人的性别(如:男1;女0):");
                            scanf ("%d",&(s->sex));
                            printf ("\n        请输入客人入住的时间(如:1990 10 11):");
                            scanf ("%d %d %d",&s->year,&s->month,&s->day);
                            s->lv=lv;
                            s->next=p2->next;
                            p2->next=s;
                            p1->mem_num++;
                            s->bed_num=i-1;
                            Pr_divide(s,p1);
                            system("cls");
                            break;

                            }

                        }
                    }
                }
                break;
            }
        }
    }
}


cus* Delete (hotel_lv *L)                 //退房
{
    int lv,hotel_num,bed_num;
    hotel_lv *l;
    l=L->next;
    fangjian *f;
    cus *p,*q;
    char c;
    printf ("请输入该退房客人的房间等级号码:\n");
    scanf ("%d",&lv);                       //输入退房人的房间等级
    getchar ();
    while (l!=NULL)
    {
        if (l->lv_num!=lv)
            l=l->next;
        else                                 //找到该等级
        {
            f=l->fj_next;
            printf("请输入退房客人的房间号码:\n");
            scanf ("%d",&hotel_num);            //输入退房人的房间号码
            getchar ();
            while (f!=NULL)
            {
                if (f->fj_num!=hotel_num)
                    f=f->next;
                else                            //找到该房间
                {
                    p=f->cus_next;
                    q=f->cus_next;
                    printf("请输入该客人的床位号:\n");
                    scanf ("%d",&bed_num);             //输入退放入的床位号
                    getchar ();
                    while (q!=NULL)
                    {
                        if (q->bed_num!=bed_num)
                            q=q->next;
                        else                           //查找该床位
                        {
                            if (bed_num==1)               //因为床位没有设置头结点,所以对第一个结点要特别判断
                            {                              //直接打印客人信息
                                printf ("此等级、此房间、此床位的客人信息为:\n");
                                printf ("改客人的信息为:\n");
                                printf ("姓名\t性别\t年龄\t入住时间\n");
                                printf ("%s\t%d\t%d\t%d-%d-%d\n",q->name,q->sex,q->age,q->year,q->month,q->day);
                                printf ("是否与退房人的信息相同?[y/n]\n");
                                scanf ("%c",&c);
                                if (c=='y')                //做出是否退房的选择
                                {
                                    f->mem_num--;
                                    printf ("退房成功!\n");
                                    system ("pause");
                                    return (q);
                                }
                                else
                                    return NULL;
                            }
                            else                   //如果床位不为1
                            {
                                while (p->next!=q)                      //指向下一床位
                                    p=p->next;                      //打印客人信息
                                printf ("此等级、此房间、此床位的客人信息为:\n");
                                printf ("改客人的信息为:\n");
                                printf ("姓名\t性别\t年龄\t入住时间\n");
                                printf ("%s\t%d\t%d\t%d-%d-%d\n",q->name,q->sex,q->age,q->year,q->month,q->day);
                                printf ("是否与退房人的信息相同?[y/n]\n");
                                scanf ("%c",&c);
                                if (c=='y')                  //做出是否退房的选择
                                {
                                    f->mem_num--;
                                    printf ("退房成功!\n");
                                    system ("pause");
                                    return (q);
                                }
                                else
                                    return NULL;
                            }
                        }
                    }
                    if (q=NULL)                    //如果该房间内床位为空                  
                    {
                        printf ("没有找到该床位,请核对信息后重新输入。\n");
                    }
                }
            }
            if (f==NULL)                            //如果该等级的房间为空
            {
                printf ("没有找到该房间号,请从新输入。\n");
            }

        }
    }
    if (l==NULL)                   //如果等级链表为空
    {
        printf ("没有找到该房间等级,请核对后输入!\n");
    }
    system ("pause");
}


void cx_customer (hotel_lv *L)            //查询客人信息
{
    char s[15];
    hotel_lv *l;
    fangjian *f;
    cus *t;   
    int flag=0;                        //设置标志量
    printf ("请输入要查询的客人姓名:\n");
    scanf ("%s",s);                      //输入要查询的客人姓名                  
    getchar ();
    l=L->next;
    while (l!=NULL)                       //等级不为空时,走向房间
    {
        f=l->fj_next;
        while (f!=NULL)                 //房间不为空时,走向床位
        {
            if (f->mem_num==0)           //若此房间当前人数为0,走向下一见房
                f=f->next;
            else
            {
                t=f->cus_next;
                while (t!=NULL)
                {
                    if (!strcmp (t->name,s))            //如果找到该客人
                    {
                        Pr_divide (t,f);                //打印信息
                        t=t->next;                      //指向下一个人,继续查找
                        flag++;                          //标量加1
                    }
                    else
                        t=t->next;
                }
                f=f->next;
            }
        }
        l=l->next;
    }
    if (!flag)                            //标志量为0,则未查找到
    {
        printf ("没有找到该客人,请核对再输入。\n");
        system ("pause");
    }
}                                     //统计函数与查询函数基本类似               





void tongji_cus (hotel_lv *L)                //统计当前客人人数函数
{
    char s[15];
    hotel_lv *l;
    fangjian *f;
    cus *t;
    int i=0,j=0;
    int flag;
    l=L->next;
    while (l!=NULL)
    {
        flag=0;
        i++;
        f=l->fj_next;
        while (f!=NULL)
        {
            if (f->mem_num==0)
                f=f->next;
            else
            {
                t=f->cus_next;
                while (t!=NULL)
                {
                    flag++;
                    j=j+flag;
                    t=t->next;
                }
                f=f->next;
            }
        }
        printf ("等级为%d的房间的入住人数为%d\n",i,flag);
        l=l->next;
    }
    if (!j)
        printf ("此时无人入住。\n");
    system ("pause");
}




void main ()                                      //主函数
{
    hotel_lv *L;
    cus *p;
    int c;
    L=(hotel_lv *)malloc (sizeof(hotel_lv));
    printf ("初始化旅店信息:\n");
    Init (L);
        while (1)                     //进入菜单选项
        {
            system ("cls");
            printf ("\n\n\n");
            printf ("************************************************************\n");
            printf ("*                                                          *\n");
            printf ("*              欢迎进入宾馆客房管理系统                    *\n");
            printf ("*                                                          *\n");
            printf ("************************************************************\n");
            printf ("        1 录入客人信息\n");
            printf ("        2 退房业务    \n ");
            printf ("        3 查询客人信息\n");
            printf ("        4 统计客人信息\n");
            printf ("        0 退出系统    \n");
            printf ("         请选择你要办理的业务 \n");
            scanf ("%d",&c);                            // 做选择
            getchar ();
            switch (c)
            {
            case 1:  input (L);
                break;
            case 2:  p=Delete (L);free (p);
                break;
            case 3:  cx_customer (L);
                break;
            case 4:  tongji_cus (L);
                break;
            case 0:  return;
            }
            getchar ();
        }
}

搜索更多相关主题的帖子: next customer 结构体 include 
2012-10-23 17:21
hgand
Rank: 2
等 级:论坛游民
帖 子:32
专家分:77
注 册:2012-10-17
收藏
得分:10 
typedef struct customer                //客人结构体
{
    char name[15];
    int age;
    int sex;
    int lv;
    int bed_num;
    int year;
    int month;
    int day;
    struct cusyomer* next;
   
}cus;

你看我给你标记的,明显错误啊!!你编译的时候也会有哦!你多了解编译出错的信息!
2012-10-25 11:09
hgand
Rank: 2
等 级:论坛游民
帖 子:32
专家分:77
注 册:2012-10-17
收藏
得分:0 
void Init(hotel_lv *L)                    //初始化函数
{
    int i,j,k,l;
    hotel_lv *p,*q;
    fangjian *p1, *p2,*p3;
    printf ("请输入房间分为几个等级:\n");
    scanf ("%d",&j);                      //输入房间分为几个等级
    q=L;
    for (i=1;i<j;i++)
    {
        p= (hotel_lv*) malloc (sizeof(hotel_lv));

请把上面的我标记的 j 改为 j+1 吧,这样就不会漏一个等级啊!  你按照我上面两个说的改,就可以用了!! 记得给分啊!呵呵!

2012-10-25 12:37
pangding
Rank: 19Rank: 19Rank: 19Rank: 19Rank: 19Rank: 19
来 自:北京
等 级:贵宾
威 望:94
帖 子:6784
专家分:16751
注 册:2008-12-20
收藏
得分:10 
这么长的代码,楼上有心了。
2012-10-30 22:33
快速回复:求高手修改程序,这个程序有点小错误。谢谢了
数据加载中...
 
   



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

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