zoukankan      html  css  js  c++  java
  • 软件工程个人作业01

    设计思想:

    1.里用随机数生成函数生成4个随机数

    2.中间随机数加工,除4取余,0,1,2,3分别代表加减乘除.最后一个随机数除2取余,0代表整数,1代表假分数

    3.当生成除法判断除数不为0

    4.随机题目生成,循环30道题目

    5.输出

    源程序代码:

    #include<iostream>
    using namespace std;
    #include<time.h>
    
    struct yunsuan
    {
        int fuhao;     
        int one;     
        int two;    
        int select;
    };
    
    int main()
    {
        yunsuan num[30];
        srand((int)time(NULL));
        int i;
    
        for(i=0;i<30;i++)
        {
            num[i].one = rand()%100; 
            num[i].two = rand()%100;   
            num[i].fuhao = rand() % 4;  
            num[i].select = rand() % 2;
    
            if(num[i].fuhao==3)
            {
                if(num[i].two == 0&&num[i].one < num[i].two)
                {
                    i=i-1;
                }
            }
        }
    
        for(i=0;i<30;i++)
        {
            if(num[i].select == 0)
            {
                if(num[i].fuhao==0)
                {
                    cout << num[i].one << " + " << num[i].two << " = " << endl;
                }
                if(num[i].fuhao==1)
                {
                    cout << num[i].one << " - " << num[i].two << " = " << endl;
                }
                if(num[i].fuhao==2)
                {
                    cout << num[i].one << " * " << num[i].two<< " = " << endl;
                }
                if(num[i].fuhao==3)
                {
                    cout << num[i].one << " / " << num[i].two<< " = " << endl;
                }
            }
            else
            {
                int num1 = rand() % 100+1;
                int num2 = num[i].one+1;
                int num3 = rand() % 100+1;
                int num4 = num[i].two+1;
                if(num[i].fuhao==0) 
                {
                    cout << num1 << "/" << num2 << " + " << num3 << "/" << num4 << " = " << endl; 
                }
                if(num[i].fuhao==1)
                {
                    cout << num1 << "/" << num2 << " + " << num3 << "/" << num4 << " = " << endl; 
                }
                if(num[i].fuhao==2)
                {
                    cout << "(" << num1 << "/" << num2 << ") * (" <<num3 << "/" << num4 << ") = " << endl; 
                }
                if(num[i].fuhao==3)
                {
                    cout << "(" << num1 << "/" << num2 << ") /(" <<num3 << "/" << num4 << ") = " << endl; 
                }
            }
        }
    }

    运行结果截图:

    上课未按时完成的原因:

  • 相关阅读:
    【LeetCode】13. Roman to Integer (2 solutions)
    【LeetCode】16. 3Sum Closest
    【LeetCode】18. 4Sum (2 solutions)
    【LeetCode】168. Excel Sheet Column Title
    如何应用性能测试常用计算公式
    系统吞吐量(TPS)、用户并发量、性能测试概念和公式
    Monkey测试3——Monkey测试结果分析
    Monkey测试2——Monkey测试策略
    Monkey测试1——Monkey的使用
    TestNG 三 测试方法
  • 原文地址:https://www.cnblogs.com/hyluckydog/p/5260207.html
Copyright © 2011-2022 走看看