| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 1699 人关注过本帖
标题:求大神帮我把这段代码换成新手入门能看懂的
只看楼主 加入收藏
不呐呐
Rank: 1
等 级:新手上路
帖 子:6
专家分:0
注 册:2016-4-10
结帖率:50%
收藏
已结贴  问题点数:20 回复次数:6 
求大神帮我把这段代码换成新手入门能看懂的
代码太复杂了,看不懂啊,里面有很多函数都是没见过的
#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
linlulu001
Rank: 13Rank: 13Rank: 13Rank: 13
等 级:贵宾
威 望:20
帖 子:944
专家分:4047
注 册:2016-4-13
收藏
得分:4 
这里用到的头文件应该只有stdio.h和stdlib.h这两个。
所用到的都是基础,不应该看懂。
#define OK 1 就是说OK=1;后面的#define同理。
typedef定义简单易懂的别名。例如:
typedef struct dish
{
    int id;
    char name[NAMELEN];
    float price;
    char classify[NAMELEN];
    char summary[NOTELEN];
    struct dish *next;
} Dish;
Dish a,b[3];这里a的类型是结构体struct dish,b[3]是结构体struct dish数组。
同理:typedef int bool;
typedef int Status;
这里 int,bool,Status定义的类型都是整型。
估计你应该是这些看不明白。如果说程序看不明白,你就指出是哪一段看不明白,好让别人帮你,不然说明一遍太花费时间了。
2016-06-21 07:02
吹水佬
Rank: 16Rank: 16Rank: 16Rank: 16
等 级:版主
威 望:451
帖 子:10607
专家分:43186
注 册:2014-5-20
收藏
得分:4 
感觉看不懂是好事
2016-06-21 07:58
wanglianyi1
Rank: 11Rank: 11Rank: 11Rank: 11
等 级:贵宾
威 望:14
帖 子:647
专家分:2067
注 册:2015-6-18
收藏
得分:4 
二楼说的差不多了。开个玩笑,二楼你那个意思应该:都是基础,不应该看不懂吧??
你先整体看一遍程序,用到了哪些语句,如if-else,for,while这些懂不懂
再看看用到的哪些数据类型等,最后再理解下程序的运行流程,设计的算法这些也就大差不差了,读这些时候哪地方不懂再具体问或者查书查资料,
每一句给你注释不太可能,也没那必要。
2016-06-21 08:37
tremere
Rank: 6Rank: 6
来 自:火星
等 级:侠之大者
帖 子:223
专家分:432
注 册:2013-3-11
收藏
得分:4 
文件操作,结构体,宏定义,这个怎么还能怎么转成新手的……

极品菜鸟,来学习啦,啦啦啦啦啦啦啦。。。
2016-06-21 08:37
墨莫莫
Rank: 3Rank: 3
等 级:论坛游侠
威 望:2
帖 子:29
专家分:102
注 册:2016-4-18
收藏
得分:4 
看懂三分之一
2016-06-21 09:46
呆呆养的企鹅
Rank: 1
等 级:新手上路
帖 子:2
专家分:7
注 册:2016-6-15
收藏
得分:4 
完全看不懂……

c语言新手一只,劳烦指教,谢谢!
2016-06-21 13:13
快速回复:求大神帮我把这段代码换成新手入门能看懂的
数据加载中...
 
   



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

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