码迷,mamicode.com
首页 > 其他好文 > 详细

软件工程个人作业01

时间:2016-03-10 00:09:06      阅读:139      评论:0      收藏:0      [点我收藏+]

标签:

设计思想:

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

运行结果截图:

技术分享

上课未按时完成的原因:

 

软件工程个人作业01

标签:

原文地址:http://www.cnblogs.com/hyluckydog/p/5260207.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!