首页 > 其他 > 详细

基于控制台的四则运算

时间:2017-03-08 00:31:49      阅读:247      评论:0      收藏:0      [点我收藏+]

 coding地址:https://git.coding.net/Dialect/c-sizeyunsuan.git

题目要求

  1. 除了整数以外,还要支持真分数的四则运算,真分数的运算,例如:1/6 + 1/8 = 7/24
  2. 运算符为 +, ?, ×, ÷
  3. 并且要求能处理用户的输入,并判断对错,打分统计正确率。
  4. 要求能处理用户输入的真分数, 如 1/2, 5/12 等
  5. 使用 -n 参数控制生成题目的个数,例如执行下面命令将生成10个题目

部分代码展示

void DealInt(int n, int a[])
{
    srand(time(NULL));
    for (int p = 0; p<n; p++)
    {
        int i = (int)rand() % 10;
        int j = (int)rand() % 10;
        int k = (int)rand() % 100 / 25;
        switch (k)
        {
        case 0:
            cout << i << "+" << j << "=";
            a[p] = i + j;
            check2(n, a);
            break;
        case 1:
            cout << i << "-" << j << "=";
            a[p] = i - j;
            check2(n, a);
            break;
        case 2:
            cout << i << "*" << j << "=";
            a[p] = i*j;
            check2(n, a);
            break;
        case 3:
            try
            {
                a[p] = i / j;
                cout << i << "/" << j << "=";
                check2(n, a);
            }
            catch (...)
            {
                p--;
            }


        }

    }
    float t = (float)r / (float)n;
    cout << "正确率:" << 100 * t << "%" << endl;
}

void DealFenshu(int n, int a[][2])
{
    srand(time(NULL));
    for (int p = 0; p<n; p++)
    {
        int i = (int)rand() % 10;
        int j = (int)rand() % 10;
        while (j == 0 || i >= j)
        {
            i = (int)rand() % 10;
            j = (int)rand() % 10;
        }
        int x = (int)rand() % 10;
        int y = (int)rand() % 10;
        while (y == 0 || x >= y)
        {
            x = (int)rand() % 10;
            y = (int)rand() % 10;
        }
        int k = (int)rand() % 100 / 25;
        switch (k)
        {
        case 0:
            cout << "(" << i << "/" << j << ")" << "+" << "(" << x << "/" << y << ")" << "=";
            a[p][0] = i*y + x*j;
            a[p][1] = j*y;
            check1(n, a);
            break;
        case 1:
            cout << "(" << i << "/" << j << ")" << "-" << "(" << x << "/" << y << ")" << "=";
            a[p][0] = i*y - x*j;
            a[p][1] = j*y;
            check1(n, a);
            break;
        case 2:
            cout << "(" << i << "/" << j << ")" << "*" << "(" << x << "/" << y << ")" << "=";
            a[p][0] = i*x;
            a[p][1] = j*y;
            check1(n, a);
            break;
        case 3:
            cout << "(" << i << "/" << j << ")" << "/" << "(" << x << "/" << y << ")" << "=";
            a[p][0] = i*y;
            a[p][1] = j*x;
            check1(n, a);
            break;

        }


    }
    float t = (float)r / (float)n;
    cout << "正确率:" << 100 * t << "%" << endl;
}

 

 

 

技术分享

技术分享

 

PSP2.1 Personal Software Process Stages Time (%) Senior Student Time (%)
Planning 计划 8 6
· Estimate 估计这个任务需要多少时间 8 6
Development 开发 82 88
· Analysis 需求分析 (包括学习新技术) 6 10
· Design Spec 生成设计文档 5 18
· Design Review 设计复审 4 12
· Coding Standard 代码规范 3 30
· Design 具体设计 10 12
· Coding 具体编码 36 21
· Code Review 代码复审 7 15
· Test 测试(自我测试,修改代码,提交修改) 13 21
Reporting 报告 9 60
· 测试报告 3 20
· 计算工作量 2 10
· 并提出过程改进计划 3 30

基于控制台的四则运算

原文:http://www.cnblogs.com/dialect/p/6517335.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!