zoukankan      html  css  js  c++  java
  • 又是二柱子的四则运算

    题目:二柱子将做好的项目交给了老师,几天后又得到了新的需求:

    作业要求1、实现在线答题。

                  2、答题结束后,可以判断对错。

                  3、并将错题的结果保存起来。

    出现的问题:

    1、对于系统的分类一开始没有考虑全面,在经过一次一次的使用之后才使程序比较完善。

    2、程序较长出现了思路断裂的情况。

    #include <stdio.h>
    #include <time.h>
    #include <stdlib.h>
    #include <conio.h>
    #define N 10
    typedef struct _ti {
        int a, b;
        int op;
        int result;
        int input;
        int rw;
    }ti;
    ti timu[N];
    int fen;
    int flag;
    int mulu()
    {
        int s;
        while(1) {
            printf(" 欢迎进入super考试系统 ");
            printf("1)随机出题 ");
            printf("2)开始考试 ");
            printf("3)试卷评分 ");
            printf("4)显示批改的试卷 ");
            printf("5)退出系统 ");
            printf("请做出选择:");
       
            scanf("%d", &s);
            while(getchar() != ' ');
           
            if(s < 1 || s > 5)
                printf("选择有误!请重新输入. ");
            else
                break;
        }
        return s;
    }
    void chuti()
    {
        int i, f;
        printf("确认随机出%d道题吗?(y确认):", N);
        if(getchar() != 'y')
            return;
       
        for(i = 0, f = 1; i < N; f ? i++ : 0) {
            timu[i].a = rand() % 100+1;
            timu[i].b = rand() % 100+1;
            timu[i].op = rand() % 4;
            if(timu[i].b == 0 && timu[i].op == 3) {
                f = 0;
                continue;
            }
            else
                f = 1;
            switch(timu[i].op) {
            case 0: timu[i].result = timu[i].a + timu[i].b;break;
            case 1: timu[i].result = timu[i].a - timu[i].b;break;
            case 2: timu[i].result = timu[i].a * timu[i].b;break;
            case 3: timu[i].result = timu[i].a / timu[i].b;break;
            }
        }
        printf("出题完毕! ");
        flag = 1;
    }
    void kaoshi()
    {
        int i, f, n;
        char op[] = "+-*/";
        if(!flag) {
            printf("还未出题! ");
            return;
        }
        printf("确认开始练习最后一次出的题吗?(y确认):");
        if(getchar() != 'y')
            return;
        fen = 0;
        for(i = 0, f = 1; i < N; f ? ++i : 0) {
            printf("题目%d: %d %c %d = ", i+1, timu[i].a, op[timu[i].op], timu[i].b);
            if(!scanf("%d", &n)) {
                printf("输入有误!请重试. ");
                f = 0;
            } else {
                timu[i].input = n;
                timu[i].rw = (n == timu[i].result ? (fen += 10, 1) : 0);
                f = 1;
            }
        }
        printf("练习完毕! ");
    }
    void pinfen()
    {
        char* a[] = {"perfect!", "good", "还行啦", "囧rz"};
        char** p;
        int n;
        p = a + 3;
        n = fen / 10;
       
        if(n >= 6)p--;
        if(n >= 8)p--;
        if(n == 10)p--;
       
        printf("你上次测试的总分为 %s:%d分 ", *p, fen);
    }
    void shijuan()
    {
        int i;
        char op[] = "+-*/";
        for(i = 0; i < N; ++i){
            printf("%d %c %d = %d %s", timu[i].a, op[timu[i].op],
            timu[i].b, timu[i].input, timu[i].rw ? "√": "×");
            if(!timu[i].rw)
                printf(" 正确答案: %d", timu[i].result);
            putchar(' ');
        }
    }
    int main()
    {
        int i;
        srand(time(0));
        void (*f[])() = {chuti, kaoshi, pinfen, shijuan};
        while((i = mulu()) != 5) {
            f[i-1]();
            printf("按任意键继续...");
            getch();
        }
        printf("Bye!");
        return 0;
    }
    总结,在进行人机交互的时候需要考虑到更多的情况,不只是逻辑上的问题还有使用者的感受。






  • 相关阅读:
    There is an overlap in the region chain修复
    There is an overlap in the region chain
    region xx not deployed on any region server
    python 中的re模块,正则表达式
    TCP粘包问题解析与解决
    yield from
    Git push提交时报错Permission denied(publickey)...Please make sure you have the correct access rights and the repository exists.
    mysql 中Varchar 与char的区别
    Mysql 字符集及排序规则
    请实现一个装饰器,限制该函数被调用的频率,如10秒一次
  • 原文地址:https://www.cnblogs.com/nanzhujue/p/9866362.html
Copyright © 2011-2022 走看看