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


    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
  • 相关阅读:
    C#开发中is和as的区别
    Winform开发框架之系统登录实现
    C#几个经常犯错误汇总
    JavaScript事件冒泡简介及应用
    在C#的winForm程序中调用和执行javascript
    C#关于托管程序和非托管程序的区别
    分布式计算 网格计算 并行计算 云计算
    (转)960的秘密
    集群概念:集群技术简介(转)
    好用的Sql格式化工具
  • 原文地址:https://www.cnblogs.com/yaq233/p/6516860.html
Copyright © 2020-2023  润新知