zoukankan      html  css  js  c++  java
  • 四则运算3+PSP

    题目要求:

         1、要求在第二次实验(四则运算2)的基础上加上其他功能。

         2、要求能够在每个运算式打印出来后,用户能够进行输入计算的答案,并且程序进行判断给出用户输入的答案的正确性。

         3、要求实现四则混合运算,适合小学1-6年级的难度

         4、要求多个除号相连时,加上括号进行优先级的确定

    团队成员:贾兆款、宋海林(http://www.cnblogs.com/hulidanxiang/p/5295475.html

    设计思路:

         1、首先对要实现的功能进行分析并分解称若干个具体的小函数,这样使得思路更加明确,修改维护更加方便给,同时降低了代码的重用性

         2、本实验用到的函数大体有:生成运算符的函数、生成存储运算数据数组的函数、生成运算符数组的函数(含括号)、判断余数的函数、判断负数的函数、进行打印输出的函数

         3、由于本次试验是在第二次实验的的基础上进行的完善,所以具体的设计思路和第二次试验一样。此次主要加入的功能是连除时加入括号进行优先级的判定,对输出的运算式能够求得其结果,并能够根据用户的输入对用户的计算结果进行判断正误

    #include<iostream>
    #include<string>
    #include<stdlib.h>
    #include<time.h>
    #include<math.h>
    #include<fstream>
    using namespace std;
    
    
    
    //生成四个运算数函数,即多运算数式子中的每个操作数
    void create_Operand(int A[], int min, int max)
    {
        for (int i = 0; i < 4; i++)
        {
            A[i] = min + rand() % (max - min + 1);
        }
    }
    
    //若用户选择不生成除法,则只生成含有加减运算的运算符,用string类型存放运算符,并将括号也存到数组中
    void create_Operator_JiaJian(string B[], int kuohao)
    {
        for (int i = 0; i < 5; i++)
        {
            B[i] = 'a';
        }
        if (1 == kuohao)
        {
            string C[3];
            for (int i = 0; i < 3; i++)
            {
                int Judge = rand() % 2;
                switch (Judge)
                {
                case 0:
                    C[i] = '+'; break;
                case 1:
                    C[i] = '-'; break;
                }
            }
            int intLeftLocation;
            intLeftLocation = 1 + rand() % 2;
            int intRightLocation;
            int a = intLeftLocation + 2;
            intRightLocation = a + rand() % (5 - a);
            B[intLeftLocation] = "(";
            B[intRightLocation] = ")";
            int j = 0;
            for (int i = 0; i < 5; i++)
            {
                if ((B[i] != "(") && (B[i] != ")"))
                {
                    B[i] = C[j];
                    j++;
                }
            }
        }
        else
        {
            for (int i = 0; i < 3; i++)
            {
                int Judge = rand() % 2;
                switch (Judge)
                {
                case 0:
                    B[i] = '+'; break;
                case 1:
                    B[i] = '-'; break;
                }
            }
        }
    }
    
    //生成加减乘除四则运算的运算符
    void create_Operator_ChengChu(string B[])
    {
        for (int i = 0; i < 3; i++)
        {
            int Judge = rand() % 4;
            switch (Judge)
            {
            case 0:
                B[i] = '+'; break;
            case 1:
                B[i] = '-'; break;
            case 2:
                B[i] = 'x'; break;
            case 3:
                B[i] = "÷"; break;
            }
        }
    }
    
    //生成字符数组
    void MulDivShuZus(string B[])
    {
        for (int i = 0; i < 3; i++)
        {
            create_Operator_ChengChu(B);
        }
        if ((B[0] == "÷") && (B[1] == "÷") && (B[2] == "÷"))  //规定不能有连续的3个除法
        {
            int intJudge = 1 + rand() % 2;
            switch (intJudge)
            {
            case 1:
                B[2] = '+';
                break;
            case 2:
                B[2] = '-';
                break;
            }
        }
    }
    
    //判断分数中的分子分母是否合法,即分子的绝对值是否小于分母
    void judge_Fraction(int &fenzi, int &fenmu, int max)
    {
        if ((fenzi<0) && (((fenzi)*(-1))>max))
        {
            int temp = (-1)*fenzi;
            fenzi = fenmu;
            fenmu = temp*(-1);
        }
    
        //为保证分数相加相减后仍然是真分数,将分子设为小于二分之分母的整数
        if (fenzi <= 0)
        {
            if (fenzi*(-1)>(max / 2))
            {
                fenzi = fenzi / 2;
            }
        }
        if (fenzi>0)
        {
            if (fenzi>(max / 2))
            {
                fenzi = fenzi / 2;
            }
        }
    }
    
    //求分子和分母的最大公约数,以便将分子分母化简到最简
    int great_common_Divisor(int fenzi, int fenmu)
    {
        int original_fenzi = fenzi;
        int original_fenmu = fenmu;
        int remainder = fenzi%fenmu;
        while (remainder != 0)
        {
            int temp = fenmu;
            fenmu = fenzi%fenmu;
            fenzi = temp;
            remainder = fenzi%fenmu;
        }
        return fenmu;
    }
    
    //计算加减运算式的值,返回一个result值
    int calculate_Jiajian(int A[], string B[], int kuohao, int minus, int min, int max)
    {
        if (1 == minus)
        {
            int result = A[0];
            if (1 == kuohao)
            {
                result = 0;
                if ((B[1] == "(") && (B[3] == ")"))
                {
                    if (B[2] == "+")
                    {
                        result = A[1] + A[2];
                    }
                    else
                    {
                        result = A[1] - A[2];
                    }
                    if (B[0] == "+")
                    {
                        result = result + A[0];
                    }
                    else
                    {
                        result = A[0] - result;
                    }
                    if (B[4] == "+")
                    {
                        result = result + A[3];
                    }
                    else
                    {
                        result = result - A[3];
                    }
                }
                if ((B[2] == "(") && (B[4] == ")"))
                {
                    int result1 = 0;
                    if (B[3] == "+")
                    {
                        result = A[2] + A[3];
                    }
                    else
                    {
                        result = A[2] - A[3];
                    }
                    if (B[0] == "+")
                    {
                        result1 = A[0] + A[1];
                    }
                    else
                    {
                        result1 = A[0] - A[1];
                    }
                    if (B[1] == "+")
                    {
                        result = result + result1;
                    }
                    else
                    {
                        result = result1 - result;
                    }
                }
                if ((B[1] == "(") && (B[4] == ")"))
                {
                    if (B[2] == "+")
                    {
                        result = A[1] + A[2];
                    }
                    else
                    {
                        result = A[1] - A[2];
                    }
                    if (B[3] == "+")
                    {
                        result = result + A[3];
                    }
                    else
                    {
                        result = result - A[3];
                    }
                    if (B[0] == "+")
                    {
                        result = result + A[0];
                    }
                    else
                    {
                        result = A[0] - result;
                    }
                }
                return result;
            }
            else
            {
                for (int i = 0; i < 3; i++)
                {
                    if (B[i] == "+")
                    {
                        result = result + A[i + 1];
                    }
                    else
                    {
                        result = result - A[i + 1];
                    }
                }
                return result;
            }
        }
        else
        {
            int result = A[0];
            if (1 == kuohao)
            {
                int result = 0;
                if ((B[1] == "(") && (B[3] == ")"))
                {
                    if (B[2] == "+")
                    {
                        result = A[1] + A[2];
                    }
                    else
                    {
                        if (A[1] > A[2])
                        {
                            result = A[1] - A[2];
                        }
                        else
                        {
                            A[1] = max;
                            result = A[1] - A[2];
                        }
                    }
                    if (B[0] == "+")
                    {
                        result = result + A[0];
                    }
                    else
                    {
                        if (A[0] > result)
                        {
                            result = A[0] - result;
                        }
                        else
                        {
                            B[0] = '+';
                            result = result + A[0];
                        }
                    }
                    if (B[4] == "+")
                    {
                        result = result + A[3];
                    }
                    else
                    {
                        if (result > A[3])
                        {
                            result = result - A[3];
                        }
                        else
                        {
                            A[3] = result / 2;
                            result = result - A[3];
                        }
                    }
                }
                if ((B[2] == "(") && (B[4] == ")"))
                {
                    int result1 = 0;
                    if (B[3] == "+")
                    {
                        result = A[2] + A[3];
                    }
                    else
                    {
                        if (A[2] > A[3])
                        {
                            result = A[2] - A[3];
                        }
                        else
                        {
                            A[2] = max;
                            result = A[2] - A[3];
                        }
                    }
                    if (B[0] == "+")
                    {
                        result1 = A[0] + A[1];
                    }
                    else
                    {
                        if (A[0] > A[1])
                        {
                            result1 = A[0] - A[1];
                        }
                        else
                        {
                            A[0] = max;
                            result1 = A[0] - A[1];
                        }
                    }
                    if (B[1] == "+")
                    {
                        result = result + result1;
                    }
                    else
                    {
                        if (result1 > result)
                        {
                            result = result1 - result;
                        }
                        else
                        {
                            B[1] = '+';
                            result = result + result1;
                        }
                    }
                }
                if ((B[1] == "(") && (B[4] == ")"))
                {
                    if (B[2] == "+")
                    {
                        result = A[1] + A[2];
                    }
                    else
                    {
                        if (A[1] > A[2])
                        {
                            result = A[1] - A[2];
                        }
                        else
                        {
                            A[1] = max;
                            result = A[1] - A[2];
                        }
                    }
                    if (B[3] == "+")
                    {
                        result = result + A[3];
                    }
                    else
                    {
                        if (result > A[3])
                        {
                            result = result - A[3];
                        }
                        else
                        {
                            B[3] = '+';
                            result = result + A[3];
                        }
                    }
                    if (B[0] == "+")
                    {
                        result = result + A[0];
                    }
                    else
                    {
                        if (A[0] > result)
                        {
                            result = A[0] - result;
                        }
                        else
                        {
                            B[0] = '+';
                            result = result + A[0];
                        }
                    }
                }
                return result;
            }
            else
            {
                for (int i = 0; i < 3; i++)
                {
                    if (B[i] == "+")
                    {
                        result = result + A[i + 1];
                    }
                    else
                    {
                        if (result>A[i + 1])
                        {
                            result = result - A[i + 1];
                        }
                        else
                        {
                            B[i] = '+';
                            result = result + A[i + 1];
                        }
                    }
                }
                return result;
            }
        }
    }
    
    //输出分数,并计算分数的值并且判断用户的计算是否正确
    int calculate_ProperFraction(int A[], int B[], int i, int min, int max, int print)
    {
        fstream fileout;
        fileout.open("BiaoDaShi.txt", ios::app);
        judge_Fraction(A[i], max, max);
        judge_Fraction(B[i], max, max);
        int divisor1 = great_common_Divisor(A[i], max);
        int divisor2 = great_common_Divisor(B[i], max);
        int inputfenzi, inputfenmu;
        int suanfu = rand() % 4;
        switch (suanfu)
        {
        case 0:
        {
                  if (0 == print)
                  {
                      cout << "请计算该分数算式(结果输入格式:分子 空格 分母):";
                      cout << A[i] / divisor1 << "/" << max / divisor1 << " + " << B[i] / divisor2 << "/" << max / divisor2 << " = " << endl;
                  }
                  else
                  {
                      cout << "请打开当前目录中的BiaoDaShi.txt文件,查看运算式,并将结果输入屏幕上!";
                      cout << "请计算该分数算式(结果输入格式:分子 空格 分母):";
                      fileout << A[i] / divisor1 << "/" << max / divisor1 << " + " << B[i] / divisor2 << "/" << max / divisor2 << " = " << endl;
                  }
                  cin >> inputfenzi >> inputfenmu;
                  int divisor3 = great_common_Divisor((A[i] + B[i]), max);
                  if (inputfenzi == ((A[i] + B[i]) / divisor3) && (inputfenmu == (max / divisor3)))
                  {
                      cout << "恭喜你答对了!" << endl;
                  }
                  else
                  {
                      cout << "答错了,继续加油哦!" << endl;
                  }
                  break;
        }
        case 1:
        {
                  if (0 == print)
                  {
                      cout << "请计算该分数算式(结果输入格式:分子 空格 分母):";
                      cout << A[i] / divisor1 << "/" << max / divisor1 << " - " << B[i] / divisor2 << "/" << max / divisor2 << " = " << endl;
                  }
                  else
                  {
                      cout << "请打开当前目录中的BiaoDaShi.txt文件,查看运算式,并将结果输入屏幕上!";
                      cout << "请计算该分数算式(结果输入格式:分子 空格 分母):";
                      fileout << A[i] / divisor1 << "/" << max / divisor1 << " - " << B[i] / divisor2 << "/" << max / divisor2 << " = " << endl;
                  }
                  cin >> inputfenzi >> inputfenmu;
                  int divisor3 = great_common_Divisor((A[i] - B[i]), max);
                  if (inputfenzi == ((A[i] - B[i]) / divisor3) && (inputfenmu == (max / divisor3)))
                  {
                      cout << "恭喜你答对了!" << endl;
                  }
                  else
                  {
                      cout << "答错了,继续加油哦!" << endl;
                  }
                  break;
        }
        case 2:
        {
                  if (0 == print)
                  {
                      cout << "请计算该分数算式(结果输入格式:分子 空格 分母):";
                      cout << A[i] / divisor1 << "/" << max / divisor1 << " x " << B[i] / divisor2 << "/" << max / divisor2 << " = " << endl;
                  }
                  else
                  {
                      cout << "请打开当前目录中的BiaoDaShi.txt文件,查看运算式,并将结果输入屏幕上!";
                      cout << "请计算该分数算式(结果输入格式:分子 空格 分母):";
                      fileout << A[i] / divisor1 << "/" << max / divisor1 << " x " << B[i] / divisor2 << "/" << max / divisor2 << " = " << endl;
                  }
                  cin >> inputfenzi >> inputfenmu;
                  int divisor3 = great_common_Divisor((A[i] * B[i]), (max * max));
                  if (inputfenzi == ((A[i] * B[i]) / divisor3) && (inputfenmu == ((max*max) / divisor3)))
                  {
                      cout << "恭喜你答对了!" << endl;
                  }
                  else
                  {
                      cout << "答错了,继续加油哦!" << endl;
                  }
                  break;
        }
        case 3:
        {
                  if (0 == print)
                  {
                      cout << "请计算该分数算式(结果输入格式:分子 空格 分母):";
                      cout << B[i] / divisor2 << "/" << max / divisor2 << " ÷ " << A[i] / divisor1 << "/" << max / divisor1 << " = " << endl;
                  }
                  else
                  {
                      cout << "请打开当前目录中的BiaoDaShi.txt文件,查看运算式,并将结果输入屏幕上!";
                      cout << "请计算该分数算式(结果输入格式:分子 空格 分母):";
                      fileout << B[i] / divisor2 << "/" << max / divisor2 << " ÷ " << A[i] / divisor1 << "/" << max / divisor1 << " = " << endl;
                  }
                  cin >> inputfenzi >> inputfenmu;
                  int divisor3 = great_common_Divisor(B[i], A[i]);
                  if ((inputfenzi == (B[i] / divisor3)) && (inputfenmu == (A[i] / divisor3)))
                  {
                      cout << "恭喜你答对了!" << endl;
                  }
                  else
                  {
                      cout << "答错了,继续加油哦!" << endl;
                  }
                  break;
        }
        }
        return 0;
    }
    
    //输出加减四则运算式,一种方式为输出到屏幕,另一种方式为输出到文件
    void output_JiaJian(int A[], string B[], int kuohao, int print)
    {
        if (0 == print)
        {
            if (1 == kuohao)
            {
                if ((B[1] == "(") && (B[3] == ")"))
                {
                    cout << A[0] << " " << B[0] << " " << B[1] << " " << A[1] << " " << B[2] << " " << A[2] << " " << B[3] << " " << B[4] << " " << A[3] << " = " << endl;
                }
                if ((B[2] == "(") && (B[4] == ")"))
                {
                    cout << A[0] << " " << B[0] << " " << A[1] << " " << B[1] << " " << B[2] << " " << A[2] << " " << B[3] << " " << A[3] << " " << B[4] << " " << " = " << endl;
                }
                if ((B[1] == "(") && (B[4] == ")"))
                {
                    cout << A[0] << " " << B[0] << " " << B[1] << " " << A[1] << " " << B[2] << " " << A[2] << " " << B[3] << " " << A[3] << " " << B[4] << " " << " = " << endl;
                }
            }
            else
            {
                for (int i = 0; i < 3; i++)
                {
                    cout << A[i] << " " << B[i] << " ";
                }
                cout << A[3] << " = " << endl;
            }
        }
        else
        {
            cout << "请打开当前目录中的BiaoDaShi.txt文件,查看运算式,并将结果输入屏幕上!";
            fstream fileout;
            fileout.open("BiaoDaShi.txt", ios::app);
            if (1 == kuohao)
            {
                if ((B[1] == "(") && (B[3] == ")"))
                {
                    fileout << A[0] << " " << B[0] << " " << B[1] << " " << A[1] << " " << B[2] << " " << A[2] << " " << B[3] << " " << B[4] << " " << A[3] << " = " << endl;
                }
                if ((B[2] == "(") && (B[4] == ")"))
                {
                    fileout << A[0] << " " << B[0] << " " << A[1] << " " << B[1] << " " << B[2] << " " << A[2] << " " << B[3] << " " << A[3] << " " << B[4] << " " << " = " << endl;
                }
                if ((B[1] == "(") && (B[4] == ")"))
                {
                    fileout << A[0] << " " << B[0] << " " << B[1] << " " << A[1] << " " << B[2] << " " << A[2] << " " << B[3] << " " << A[3] << " " << B[4] << " " << " = " << endl;
                }
            }
            else
            {
                for (int i = 0; i < 3; i++)
                {
                    fileout << A[i] << " " << B[i] << " ";
                }
                fileout << A[3] << " = " << endl;
            }
            fileout.close();
        }
    }
    
    //判断用户输入的结果是否正确,给出相应的提示
    void minus_JiaJian(int A[], string B[], int min, int max, int minus, int kuohao, int print)
    {
        int inputResult;
        create_Operand(A, min, max);
        create_Operator_JiaJian(B, kuohao);
        int calculateResult = calculate_Jiajian(A, B, kuohao, minus, min, max);
        output_JiaJian(A, B, kuohao, print);
        cin >> inputResult;
        if (calculateResult == inputResult)
        {
            cout << "恭喜你答对了!" << endl;
        }
        else
        {
            cout << "答错了,继续加油哦!" << endl;
        }
    }
    
    //生成运算符数组
    int YSShuZus(string B[], int kuohao)
    {
        int intYunSFNum;
        if (0 == kuohao)   //如果没有括号
        {
            MulDivShuZus(B);
            intYunSFNum = 3;
        }
        else  //如果有括号
        {
            MulDivShuZus(B);    //获得没有括号的运算符数组
            string chLinShi[3];   //临时数组
            for (int i = 0; i < 3; i++)
            {
                chLinShi[i] = B[i];
            }
            intYunSFNum = 3;
            int intRealstring[3];
            for (int i = 0; i < 3; i++)   //将运算符按优先级存储起来
            {
                if (B[i] == "+" || B[i] == "-")
                {
                    intRealstring[i] = 1;
                }
                else
                {
                    intRealstring[i] = 2;
                }
            }
    
            for (int i = 0; i < 2; i++)
            {
                if (chLinShi[0] == "÷")
                {
                    if (chLinShi[1] == "÷")
                    {
                        intYunSFNum = 5;
                        B[0] = "(";
                        B[1] = chLinShi[0];
                        B[2] = ")";
                        B[3] = chLinShi[1];
                        B[4] = chLinShi[2];
                        break;
                    }
    
                }
                if (intRealstring[i]<intRealstring[i + 1])
                {
                    if (i == 0)
                    {
                        if (chLinShi[i + 1] == "÷")
                        {
                            if (chLinShi[i + 2] == "÷")
                            {
                                intYunSFNum = 7;
                                B[0] = "(";
                                B[1] = "(";
                                B[2] = chLinShi[0];
                                B[3] = ")";
                                B[4] = chLinShi[1];
                                B[5] = ")";
                                B[6] = chLinShi[2];
                            }
                            else
                            {
                                intYunSFNum = 5;
                                B[0] = "(";
                                B[1] = chLinShi[0];
                                B[2] = ")";
                                B[3] = chLinShi[1];
                                B[4] = chLinShi[2];
                            }
                        }
                        else
                        {
                            intYunSFNum = 5;
                            B[0] = "(";
                            B[1] = chLinShi[0];
                            B[2] = ")";
                            B[3] = chLinShi[1];
                            B[4] = chLinShi[2];
                        }
                    }
                    else
                    {
                        intYunSFNum = 5;
                        B[0] = chLinShi[0];
                        B[1] = "(";
                        B[2] = chLinShi[1];
                        B[3] = ")";
                        B[4] = chLinShi[2];
                    }
                }
            }
        }
        return intYunSFNum;
    }
    
    //
    
    //生成两个存储数据的数组,主函数中的作用是用来进行判断是进行两位真分数的判断还是多位整数的四则运算
    void createArray(int A[], int B[], int count, int min, int max)
    {
        while ((max - min + 1) < count)
        {
            cout << "数值范围输入错误,请重新输入数值范围(友情提示:数值范围应大于运算式的数量)!" << endl;
            cout << "请输入参与四则运算的数值范围(格式如:1  100):";
            cin >> min >> max;
        }
        for (int i = 0; i < count; i++)
        {
    
            A[i] = min + rand() % (max - min + 1);
            B[i] = min + rand() % (max - min + 1);
    
            for (int j = 0; j < i; j++)
            {
                if (A[i] == A[j])
                {
                    A[i] = min + rand() % (max - min + 1);
                    j = -1;    //通过设置j,对新生成的数A[i],使其和前面的所有数进行比较,此循环重复
                }
            }
            for (int j = 0; j < i; j++)
            {
                if (B[i] == B[j])
                {
                    B[i] = min + rand() % (max - min + 1);
                    j = -1;
                }
            }
        }
    }
    
    //生成加减运算符
    void AddRedu(string &stringArry)
    {
        //srand((int)time(NULL));
        int intJudge;      //此变量分别以1,2,3,4代表+、-、×、÷
    
        intJudge = 1 + rand() % 2;
        switch (intJudge)
        {
        case 1:
        {
                  stringArry = '+';
                  break;
        }
        case 2:
        {
                  stringArry = '-';
                  break;
        }
        }
    }
    
    //生成乘除运算符
    void MulDiv(string &stringArry)
    {
        //srand((int)time(NULL));
        int intJudge;      //此变量分别以1,2,3,4代表+、-、×、÷
    
        intJudge = 1 + rand() % 4;
        switch (intJudge)
        {
        case 1:
        {
                  stringArry = '+';
                  break;
        }
        case 2:
        {
                  stringArry = '-';
                  break;
        }
        case 3:
        {
                  stringArry = "×";
                  break;
        }
        case 4:
        {
                  stringArry = "÷";
                  break;
        }
        }
    }
    
    //判断乘除号,生成字符数组
    void MulDivShuZu(string stringMDYSF[], int intMulDiv)
    {
        //srand((int)time(NULL));     
        if (intMulDiv == 0)          //如果没有乘除法
        {
            //srand((int)time(NULL));    //若还原还原此处
            for (int i = 0; i < 3; i++)
            {
                AddRedu(stringMDYSF[i]);
            }
        }
        else                        //如果有乘除法
        {
            //srand((int)time(NULL));    //若还原还原此处
            for (int i = 0; i < 3; i++)
            {
                MulDiv(stringMDYSF[i]);
            }
    
            for (int i = 0; i < 3; i++)    //不能有连续的3个除法
            {
                if (stringMDYSF[i] == "÷")
                {
                    if (stringMDYSF[i + 1] == "÷" && stringMDYSF[i + 2] == "÷")
                    {
                        AddRedu(stringMDYSF[i + 2]);
                    }
                }
            }
    
        }
    }
    
    //生成运算符数组
    void YSShuZu(string stringYunSF[], int intMulDiv, int intKuoHao, int &intYunSFNum)
    {
        //srand((int)time(NULL));
        if (0 == intKuoHao)   //如果没有括号
        {
            MulDivShuZu(stringYunSF, intMulDiv);
            intYunSFNum = 3;
        }
        else  //如果有括号
        {
            MulDivShuZu(stringYunSF, intMulDiv);    //获得没有括号的运算符数组
    
            string chLinShi[3];   //临时数组
            for (int i = 0; i < 3; i++)
            {
                chLinShi[i] = stringYunSF[i];
            }
    
            if (0 == intMulDiv)     //如果没有乘除,只有加减,加上括号
            {
                int intKHaoNum;
                //intKHaoNum = 1 + rand() % 2;  用于判断生成几个括号时使用此功能
                intKHaoNum = 1;
    
                if (1 == intKHaoNum)    //加一个括号
                {
                    intYunSFNum = 5;    //运算符的个数为5个
                    int intLeftLocation;
                    intLeftLocation = 1 + rand() % 2;
                    int intRightLocation;
                    int a = intLeftLocation + 2;
                    intRightLocation = a + rand() % (5 - a);
    
                    stringYunSF[intLeftLocation] = "(";
                    stringYunSF[intRightLocation] = ")";
    
                    int j = 0;
                    for (int i = 0; i < 5; i++)
                    {
                        if ((stringYunSF[i] != "(") && (stringYunSF[i] != ")"))
                        {
                            stringYunSF[i] = chLinShi[j];
                            j++;
                        }
                    }
    
    
                }
                /*  用于判断生成几个括号时使用此功能
                else   //加两个括号
                {
                    intYunSFNum = 7;     //运算符个数为7个
                    stringYunSF[0] = "(";
                    stringYunSF[1] = chLinShi[0];
                    stringYunSF[2] = ")";
                    stringYunSF[3] = chLinShi[1];
                    stringYunSF[4] = "(";
                    stringYunSF[5] = chLinShi[2];
                    stringYunSF[6] = ")";
                }*/
            }
            else   //如果有乘除,加上括号
            {
                intYunSFNum = 3;
    
                int intRealstring[3];
                for (int i = 0; i < 3; i++)   //将运算符按优先级存储起来
                {
                    if (stringYunSF[i] == "+" || stringYunSF[i] == "-")
                    {
                        intRealstring[i] = 1;
                    }
                    else
                    {
                        intRealstring[i] = 2;
                    }
                }
    
                for (int i = 0; i < 2; i++)
                {
                    if (chLinShi[0] == "÷")
                    {
                        if (chLinShi[1] == "÷")
                        {
                            intYunSFNum = 5;
                            stringYunSF[0] = "(";
                            stringYunSF[1] = chLinShi[0];
                            stringYunSF[2] = ")";
                            stringYunSF[3] = chLinShi[1];
                            stringYunSF[4] = chLinShi[2];
                            break;
                        }
    
                    }
                    if (intRealstring[i]<intRealstring[i + 1])
                    {
                        if (i == 0)
                        {
                            if (chLinShi[i + 1] == "÷")
                            {
                                if (chLinShi[i + 2] == "÷")
                                {
                                    intYunSFNum = 7;
                                    stringYunSF[0] = "(";
                                    stringYunSF[1] = "(";
                                    stringYunSF[2] = chLinShi[0];
                                    stringYunSF[3] = ")";
                                    stringYunSF[4] = chLinShi[1];
                                    stringYunSF[5] = ")";
                                    stringYunSF[6] = chLinShi[2];
                                }
                                else
                                {
                                    intYunSFNum = 5;
                                    stringYunSF[0] = "(";
                                    stringYunSF[1] = chLinShi[0];
                                    stringYunSF[2] = ")";
                                    stringYunSF[3] = chLinShi[1];
                                    stringYunSF[4] = chLinShi[2];
                                }
                            }
                            else
                            {
                                intYunSFNum = 5;
                                stringYunSF[0] = "(";
                                stringYunSF[1] = chLinShi[0];
                                stringYunSF[2] = ")";
                                stringYunSF[3] = chLinShi[1];
                                stringYunSF[4] = chLinShi[2];
                            }
                        }
                        else
                        {
                            intYunSFNum = 5;
                            stringYunSF[0] = chLinShi[0];
                            stringYunSF[1] = "(";
                            stringYunSF[2] = chLinShi[1];
                            stringYunSF[3] = ")";
                            stringYunSF[4] = chLinShi[2];
                        }
                    }
                }
    
            }
        }
    
    
    }
    
    //函数实现有无余数
    void RemainderFouction(int intNum[], string stringYunSuanFu[], int intYunSuanFNu)
    {
    
        //包括括号和乘除法的区分
        //首先实现对乘除法有无余数的判断
        //其次加入括号,判断括号内的乘除法有无余数的实现
    
        //对运算符数组循环寻找括号和乘除号
        int intCycleNum = 0;
        int intParentNum = 0;
        for (intCycleNum = 0; intCycleNum < intYunSuanFNu; intCycleNum++)
        {
            if ((stringYunSuanFu[intCycleNum] == "(") || (stringYunSuanFu[intCycleNum] == ")"))
            {
                intParentNum += 1;
            }
    
            if (stringYunSuanFu[intCycleNum] == "÷")
            {
                if (intNum[intCycleNum + 1 - intParentNum] == 0)
                {
                    intNum[intCycleNum + 1 - intParentNum] = 1 + rand() % 10;
                }
    
                if (intCycleNum != 0 && stringYunSuanFu[intCycleNum - 1] == ")")    //此IF语句是测试(a+b)÷c的情况
                {
                    int num;
                    num = intCycleNum - intParentNum;     //标识没有括号的字符数组中除号的位置
    
                    int intSum;   //括号内的数的运算结果
                    int intLeft;  //括号内参与运算的左边的数
                    int intRight;  //括号内参与运算的右边的数
                    string strYunSF;
                    intLeft = intNum[num - 1];
                    intRight = intNum[num];
                    strYunSF = stringYunSuanFu[intCycleNum - 2];
                    if (strYunSF == "+")
                    {
                        intSum = intLeft + intRight;
                    }
                    else if (strYunSF == "-")
                    {
                        intSum = intLeft - intRight;
                        if (intSum < 0)
                        {
                            intNum[num - 1] = intRight;
                            intNum[num] = intLeft;
                            intSum = intRight - intLeft;
                        }
    
                    }
                    else if (strYunSF == "×")
                    {
                        intSum = intLeft * intRight;
                    }
                    else
                    {
                        intSum = intLeft / intRight;
                    }
    
                    if (intSum < 0)
                    {
                        int a;
                        a = intNum[num];
                        intNum[num] = intNum[num + 1];
                        intNum[num + 1] = intNum[num];
                        intSum = intNum[num] - intNum[num + 1];
                    }
    
                    int intYushu;    //余数
                    intYushu = intSum % (intNum[num + 1]);   //除号两边的数求商
                    if (intYushu != 0)
                    {
                        if (intSum == 1)
                        {
                            intNum[num + 1] = 1;
                        }
                        else
                        {
                            int j = intSum - 1;
                            for (int i = 0; i < intSum; i++)
                            {
                                intYushu = intSum%j;
                                if (intYushu == 0)
                                {
                                    intNum[num + 1] = j;
                                    break;
                                }
                                j--;
                            }
                        }
    
                    }
    
                    //下面是(a+b)÷c÷d的情况
                    if (stringYunSuanFu[intCycleNum + 1] == "÷")
                    {
                        int intOneResult;         //intOneReslut=(a+b)÷c
                        intOneResult = intSum / intNum[num + 1];
                        int intSecResult;         //intSecResult=(a+b)÷c÷d
                        if (intNum[num + 2] == 0)
                        {
                            intNum[num + 2] = 1 + rand() % 10;
                        }
                        intSecResult = intOneResult % (intNum[num + 2]);
    
                        if (intSecResult != 0)
                        {
                            if (intOneResult == 1)
                            {
                                intNum[num + 2] = 1;
                            }
                            else
                            {
                                int intSecYue;
                                intSecYue = intOneResult - 1;
    
                                for (int i = 0; i < intOneResult; i++)
                                {
                                    intSecResult = intOneResult%intSecYue;
                                    if (intSecResult == 0)
                                    {
                                        intNum[num + 2] = intSecYue;
                                        break;
                                    }
                                    intSecYue--;
                                }
                            }
    
                        }
    
                    }
    
                }
                else   //a÷b的情况
                {
                    int num;
                    num = intCycleNum - intParentNum;
    
                    int YuShu;
                    if (intNum[num + 1] == 0)
                    {
                        intNum[num + 1] = 1 + rand() % 10;
                    }
                    YuShu = (intNum[num]) % (intNum[num + 1]);
                    if (YuShu != 0)
                    {
                        if (intNum[num] == 1)
                        {
                            intNum[num + 1] = 1;
                        }
                        else
                        {
                            int j = intNum[num] - 1;
                            for (int i = 0; i < intNum[num]; i++)
                            {
                                YuShu = intNum[num] % j;
                                if (YuShu == 0)
                                {
                                    intNum[num + 1] = j;
                                    break;
                                }
                                j--;
                            }
                        }
    
                    }
    
                    //下面是a÷b÷c的情况
                    if (stringYunSuanFu[intCycleNum + 1] == "÷")
                    {
                        int OneRes;
                        OneRes = intNum[num] % intNum[num + 1];
                        if (OneRes != 0)
                        {
                            int j;
                            j = intNum[num] - 1;
                            for (int i = 0; i < intNum[num]; i++)
                            {
                                OneRes = intNum[num] % j;
                                if (OneRes == 0)
                                {
                                    intNum[num + 1] = j;
                                    break;
                                }
                                j--;
                            }
                        }
                        OneRes = intNum[num] / intNum[num + 1];
                        int yushus;
                        if (intNum[num + 2] == 0)
                        {
                            intNum[num + 2] = 1 + rand() % 10;
                        }
                        yushus = OneRes % (intNum[num + 2]);
                        if (yushus != 0)
                        {
                            if (OneRes == 1)
                            {
                                intNum[num + 2] = 1;
                            }
                            else
                            {
                                int yueshu;
                                yueshu = OneRes - 1;
                                for (int i = 0; i < OneRes; i++)
                                {
                                    yushus = OneRes%yueshu;
                                    if (yushus == 0)
                                    {
                                        intNum[num + 2] = yueshu;
                                        break;
                                    }
                                    yueshu--;
                                }
                            }
    
                        }
                    }
                }
            }
    
        }
    
        //
        if (stringYunSuanFu[0] == "÷" && stringYunSuanFu[1] == "(" && stringYunSuanFu[3] == ")")         //a÷(b+c)
        {
            int intTemps;
            if (stringYunSuanFu[2] == "+")
            {
                intTemps = intNum[1] + intNum[2];
                int yushuab;
                yushuab = intNum[0] % intTemps;
                if (yushuab != 0)
                {
                    intNum[0] = 2 * intTemps;
                }
                //cout << "yueshu=" << yushuab << " ";
                //cout << "第一种情况:" << "intTemps=" << intTemps << " " << "intNum[0]=" << intNum[0] << endl;
            }
            if (stringYunSuanFu[2] == "-")
            {
                intTemps = intNum[1] - intNum[2];
                if (intTemps < 0)
                {
                    int aaa;
                    aaa = intNum[1];
                    intNum[1] = intNum[2];
                    intNum[2] = aaa;
    
                    intTemps = intNum[1] - intNum[2];
                }
                if (intTemps == 0)
                {
                    intNum[2] = 1 + rand() % 10;
                    intNum[1] = intNum[2] + rand() % 3;
                    intTemps = intNum[1] - intNum[2];
                }
                int yushua;
                yushua = intNum[0] % intTemps;
                if (yushua != 0)
                {
                    intNum[0] = 2 * intTemps;
                }
    
                //cout << "yueshu=" << yushua << " ";
                //cout << "第二种情况:" << "intTemps=" << intTemps << " " << "intNum[0]=" << intNum[0] << endl;
            }
    
            for (int i = 0; i < 4; i++)
            {
                cout << intNum[i] << " ";
            }
            cout << endl;
        }
    }
    
    //含有乘除法的计算
    double OperatorMD(int intYunSuanShu[], string strYunSuanFu[], int YunSuanfuN)
    {
        double jieguo = 0;
    
        if ((strYunSuanFu[0] == "(") && (strYunSuanFu[1] == "("))
        {
            double jieguo1;
            if (strYunSuanFu[2] == "+")
            {
                jieguo = (intYunSuanShu[0] + intYunSuanShu[1]) / intYunSuanShu[2] / intYunSuanShu[3];
            }
            else
            {
                jieguo = (intYunSuanShu[0] - intYunSuanShu[1]) / intYunSuanShu[2] / intYunSuanShu[3];
            }
        }
        if (strYunSuanFu[0] == "(")
        {
            double jieguo1;
            if (strYunSuanFu[1] == "+")
            {
                jieguo1 = intYunSuanShu[0] + intYunSuanShu[1];
            }
            else if (strYunSuanFu[1] == "-")
            {
                jieguo1 = intYunSuanShu[0] - intYunSuanShu[1];
            }
            else
            {
                jieguo1 = intYunSuanShu[0] / intYunSuanShu[1];
            }
    
            if (strYunSuanFu[3] == "×")
            {
                jieguo1 = jieguo1*intYunSuanShu[2];
            }
            else
            {
                jieguo1 = jieguo1 / intYunSuanShu[2];
            }
    
            if (strYunSuanFu[4] == "+")
            {
                jieguo = jieguo1 + intYunSuanShu[3];
            }
            else if (strYunSuanFu[4] == "-")
            {
                jieguo = jieguo1 - intYunSuanShu[3];
            }
            else if (strYunSuanFu[4] == "×")
            {
                jieguo = jieguo1 * intYunSuanShu[3];
            }
            else
            {
                jieguo = jieguo1 / intYunSuanShu[3];
            }
        }
    
        if (strYunSuanFu[1] == "(" && strYunSuanFu[0] != "(")
        {
            cout << "开始运行!" << endl;
            int jieguo1;
            if (strYunSuanFu[2] == "+")
            {
                if (strYunSuanFu[0] == "+")
                {
                    if (strYunSuanFu[4] == "×")
                    {
                        jieguo = intYunSuanShu[0] + (intYunSuanShu[1] + intYunSuanShu[2])*intYunSuanShu[3];
                        cout << "+(+)*" << endl;
                    }
                    else
                    {
                        jieguo = intYunSuanShu[0] + (intYunSuanShu[1] + intYunSuanShu[2]) / intYunSuanShu[3];
                        cout << "+(+)/" << endl;
                    }
                }
                if (strYunSuanFu[0] == "-")
                {
                    if (strYunSuanFu[4] == "×")
                    {
                        jieguo = intYunSuanShu[0] - (intYunSuanShu[1] + intYunSuanShu[2])*intYunSuanShu[3];
                        cout << "-(+)*" << endl;
                    }
                    else
                    {
                        jieguo = intYunSuanShu[0] - (intYunSuanShu[1] + intYunSuanShu[2]) / intYunSuanShu[3];
                        cout << "-(+)/" << endl;
                    }
                }
                if (strYunSuanFu[0] == "×")
                {
                    if (strYunSuanFu[4] == "×")
                    {
                        jieguo = intYunSuanShu[0] * (intYunSuanShu[1] + intYunSuanShu[2])*intYunSuanShu[3];
                        cout << "*(+)*" << endl;
                    }
                    else
                    {
                        jieguo = intYunSuanShu[0] * (intYunSuanShu[1] + intYunSuanShu[2]) / intYunSuanShu[3];
                        cout << "*(+)/" << endl;
                    }
                }
                if (strYunSuanFu[0] == "÷")
                {
                    if (strYunSuanFu[4] == "×")
                    {
                        jieguo = intYunSuanShu[0] / (intYunSuanShu[1] + intYunSuanShu[2])*intYunSuanShu[3];
                        cout << "/(+)*" << endl;
                    }
                    else
                    {
                        jieguo = intYunSuanShu[0] / (intYunSuanShu[1] + intYunSuanShu[2]) / intYunSuanShu[3];
                        cout << "/(+)/" << endl;
                    }
                }
            }
            else
            {
                if (strYunSuanFu[0] == "+")
                {
                    if (strYunSuanFu[4] == "×")
                    {
                        jieguo = intYunSuanShu[0] + (intYunSuanShu[1] - intYunSuanShu[2])*intYunSuanShu[3];
                        cout << "+(-)*" << endl;
                    }
                    else
                    {
                        jieguo = intYunSuanShu[0] + (intYunSuanShu[1] - intYunSuanShu[2]) / intYunSuanShu[3];
                        cout << "+(-)/" << endl;
                    }
                }
                if (strYunSuanFu[0] == "-")
                {
                    if (strYunSuanFu[4] == "×")
                    {
                        jieguo = intYunSuanShu[0] - (intYunSuanShu[1] - intYunSuanShu[2])*intYunSuanShu[3];
                        cout << "-(-)*" << endl;
                    }
                    else
                    {
                        jieguo = intYunSuanShu[0] - (intYunSuanShu[1] - intYunSuanShu[2]) / intYunSuanShu[3];
                        cout << "-(-)*" << endl;
                    }
                }
                if (strYunSuanFu[0] == "×")
                {
                    if (strYunSuanFu[4] == "×")
                    {
                        jieguo = intYunSuanShu[0] * (intYunSuanShu[1] - intYunSuanShu[2])*intYunSuanShu[3];
                        cout << "*(-)*" << endl;
                    }
                    else
                    {
                        jieguo = intYunSuanShu[0] * (intYunSuanShu[1] - intYunSuanShu[2]) / intYunSuanShu[3];
                        cout << "*(-)/" << endl;
                    }
                }
                if (strYunSuanFu[0] == "÷")
                {
                    if (strYunSuanFu[4] == "×")
                    {
                        int ab = intYunSuanShu[1] - intYunSuanShu[2];
                        if (ab == 0)
                        {
                            intYunSuanShu[1] = 8;
                            intYunSuanShu[2] = 7 - rand() % 4;
                        }
                        jieguo = intYunSuanShu[0] / (intYunSuanShu[1] - intYunSuanShu[2])*intYunSuanShu[3];
                        cout << "/(-)*" << endl;
                    }
                    else
                    {
                        int ab = intYunSuanShu[1] - intYunSuanShu[2];
                        if (ab == 0)
                        {
                            intYunSuanShu[1] = 8;
                            intYunSuanShu[2] = 7 - rand() % 4;
                        }
                        jieguo = intYunSuanShu[0] / (intYunSuanShu[1] - intYunSuanShu[2]) / intYunSuanShu[3];
                        cout << "/(-)/" << endl;
                    }
                }
            }
    
        }
        if ((strYunSuanFu[0] != "(") && (strYunSuanFu[1] != "("))
        {
            int jieguo1;
            if (strYunSuanFu[0] == "+")
            {
                if (strYunSuanFu[1] == "+")
                {
                    if (strYunSuanFu[2] == "+")
                    {
                        jieguo = intYunSuanShu[0] + intYunSuanShu[1] + intYunSuanShu[2] + intYunSuanShu[3];
                    }
                    else
                    {
                        jieguo = intYunSuanShu[0] + intYunSuanShu[1] + intYunSuanShu[2] - intYunSuanShu[3];
                    }
                }
                else
                {
                    if (strYunSuanFu[2] == "+")
                    {
                        jieguo = intYunSuanShu[0] + intYunSuanShu[1] - intYunSuanShu[2] + intYunSuanShu[3];
                    }
                    else
                    {
                        jieguo = intYunSuanShu[0] + intYunSuanShu[1] - intYunSuanShu[2] - intYunSuanShu[3];
                    }
                }
            }
            if (strYunSuanFu[0] == "-")
            {
                if (strYunSuanFu[1] == "+")
                {
                    if (strYunSuanFu[2] == "+")
                    {
                        jieguo = intYunSuanShu[0] - intYunSuanShu[1] + intYunSuanShu[2] + intYunSuanShu[3];
                    }
                    else
                    {
                        jieguo = intYunSuanShu[0] - intYunSuanShu[1] + intYunSuanShu[2] - intYunSuanShu[3];
                    }
                }
                if (strYunSuanFu[1] == "-")
                {
                    if (strYunSuanFu[2] == "+")
                    {
                        jieguo = intYunSuanShu[0] - intYunSuanShu[1] - intYunSuanShu[2] + intYunSuanShu[3];
                    }
                    else
                    {
                        jieguo = intYunSuanShu[0] - intYunSuanShu[1] - intYunSuanShu[2] - intYunSuanShu[3];
                    }
                }
                if (strYunSuanFu[1] == "×")
                {
                    if (strYunSuanFu[2] == "+")
                    {
                        jieguo = intYunSuanShu[0] - intYunSuanShu[1] * intYunSuanShu[2] + intYunSuanShu[3];
                    }
                    else
                    {
                        jieguo = intYunSuanShu[0] - intYunSuanShu[1] * intYunSuanShu[2] - intYunSuanShu[3];
                    }
                }
    
                if (strYunSuanFu[1] == "÷")
                {
                    if (strYunSuanFu[2] == "+")
                    {
                        jieguo = intYunSuanShu[0] - intYunSuanShu[1] / intYunSuanShu[2] + intYunSuanShu[3];
                    }
                    else
                    {
                        jieguo = intYunSuanShu[0] - intYunSuanShu[1] / intYunSuanShu[2] - intYunSuanShu[3];
                    }
                }
            }
    
    
    
            if (strYunSuanFu[0] == "×")
            {
                if (strYunSuanFu[1] == "+")
                {
                    if (strYunSuanFu[2] == "+")
                    {
                        jieguo = intYunSuanShu[0] * intYunSuanShu[1] + intYunSuanShu[2] + intYunSuanShu[3];
                    }
                    else
                    {
                        jieguo = intYunSuanShu[0] * intYunSuanShu[1] + intYunSuanShu[2] - intYunSuanShu[3];
                    }
                }
                if (strYunSuanFu[1] == "-")
                {
                    if (strYunSuanFu[2] == "+")
                    {
                        jieguo = intYunSuanShu[0] * intYunSuanShu[1] - intYunSuanShu[2] + intYunSuanShu[3];
                    }
                    else
                    {
                        jieguo = intYunSuanShu[0] * intYunSuanShu[1] - intYunSuanShu[2] - intYunSuanShu[3];
                    }
                }
                if (strYunSuanFu[1] == "×")
                {
                    if (strYunSuanFu[2] == "+")
                    {
                        jieguo = intYunSuanShu[0] * intYunSuanShu[1] * intYunSuanShu[2] + intYunSuanShu[3];
                    }
                    if (strYunSuanFu[2] == "-")
                    {
                        jieguo = intYunSuanShu[0] * intYunSuanShu[1] * intYunSuanShu[2] - intYunSuanShu[3];
                    }
                    if (strYunSuanFu[2] == "×")
                    {
                        jieguo = intYunSuanShu[0] * intYunSuanShu[1] * intYunSuanShu[2] * intYunSuanShu[3];
                    }
                    if (strYunSuanFu[2] == "÷")
                    {
                        jieguo = intYunSuanShu[0] * intYunSuanShu[1] * intYunSuanShu[2] / intYunSuanShu[3];
                    }
                }
                if (strYunSuanFu[1] == "÷")   //strYunSuanFu[1]=="÷"
                {
                    if (strYunSuanFu[2] == "+")
                    {
                        jieguo = intYunSuanShu[0] * intYunSuanShu[1] / intYunSuanShu[2] + intYunSuanShu[3];
                    }
                    if (strYunSuanFu[2] == "-")
                    {
                        jieguo = intYunSuanShu[0] * intYunSuanShu[1] / intYunSuanShu[2] - intYunSuanShu[3];
                    }
                    if (strYunSuanFu[2] == "×")
                    {
                        jieguo = intYunSuanShu[0] * intYunSuanShu[1] / intYunSuanShu[2] * intYunSuanShu[3];
                    }
                    if (strYunSuanFu[2] == "÷")
                    {
                        jieguo = intYunSuanShu[0] * intYunSuanShu[1] / intYunSuanShu[2] / intYunSuanShu[3];
                    }
                }
            }
            if (strYunSuanFu[0] == "÷")
            {
                if (strYunSuanFu[1] == "+")
                {
                    if (strYunSuanFu[2] == "+")
                    {
                        jieguo = intYunSuanShu[0] / intYunSuanShu[1] + intYunSuanShu[2] + intYunSuanShu[3];
                    }
                    else
                    {
                        jieguo = intYunSuanShu[0] / intYunSuanShu[1] + intYunSuanShu[2] - intYunSuanShu[3];
                    }
                }
                if (strYunSuanFu[1] == "-")
                {
                    if (strYunSuanFu[2] == "+")
                    {
                        jieguo = intYunSuanShu[0] / intYunSuanShu[1] - intYunSuanShu[2] + intYunSuanShu[3];
                    }
                    else
                    {
                        jieguo = intYunSuanShu[0] / intYunSuanShu[1] - intYunSuanShu[2] - intYunSuanShu[3];
                    }
                }
                if (strYunSuanFu[1] == "×")
                {
                    if (strYunSuanFu[2] == "+")
                    {
                        jieguo = intYunSuanShu[0] / intYunSuanShu[1] * intYunSuanShu[2] + intYunSuanShu[3];
                    }
                    if (strYunSuanFu[2] == "-")
                    {
                        jieguo = intYunSuanShu[0] / intYunSuanShu[1] * intYunSuanShu[2] - intYunSuanShu[3];
                    }
                    if (strYunSuanFu[2] == "×")
                    {
                        jieguo = intYunSuanShu[0] / intYunSuanShu[1] * intYunSuanShu[2] * intYunSuanShu[3];
                    }
                    if (strYunSuanFu[2] == "÷")
                    {
                        jieguo = intYunSuanShu[0] / intYunSuanShu[1] * intYunSuanShu[2] / intYunSuanShu[3];
                    }
                }
    
            }
        }
    
    
        return jieguo;
    }
    
    //乘除运算的输出
    void MDOutput(int intNumC[], string stringOperator[], int intYunSFLen,int intPrintS)
    {
        //对运算式进行输出
        if (0 == intPrintS)
        {
            int fuhaojishus0 = 0;
            for (int shuchushuzi = 0; shuchushuzi < 4; shuchushuzi++)
            {
                if (shuchushuzi == 0)
                {
                    if (stringOperator[0] == "(")
                    {
                        cout << stringOperator[0];
                        fuhaojishus0 = 1;
    
                        if (stringOperator[1] == "(")
                        {
                            cout << stringOperator[0];
                            fuhaojishus0 = 2;
                        }
                    }
    
                }
    
                cout << intNumC[shuchushuzi];
    
                for (; fuhaojishus0 < intYunSFLen;)
                {
                    while (stringOperator[fuhaojishus0] == ")")
                    {
                        cout << ")";
                        fuhaojishus0 += 1;
                    }
                    if (fuhaojishus0 < intYunSFLen)
                    {
                        cout << stringOperator[fuhaojishus0];    //输出右括号紧邻的运算符或者是输出第一个符号
                    }
    
                    fuhaojishus0 += 1;
                    while (stringOperator[fuhaojishus0] == "(")
                    {
                        cout << "(";
                        fuhaojishus0 += 1;
                    }
                    break;
                }
            }
        }
        else
        {
            fstream outfile;
            outfile.open("BiaoDaShi.txt", ios::app);
    
            int fuhaojishus0 = 0;
            for (int shuchushuzi = 0; shuchushuzi < 4; shuchushuzi++)
            {
                if (shuchushuzi == 0)
                {
                    if (stringOperator[0] == "(")
                    {
                        outfile << stringOperator[0];
                        fuhaojishus0 = 1;
    
                        if (stringOperator[1] == "(")
                        {
                            outfile << stringOperator[0];
                            fuhaojishus0 = 2;
                        }
                    }
    
                }
    
                outfile << intNumC[shuchushuzi];
    
                for (; fuhaojishus0 < intYunSFLen;)
                {
                    while (stringOperator[fuhaojishus0] == ")")
                    {
                        outfile << ")";
                        fuhaojishus0 += 1;
                    }
                    if (fuhaojishus0 < intYunSFLen)
                    {
                        outfile << stringOperator[fuhaojishus0];    //输出右括号紧邻的运算符或者是输出第一个符号
                    }
    
                    fuhaojishus0 += 1;
                    while (stringOperator[fuhaojishus0] == "(")
                    {
                        outfile << "(";
                        fuhaojishus0 += 1;
                    }
                    break;
                }
            }
            outfile << endl;
            outfile.close();
        }
    }
    
    //
    
    void output_ChengChu(int A[], string B[], int min, int max, int kuohao, int print)
    {
        int kuohaoNum = 0;
        fstream fileout;
        fileout.open("BiaoDaShi.txt", ios::app);
        create_Operand(A, min, max);
        MulDivShuZus(B);
        int suanfuNum = YSShuZus(B, kuohao);
        RemainderFouction(A, B, suanfuNum);
        if (3 == suanfuNum)
        {
            if (0 == print)
            {
                cout << A[0] << " " << B[0] << " " << A[1] << " " << B[1] << " " << A[2] << " " << B[2] << " " << A[3] << " = " << endl;
            }
            else
            {
                fileout << A[0] << " " << B[0] << " " << A[1] << " " << B[1] << " " << A[2] << " " << B[2] << " " << A[3] << " = " << endl;
            }
        }
        else
        {
            for (int i = 0; i < suanfuNum; i++)
            {
                if ((B[i] == "(") || (B[i] == ")"))
                {
                    if (i == 0 || ((i != 0) && B[i] == "("))
                    {
                        kuohaoNum++;
                        cout << B[i];
                        continue;
                    }
                    else
                    {
                        cout << A[i - kuohaoNum];
                        kuohaoNum++;
                        cout << B[i];
                        continue;
                    }
                }
                else
                {
                    if (B[i - 1] == "(")
                    {
                        cout << A[i - kuohaoNum] << B[i];
                    }
                    else
                    {
                        cout << B[i] << A[i - kuohaoNum + 1];
                    }
                }
            }
            cout << " = " << endl;
        }
    }
    
    //主函数
    int main()
    {
        fstream fileout;
        fileout.open("BiaoDaShi.txt", ios::out); //以输出的方式打开文件,将其上次存放的内容清空
        fileout.close(); //关闭文件
    
        srand((int)time(NULL));
    
        int intPrintStyle;          //定义打印方式(DOS界面打印、输出到文件)
        int intMultiplyDivide;      //定义是否有乘除法,0代表没有,1代表有
        int intMax, min;            //定义四则运算中的数的取值范围
        int intMinus;               //定义是否有负数,0代表没有,1代表有
        int intRemainder;           //定义是否有余数,0代表没有,1代表有
        int intParentheses;         //定义是否有括号,0代表没有,1代表有
        int intCount;               //定义生成几个运算式
        int intYunSFLen = 0;            //记录运算符长度
    
        cout << "请选择打印方式(0代表DOS界面,1代表文件):";
        cin >> intPrintStyle;
        cout << "请选择运算可否出现括号(0代表不能,1代表能):";
        cin >> intParentheses;
        cout << "请选择运算可否出现乘除(0代表没有,1代表有):";
        cin >> intMultiplyDivide;
        cout << "请选择运算可否出现负数(0代表不能,1代表能):";
        cin >> intMinus;
        cout << "请选择运算可否出现余数(0代表不能,1代表能):";
        cin >> intRemainder;
        cout << "请输入运算数的范围(最小 空格 最大):";
        cin >> min;
        cin >> intMax;
        cout << "请输入运算式的个数:";
        cin >> intCount;
    
        double dobResult;    //记录结果值
        int intNumA[100];
        int intNumB[100];      //两个数组,存储运算数
        createArray(intNumA, intNumB, intCount, min, intMax);   //生成两个数组
    
        string stringOperator[10];
        for (int i = 0; i < 10; i++)
        {
            stringOperator[i] = 'a';
        }
        int intNumC[4];     //运算数的数组,存储4个数
    
        //srand((int)time(NULL));
        for (int outI = 0; outI < intCount; outI++)
        {
            if (intNumA[outI] < intNumB[outI])   //生成多位整数进行运算
            {
                for (int i = 0; i < 4; i++)    //生成数组,存储4个整数
                {
                    intNumC[i] = min + rand() % (intMax - min + 1);
                }
    
                YSShuZu(stringOperator, intMultiplyDivide, intParentheses, intYunSFLen);   //生成运算符
    
                if (1==intMultiplyDivide)
                {
                    if (0 == intRemainder)
                    {
                        RemainderFouction(intNumC, stringOperator, intYunSFLen);      //不能出现余数
                        int intInR;
                        if (intPrintStyle == 0)
                        {
                            cout << "请输入结果:" << endl;
                        }
                        else
                        {
                            cout << "请打开文件“BiaoDaShi.txt”并在屏幕上输入结果:" << endl;
                        }
                        MDOutput(intNumC, stringOperator, intYunSFLen,intPrintStyle);
                        dobResult = OperatorMD(intNumC, stringOperator, intYunSFLen);
                        cout << "=";
                        cin >> intInR;
    
                        if (intInR == dobResult)
                        {
                            cout << " " << "(√)" << endl;
                        }
                        else
                        {
                            cout << "(×)" << endl;
                        }
                    }
    
                    if (1 == intRemainder)
                    {
                        int intInR;
                        cout << "请输入结果:" << endl;
                        MDOutput(intNumC, stringOperator, intYunSFLen,intPrintStyle);
                        dobResult = OperatorMD(intNumC, stringOperator, intYunSFLen);
                        cout << "=";
                        cin >> intInR;
                        if (intInR == dobResult)
                        {
                            cout << " " << "" << endl;
                        }
                        else
                        {
                            cout << "计算结果错误!" << endl;
                        }
                    }
                    
                }
                if (0==intMultiplyDivide)
                {
                    minus_JiaJian(intNumA,stringOperator,min,intMax,intMinus,intParentheses,intPrintStyle);
                }            
            }
            else    //使用数组intNumA[100],intNumB[100]中的数进行真分数进行运算
            {
                calculate_ProperFraction(intNumA, intNumB, outI, min, intMax, intPrintStyle);
            }
        }
    
        cout << endl;
        cout << "运算符数组为:";
        for (int i = 0; i < 10; i++)
        {
            cout << stringOperator[i] << " ";
        }
        cout << endl;
        cout << "运算数数组为:";
        for (int i = 0; i < 4; i++)
        {
            cout << intNumC[i] << " ";
        }
        cout << endl;
    
        return 0;
    }

    实验截图:

    实验总结:

          通过本次试验,首先我认为当编写较大的程序是,使用函数是很好的一种方法,他能使得代码的重用性大大降低,使得程序更加简明,结构更加宏观清晰,同时也更加方便阅读和维护。其次,我深刻体会到边编写代码变测试程序的重要性与优点,这样能够快速的发现程序的不足之处,同时在最后完成程序后进行调试会很方便,出的错误会比较少,更加便于维护。上次实验我是将所有功能写入全都写入主函数中,并且是在最后进行的测试,这样真的很麻烦,有时候找到错误之后是牵一发而动全身。另外在写程序和调程序的过程中要做记录,这样会更好的记住自己犯下的错误,并且能够在一定的程度上在之后编程中进行避免。

          本次试验最大的收获就是实打实的体验了一把结对开发,这真的挺有意思,开拓了个人的思路,更快更明晰了编程思路,减少了编程过程中的错误,果然是人多力量大。

          以下附上实验记录表:

    1、项目计划总结表

                                                                    周活动总结表                               时间:2016年3月19日

    日期任务 听课/时 编写程序/时 阅读课本/时 日总结/时
    周一 3.14 2 1   3
    周二 3.15        
    周三 3.16   2 1 3
    周四 3.17 2 3   5
    周五 3.18   7   7
    周六 3.19   12   12
    周日 3.10        
    周总计 4 25 1 30

    2、时间记录表

    日期 开始时间 结束时间 中断时间 净时间 活动 备注
    3.14 14:00 16:00   2 听课,编写程序,结对讨论  
      21:00 22:00   1 写程序  
    3.15            
    3.16 15:00 18:00   3 写程序,看课本  
    3.17 14:00 16:00   2 上课,看课本  
      19:30 22:30   3 写程序  
    3.18 8:00 10:00   2 写程序  
      13:00 17:00   4 写程序  
      20:00 21:00   1 写程序  
    3.19 7:00 9:00   2 写程序  
      12:00 22:00   10 写程序  
    3.20            

    3、缺陷记录日志

    日期 编号 类型 引入阶段 排除阶段 修复时间 修复缺陷
    3.14 1   测试 单步调试 15min  
    描述:算法公式错误,以致某些情况下得不到正确的结果
    3.15            
               
    3.16 2   编码 编码 30min  
    描述:函数的调用与如何返回值发生混乱
    3.17 3   设计 设计 3hour  
    描述:程序设计思路混乱
    3.18            
               
    3.19 4   测试 单步调试 10min  
    描述:函数的逻辑结果不正确
    3.20            
               

    队友博客地址:宋海林(http://www.cnblogs.com/hulidanxiang/p/5295475.html

  • 相关阅读:
    倒序三角形
    有时间了
    测试一个数是不是素数
    初学C++编写小程序
    N!的递归调用
    1+...+5的递归调用
    1!+....+5!
    菱形块
    23.git简单使用
    27.flask学习
  • 原文地址:https://www.cnblogs.com/seven-seven/p/5294985.html
Copyright © 2011-2022 走看看