zoukankan      html  css  js  c++  java
  • C语言寒假大作战03

    问题 答案
    这个作业属于哪个课程 https://edu.cnblogs.com/campus/zswxy/CST2019-4/homework/10269
    这个作业要求在哪 https://edu.cnblogs.com/campus/zswxy/CST2019-4/homework/10269
    这个作业的目标 根据上次作业,添加使用rand()的使用
    作业正文 使用上次作业的菜单框架,并在其基础上增加各年级题目操作函数
    其他参考文献 https://www.runoob.com/cprogramming/c-function-rand.html, 百度等

    2.2.2设计思路和遇到的问题

    设计思路:

    一开始看到思维框架时多了几个自定义函数,所以我首先想到的是添加函数,然后根据所给的运行界面示例和有关rand()函数的操作说明,就在原来代码的基础上做了修改
    

    遇到的问题:

     1.在运行时,没有打印出我所给出的内容 2.在第一次尝试rand()函数时编译错误
    

    2.2.3程序结果截图



    2.2.4程序代码

    #include <stdio.h>
    #include <stdlib.h>
    #include <time.h>
    void menu(); 
    void help();
    void one();void operation_1(); 
    void two();void operation_2();
    void three();void operation_3(); 
    void error();
    int main()
    {
    int opt=1,n;
    printf("==========口算生成器==========
    ");
    printf("欢迎使用口算生成器:
    ");
    printf("
    ");
    help();
    while(opt!=0)
    {
    menu();
    printf("请输入操作> ");
    scanf("%d",&opt);
    printf("<执行操作:)
    ");
    printf("
    ");
    switch(opt)
    {
    case 1:operation_1();break;
    case 2:operation_2();break;
    case 3:operation_3();break;
    case 4:help();break;
    case 5:printf("程序结束, 欢迎下次使用
    ");
    printf("任意键结束……");
    opt=0;
    default:error();break;
    }
    }
    return 0;
    }
    void menu()
    {
    printf("
    ");
    printf("操作列表:
    ");
    printf("1)一年级 2)二年级 3)三年级
    ");
    printf("4)帮助 5)退出程序
    ");
    }
    void help()
    {
    printf("
    ");
    printf("帮助信息
    ");
    printf("您需要输入命令代号来进行操作,且
    ");
    printf("一年级题目为不超过十位的加减法
    ");
    printf("二年级题目为不超过百位的乘除法
    ");
    printf("三年级题目为不超过百位的加减乘除混合题目.
    ");
    }
    void operation_1() 
    {
    printf("请输入生成个数>");
    one();
    }
    void operation_2()
    {
    printf("请输入生成个数>");
    two();
    }
    void operation_3()
    {
    printf("请输入生成个数>");
    three();
    }
    void one()
    {
    int n,a,b,c;
    scanf("%d",&n);
    printf("一年级题目如下:
    "); 
    srand((unsigned)time(NULL));
    for(int i=1;i<=n;i++)
    {
        a=rand()%10;
        b=rand()%10;
        c=rand()%2;
        if(c==0)
        printf("%2d + %2d = ___",a,b);
        else
        printf("%2d - %2d = ___",a,b);
        printf("
    ");
     } 
    
    }
    void two()
    {
    int n,a,b,c;
    scanf("%d",&n);
    printf("二年级题目如下:
    "); 
    srand((unsigned)time(NULL));
    for(int i=1;i<=n;i++)
    {
        a=rand()%100;
        b=rand()%100;
        c=rand()%2;
        if(c==0)
        printf("%3d * %3d = ___",a,b);
        else
        printf("%3d / %3d = ___",a,b);
        printf("
    ");
     } 
    
    }
    void three()
    {
    int n,a,b,c;
    scanf("%d",&n); 
    printf("三年级题目如下:
    "); 
    srand((unsigned)time(NULL));
    for(int i=1;i<=n;i++)
    {
        a=rand()%100;
        b=rand()%100;
        c=rand()%4;
        switch(c)
        {
            case 0:printf("%3d + %3d = ___",a,b);break;
            case 1:printf("%3d - %3d = ___",a,b);break;
            case 2:printf("%3d * %3d = ___",a,b);break;
            case 3:printf("%3d / %3d = ___",a,b);break;
         }
        printf("
    ");
     }
    }
    void error()
    {
    printf("Error!!!
    ");
    printf("错误操作指令, 请重新输入
    ");
    }
    

    2.2.5Gitee上传截图与链接



    https://gitee.com/douqi123

  • 相关阅读:
    APP设计资源
    browsersync实现网页实时刷新(修改LESS,JS,HTML时)
    Browsersync + Gulp.js
    用原生js对表格排序
    js深复制
    c++刷题(43/100)矩阵旋转打印
    将本地的mongodb迁移到阿里云
    c++刷题(39/100)笔试题3
    c++刷题(37/100)笔试题2
    c++刷题(33/100)笔试题1
  • 原文地址:https://www.cnblogs.com/douqi/p/12283767.html
Copyright © 2011-2022 走看看