【2016.3.11】作业一 加减乘除四则小程序

好久没碰vs了,连编译器都不会用了,我感觉我写的东西拉低了航院的整体水平。。。。。

但是还是得发,最后附上代码,先说说我写这个的思路,这软件是个简单的数学出题软件,面向的用户是家中有正在上小学孩子的家长,因此,软件的设计要尽可能的简单,好用。因此,我使用控制台来完成这项工作。

这个软件主要有两个部分组成,一个是出四则运算的题目,另一个是出正分数的题目,因此,我的程序也分成这两个部分。

开发的时间大约为8个小时,实现花的时间较多,比较渣。。。。觉得,这东西和一个小课设差不多了,压力不小。

最后附上源代码:

#include<iostream>

#include<stdio.h>

#include<string.h>

#include<windows.h>

#include<cstdlib>

#include<time.h>

 

using namespace std;

 

char op(int x)

{

    switch (x)

    {

    case 0: return '+';

    case 1: return '-';

    case 2: return 'X';

    case 3: return '/';

    default:

        break;

    }

}

 

void main()

{

    int i;

    int j;

    int k;

    int x, y,temp,m,n;

    char opt;

    srand(time(0));

    cout << "请输入想使用的题型" << endl;

    cout << "1.四则运算练习" << endl;

    cout << "2.分数四则运算" << endl;

    cin >> i;

    if (i == 1)

    {

        cout << "请输入题目数量:" << endl;

        cin >> j;

        for (k = 1; k <= j; k++)

        {

            x = rand() % 100;

            y = rand() % 100;

            opt = op(rand() % 4);

            if (opt == '/')

            {

                if (y == 0)

                {

                    k--;

                    break;

                }

            }

            if (opt == '-')

            {

                if (x < y)

                {

                    temp = x;

                    x = y;

                    y = temp;    

                }

            }

            cout <<x << opt << y << "=" << " ";

            if ((k % 3) == 0)

            {

                cout << endl;

            }

        }

    }

    if (i == 2)

    {

        cout << "请输入题目数量:" << endl;

        cin >> j;

        for (k = 1; k <= j; k++)

        {

            x = rand() % 100;

            y = rand() % 100;

            m = rand() % 100;

            n = rand() % 100;

            opt = op(rand() % 4);

            if (x == 0 || y == 0 || m == 0 || n == 0)

            {

                k--;

                break;

            }

            if (x > y)

            {

                temp = x;

                x = y;

                y = temp;

            }

            if (m > n)

            {

                temp = m;

                m = n;

                n = temp;

            }

            if (opt == '-')

            {

                if ((x*n) < (y*m))

                {

                    k--;

                    break;

                }

            }

            cout <<"(" <<x << "/" << y <<")"<<opt << "(" << m << "/" << n << ")"<< "=" << " ";

            if ((k % 2) == 0)

            {

                cout << endl;

            }

        }

    }

    cin >> i;

}

posted @ 2016-03-11 16:42  holy_angel  阅读(242)  评论(1编辑  收藏  举报