《C语言及程序设计》实践参考——让吃货失望的菜单

来源:互联网 发布:java前后端分离session 编辑:程序博客网 时间:2024/05/16 08:05

返回:贺老师课程教学链接  项目要求


【项目 - 让吃货失望的菜单】

计算机中的应用程序,常常用“菜单”的形式,提供给用户便捷的操作。当然, 里面没有菜。
下面的程序段给出了一些提示,请在此基础上拓展,使程序的运行如图所示(不限于此,可以拓展)

int main(){    char cChioce;    while(1)    {        cChioce = getChoice();        if (cChioce=='1')            eat();        else ...    }    return 0;}char getChoice(){    char c;    printf("\n ********************\n");    printf(" *  1. 吃饭         *\n");    ...    fflush(stdin);    scanf("%c", &c);    return c;}
鼓励根据自己掌握的一些需求,例如银行存取款、学生档案管理、法律诉讼受理等,做出应用程序的“框架”,界面的表现形式也可以更美观一些。


[参考解答]

#include <stdio.h>char getChoice();void eat();void sleep();void hitdoudou();void cry();int main(){    char cChioce;    while(1)    {        cChioce = getChoice();        if (cChioce=='1')            eat();        else if (cChioce=='2')            sleep();        else if (cChioce=='3')            hitdoudou();        else if (cChioce=='4')            cry();        else if (cChioce=='0')            break;        else        {            printf("\007选择错误!\n");            continue;        }        printf("恭喜你完成了一项工作!\n");    }    return 0;}char getChoice(){    char c;    printf("\n ********************\n");    printf(" *  1. 吃饭         *\n");    printf(" *  2. 睡觉         *\n");    printf(" *  3. 打豆豆       *\n");    printf(" *  4. 找豆豆妈诉苦 *\n");    printf(" *  0. 退出         *\n");    printf(" ********************\n");    printf(" 请选择(0-4):");    fflush(stdin);    scanf("%c", &c);    return c;}void eat(){    printf(" 我吃吃吃... ...\n");}void sleep(){    printf(" 我睡觉觉... ...\n");}void hitdoudou(){    printf(" 我打打打... ...\n");}void cry(){    printf(" 哇! 你家豆豆骨头硬,害得我手疼... ...\n");}




0 0
原创粉丝点击