| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 1704 人关注过本帖
标题:求大神帮我把这段代码换成新手入门能看懂的
取消只看楼主 加入收藏
不呐呐
Rank: 1
等 级:新手上路
帖 子:6
专家分:0
注 册:2016-4-10
结帖率:50%
收藏
已结贴  问题点数:20 回复次数:0 
求大神帮我把这段代码换成新手入门能看懂的
代码太复杂了,看不懂啊,里面有很多函数都是没见过的
#define OK 1
#define ERROR 0
#define True 1
#define False 0
#define NAMELEN 41
#define NOTELEN 101

typedef int bool;
typedef int Status;

typedef struct dish
{
    int id;
    char name[NAMELEN];
    float price;
    char classify[NAMELEN];
    char summary[NOTELEN];
    struct dish *next;
} Dish;

typedef struct
{
    Dish *head;
    int len;
} DishList;

typedef struct table
{
    int id;
    char name[NAMELEN];
    char classify[NAMELEN];
    char summary[NOTELEN];
    int maxnum;
    int minnum;
    float money;
    bool east;
    //bool settlement;
    DishList flist;
    struct table *next;
} Table;

typedef struct
{
    Table *head;
    int len;
} TableList;
      


这是子函数
Status OrderManage(TableList *TL, DishList *FL)
{
    int id,n;
    char ch;
    char name[NAMELEN];
    FILE *fp;
    Table *te;
    Dish *fe;
    Dish *dish;
    int select;
    int t;
    do
    {
        system("cls");
        printf("\t*****************餐厅点餐系统*****************\n");
        printf("\t*1.用户点菜                 *\n");
        printf("\t*2.退/换/添菜                *\n");
        printf("\t*3.查询                                      *\n");
        printf("\t*4.结账                   *\n");
        printf("\t*5.浏览                                      *\n");
        printf("\t*0.返回                          *\n");
        printf("\t**********************************************\n");
        scanf("%d",&select);
        fflush(stdin);
        switch(select)
        {
        case 1:
            printf("\t\t请输入桌台编号:");
            scanf("%d", &id);
            fflush(stdin);
            n = SearchTList(TL, id, &te);
            if(n)
            {
                if(!te->east)
                {
                    DisplayFList(FL);
                    do
                    {
                        printf("\t\t请输入菜品名称(直接回车退出点菜):");
                        ch = getchar();
                        if(ch=='\n')
                        {
                            printf("\t\t消费总额:%.2f\n", te->money);
                            break;
                        }
                        else
                            ungetc(ch, stdin);
                        scanf("%s", name);
                        fflush(stdin);
                        n = SearchFListN(FL, name, &fe);
                        if(n)
                        {
                            dish = (Dish *)malloc(sizeof(Dish));
                            if(!dish)
                                return ERROR;
                            *dish = *fe;
                            if(InsertFList(&te->flist, dish, 1))
                            {
                                printf("\t\t点菜成功\n");
                                te->money += dish->price;
                                te->east = True;
                            }
                            else
                                printf("\t\t点菜失败\n");
                        }
                        else
                            printf("\t\t没有该菜品");
                    }
                    while(ch!='\n');
                }
                else if(te->east)
                    printf("\t\t有人正在就餐\n");
            }
            else
                printf("\t\t没有该编号桌台\n");
            dish = NULL;
            te = NULL;
            fe = NULL;
            system("pause");
            break;
        case 2:
            printf("\t\t请输入桌台编号:");
            scanf("%d", &id);
            fflush(stdin);
            n = SearchTList(TL, id, &te);
            if(n)
            {
                if(te->east)
                {
                    printf("\t\t当前已点菜品:\n");
                    DisplayFList(&te->flist);
                    do
                    {

                        printf("\t\t1.添菜\n");
                        printf("\t\t2.退菜\n");
                        printf("\t\t3.换菜\n");
                        printf("\t\t0.返回\n");
                        printf("\t\t请输入功能序号:");
                        scanf("%d", &t);
                        fflush(stdin);
                        switch(t)
                        {
                        case 1:
                            printf("\t\t请输入菜品名称:");
                            scanf("%s", name);
                            fflush(stdin);
                            n = SearchFListN(FL, name, &fe);
                            dish = (Dish *)malloc(sizeof(Dish));
                            if(!dish)
                                return ERROR;
                            *dish = *fe;
                            if(n&&InsertFList(&te->flist, dish, 1))
                            {
                                te->money += fe->price;
                                printf("\t\t添菜成功\n");
                                printf("\t\t消费总额:%.2f元\n", te->money);
                            }
                            else
                                printf("\t\t添菜失败\n");
                            fe = NULL;
                            dish = NULL;
                            system("pause");
                            break;
                        case 2:
                            printf("\t\t请输入菜品名称:");
                            scanf("%s", name);
                            fflush(stdin);
                            n = SearchFListN(&te->flist, name, &fe);
                            if(n)
                            {
                                DeleteFList(&te->flist, n);
                                te->money -= fe->price;
                                printf("\t\t退菜成功\n");
                                printf("\t\t消费总额:%.2f元\n", te->money);
                            }
                            else
                                printf("\t\t没有点该菜品\n");
                            fe = NULL;
                            system("pause");
                            break;
                        case 3:
                            printf("\t\t请输入要被换掉的菜品名称:");
                            scanf("%s", name);
                            fflush(stdin);
                            n = SearchFListN(&te->flist, name, &fe);
                            if(n)
                            {
                                printf("\t\t请输入要换的菜品名称:");
                                scanf("%s", name);
                                fflush(stdin);
                                t = fe->price;
                                if(SearchFListN(FL, name, &fe))
                                {
                                    if(DeleteFList(&te->flist, n))
                                    {
                                        dish = (Dish *)malloc(sizeof(Dish));
                                        if(!dish)
                                            return ERROR;
                                        *dish = *fe;
                                        te->money -= t;
                                        if(InsertFList(&te->flist, dish, 1))
                                        {
                                            te->money += dish->price;
                                            printf("\t\t换菜成功\n");
                                            printf("\t\t消费总额:%.2f元\n", te->money);
                                        }
                                        else
                                            printf("\t\t菜已退掉,但添加新菜失败\n");
                                    }
                                    else
                                        printf("\t\t换菜失败\n");

                                }
                                else
                                    printf("\t\t没有该菜品\n");
                            }
                            else
                                printf("\t\t没有点该菜品\n");
                            fe = NULL;
                            dish = NULL;
                            system("pause");
                            break;
                        case 0:
                            break;
                        default:
                            printf("\t\t序号有误\n");
                            system("pause");
                            break;
                        }
                    }
                    while(t);
                }
                else if(!te->east)
                    printf("\t\t此桌台无人就餐\n");
            }
            else
                printf("\t\t无此桌台\n");
            te = NULL;
            fe = NULL;
            system("pause");
            break;
        case 3:
            printf("\t\t请输入要查询的桌台号:");
            scanf("%d", &id);
            fflush(stdin);
            if(SearchTList(TL, id, &te))
            {
                printf("\t\t点菜信息:\n");
                DisplayFList(&te->flist);
                printf("\t\t消费总额:%.2f元\n", te->money);
            }
            else
                printf("\t\t没有该编号桌台\n");
            te = NULL;
            fe = NULL;
            system("pause");
            break;
        case 4:
            printf("\t\t请输入要结账的桌台号:");
            scanf("%d", &id);
            fflush(stdin);
            if(SearchTList(TL, id, &te))
            {
                if(te->east)
                {

                    printf("\t\t点菜信息:\n");
                    DisplayFList(&te->flist);
                    printf("\t\t消费总额:%.2f元\n", te->money);
                    SaveSettelment(te);
                    te->money = 0;
                    te->east = False;
                    DestroyFlist(&te->flist);
                }
                else
                    printf("\t\t该桌台无人就餐\n");
            }
            else
                printf("\t\t没有该编号桌台\n");
            te = NULL;
            fe = NULL;
            system("pause");
            break;
        case 5:
            fp = fopen("data\\Settlement.dat", "r");
            te = (Table *)malloc(sizeof(Table));
            if(!fp||!te)
            {
                printf("\t\t从文件读取失败\n");
            }
            else
            {
                while(fscanf(fp, "%d %s %s %s %d %d %f %d ", &te->id, te->name, te->classify, te->summary, &te->maxnum, &te->minnum, &te->money, &t)!=EOF)
                {
                    te->east = False;
                    InitFList(&te->flist);
                    while(t--)
                    {
                        dish = (Dish *)malloc(sizeof(Dish));
                        if(!dish)
                            return ERROR;
                        fscanf(fp, "%d %s %s %s %f ", &dish->id, dish->name, dish->classify, dish->summary, &dish->price);
                        InsertFList(&te->flist, dish, 1);
                    }
                    InsertTList(&bill, te, 1);
                    te = (Table *)malloc(sizeof(Table));
                    if(!te)
                        return ERROR;
                }
            }
            DisplayBill(&bill);
            DestroyTlist(&bill);
            free(te);
            te = NULL;
            fe = NULL;
            system("pause");
            break;
        case 0:
            break;
        default:
            printf("\t\t序号有误\n");
            system("pause");
            break;
        }
    }
    while(select);
    return OK;
}
搜索更多相关主题的帖子: price False 
2016-06-20 23:39
快速回复:求大神帮我把这段代码换成新手入门能看懂的
数据加载中...
 
   



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

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