• 基于控制台的小学四则运算


    1.1具体任务

    1.除了整数以外,还要支持真分数的四则运算,真分数的运算,例如:1/6 + 1/8 = 7/24

    2.运算符为 +, −, ×, ÷

    3.并且要求能处理用户的输入,并判断对错,打分统计正确率。

    4.要求能处理用户输入的真分数, 如 1/2, 5/12 等

    5.使用 -n 参数控制生成题目的个数,例如执行下面命令将生成10个题目
    Myapp.exe -n 10

    源代码:

    ···C
    int maxNum(int i, int j) //最大公约数

    {

    int k;

    if ((k = i % j) != 0)

    {

    maxNum(j, k);

    }

    else

    return j;

    }

    int main()

    {

    int n, c, a = 0;

    srand(time(NULL));

    cin >> n;

    for (int i = 0; i < n; i++)

    {

    int x1, x2, z, t, y1, y2, c, r1, r2;

    char r3[10], r4[10];

    srand(time(NULL));

    memset(r3, 0, sizeof(r3));

    memset(r4, 0, sizeof(r4));

    x1 = rand() % 100;

    x2 = rand() % 100;

    z = rand() % 4;

    r1 = 0;

    r2 = 0;

    switch (z)

    {

    case 0:

    cout << x1 << "+" << x2 << "=";

    cin >> r1;

    r2 = x1 + x2;

    if (r1 == r2)

    {

    cout << " 正" << endl;

    a = a + 1;

    }

    else cout << " 误" << endl;

    break;

    case 1:

    if (x1 < x2)

    {

    t = x1;

    x1 = x2;

    x2 = t;

    }

    else;

    cout << x1 << "-" << x2 << "=";

    cin >> r1;

    r2 = x1 - x2;

    if (r1 == r2)

    {

    cout << " 正" << endl;

    a = a + 1;

    }

    else cout << " 误" << endl;

    break;

    case 2:

    cout << x1 << "*" << x2 << "=";

    cin >> r1;

    r2 = x1 * x2;

    if (r1 == r2)

    {

    cout << " 正" << endl;

    a = a + 1;

    }

    else cout << " 误" << endl;

    break;

    case 3:

    if (x2 != 0)

    {

    cout << x1 << "÷" << x2 << "=";

    c = maxNum(x1, x2);

    y1 = x1 / c;

    y2 = x2 / c;

    if (n != 1)

    {

    sprintf_s(r3, "%d/%d", y1, y2);

    cin >> r4;

    if (strcmp(r3, r4) == 0)

    {

    cout << " 正" << endl;

    a = a + 1;

    }

    else cout << " 误" << endl;

    }

    else

    {

    cin >> r2;

    if (r2 == y1)

    {

    cout << " 正" << endl;

    a = a + 1;

    }

    else cout << " 误" << endl;

    }

    }

    else

    {

    cout << x1 << "÷" << "1" << "=";

    cin >> r2;

    if (r2 == x1)

    {

    cout << " " << "T" << endl;

    a = a + 1;

    }

    else cout << " " << "F" << endl;

    }

    break;

    }

    }

    cout << "对的数量:" << a;

    return 0;

    }
    ···

    PSP2.1 Personal Software Process Stages Time (%) Senior Student(/hour) Time (%)(/hour)
    · Planning 计划 3h 1.5h
    · Estimate 估计这个任务需要多少时间 1h 50m
    · Analysis 需求分析 (包括学习新技术) 1h 1h
    · Coding Standard 代码规范 3h 2h
    · Design 具体设计 4h 2h
    · Coding 具体编码 30h 45h
    · Test 测试(自我测试,修改代码,提交修改) 2h 1.5h
    Reporting 报告 3h 2.5h
  • 相关阅读:
    自定义swiper索引值的样式
    返回上一页面后页面后自动刷新(跨域也可)
    点击跳转到页面指定位置
    移动端输入框弹起影响布局(包括fixed布局情况)
    thinkPHP5模版页面volist循环offset使用
    Vue i18n国际化在实际项目中的使用
    前端Cookie、essionStorage、LocalStorage 的区别
    前端常用的一些浏览器对象
    前端取?后面的值
    前端下载文件重命名解决
  • 原文地址:https://www.cnblogs.com/yaq233/p/6516860.html
Copyright © 2020-2023  润新知