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; 
                }
            }
        }
    }

    运行结果截图:

    上课未按时完成的原因:

  • 相关阅读:
    netcore使用IdentityServer在nginx下502错误的解决
    更新到.netcore3.0后找不到dotnet-ef的解决办法
    openssh-win64 on windows2016 ssh pub key config
    405 Method Not Allowed error with PUT or DELETE Request on IIS Server
    minikube windows hyperx填坑记
    angular当router使用userhash:false时路由404问题
    内网gitlab11.2升级至11.4.5
    Angular7上手体验
    动态规划之背包问题
    Union-Find算法详解
  • 原文地址:https://www.cnblogs.com/hyluckydog/p/5260207.html
Copyright © 2011-2022 走看看