Two pillars arithmetic custom version + upgraded version

Source: Internet
Author: User

Title: On the basis of the last program, to realize the judgment of the connection, and to achieve a number of mixed operations, the requirements can be input results, and judgment.

Idea: Based on the last program, first think about the mixed operation, here the use of two arrays, respectively, recording the randomly generated operation number and operation symbol. Then, to judge the connection, check whether there is continuous division sign in the array of operation symbols, and some words with parentheses to avoid ambiguity. Finally, the results of the calculation, and the user input of the results of the comparison, give the corresponding hints, answers, calculations, priority to the parentheses, multiplication, and then add and subtract operations, after each operation to record the results of the operation.

Code:

Lu Guanghao 3/19

#include <iostream>
#include <time.h>
using namespace Std;
#define N 100
int main ()
{
int n = 10;
Srand ((unsigned) time (NULL));
int num, Max, out, D, Fushu, KH, yushu;//have true score judgment, number of questions, maximum value, output mode, whether there are multiplication operations, plus and minus whether there are negative numbers, there are no brackets, there is no number
cout << "******** Two pillars arithmetic custom version + upgrade ********" << Endl;
cout << "Please enter the number of questions num:" << Endl;
CIN >> Num;
cout << "Please select the maximum value range (greater than 0)" << Endl;
CIN >> Max;
cout << "Please select the printing method out (0 blank line printing, 1 space printing)" << Endl;
Cin >> out;
cout << "Please choose multiplication operation D (0 no multiplication operation, 1 have multiplication operation)" << Endl;
Cin >> D;
cout << "Please select the addition and subtraction operations with or without negative Fushu (0 no negative, 1 negative)" << Endl;
Cin >> Fushu;
cout << "Please select there are no brackets (0 without parentheses, 1 with brackets)" << Endl;
CIN >> KH;
cout << "Division is surplus number (0 no remainder, 1 surplus)" << Endl;
Cin >> Yushu;
for (int m = 0; m < num; m++)
{
int a = 2 + rand ()% 4;
int A1[n] = {};//random number of stored operations
int y;//operation result
for (int i = 0; i < A; i++)
{
int b = 1 + rand ()% Max;
A1[i] = b;
}
if (Fushu = = 1)
{
int v = rand ()% 2;
if (v = = 1)
{
A1[0] =-a1[0];
}

}
Char B1[n] = {};//symbol for operation
Char b[4] = {' + ', '-', ' * ', '/'};
for (int i = 0; i < A-1; i++)//Judging continuous Division
{
if (d = = 0)
{
int d = rand ()% 2;
B1[i] = b[d];
}
Else
{
int d = rand ()% 4;
B1[i] = b[d];
if (d = = 3)
{
int c = rand ()% 10 + 1;
if (Yushu = = 0)
{
A1[i] = a1[i + 1] * C;
}

if (b1[i-1] = = '/')
{
A1[i] = a1[i + 1] * C;
int C1 = rand ()% 10 + 1;
A1[I-1] = a1[i] * a1[i + 1] * C1;
}
}
for (int i = 0; i < a-3; i++)
{
if (b1[i] = = b1[i + 1] = = B1[i + 2] = = '/')
{
B1[i] = ' + ';
}
if (b1[i] = = b1[i + 1] = = B1[i + 2] = = B1[i + 3] = = '/')
{
B1[i + 3] = '-';
}
}
}

}
if (kh = = 1)
{
for (int i = 0; i < A-1; i++)//output operation
{
if (b1[i] = = '/' &&b1[i + 1] = = '/')//continuous division is separated by parentheses
{
cout << ' (' << a1[i] << b1[i];

}
Else
if (b1[i] = = '/' &&b1[i-1] = = '/' &&i>0)
{
cout << A1[i] << ') ' << b1[i];
}

Else
{
int e = rand ()%10;
cout << ' (' << a1[i]<< ' + ' << e << ') ' << b1[i];
}

}
cout << a1[a-1] << ' = ' << ' ";
}
Else
{
for (int i = 0; i < A-1; i++)//output operation
{
if (b1[i] = = '/' &&b1[i + 1] = = '/')//continuous division is separated by parentheses
{
cout << ' (' << a1[i] << b1[i];

}
Else
if (b1[i] = = '/' &&b1[i-1] = = '/' &&i>0)
{
cout << A1[i] << ') ' << b1[i];
}

Else
cout << A1[i] << b1[i];
}
cout << a1[a-1] << ' = ' << ' ";
}
y = a1[0];
for (int i = 0; i < A-1; i++)
{
int y = 0;

if (b1[i] = = '/' &&b1[i + 1] = = '/')
{
y = a1[i]/a1[i + 1]/a1[i + 2];
A1[i] = y;
A1[i + 1] = 0;
A1[i + 2] = 0;
B1[i] = b1[i + 1] = ' + ';

}
Else
if (b1[i] = = '/' &&b1[i + 1] = = ' * ')
{
y = a1[i]/a1[i + 1] * a1[i + 2];
A1[i] = y;
A1[i + 1] = 0;
A1[i + 2] = 0;;
B1[i] = b1[i + 1] = ' + ';

}
Else
if (b1[i] = = ' * ' &&b1[i + 1] = = '/')
{
y = a1[i] * a1[i + 1]/a1[i + 2];
A1[i] = y;
A1[i + 1] = 0;
A1[i + 2] = 0;
B1[i] = b1[i + 1] = ' + ';

}
Else
if (b1[i] = = ' * ' &&b1[i + 1] = = ' * ')
{
y = a1[i] * a1[i + 1] * a1[i + 2];
A1[i] = y;
A1[i + 1] = 0;
A1[i + 2] = 0;
B1[i] = b1[i + 1] = ' + ';

}
Else
if (b1[i] = = '/')
{
y = a1[i]/a1[i + 1];
A1[i] = y;
A1[i + 1] = 0;
B1[i] = ' + ';

}
Else
if (b1[i] = = ' * ')
{
y = a1[i] * a1[i + 1];
A1[i] = y;
A1[i + 1] = 0;
B1[i] = ' + ';

}

}
int y1 = a1[0];
for (int i = 0; i < A-1; i++)//recursive calculation
{
if (b1[i] = = ' + ')
{
Y1 = y1 + a1[i + 1];

}
Else
if (b1[i] = = '-')
{
Y1 = y1-a1[i + 1];

}
Else
if (b1[i] = = ' * ')
{
y1 = y1 * a1[i + 1];

}
Else
if (b1[i] = = '/')
{
Y1 = y1/a1[i + 1];

}

}
int s;
cout << "Please enter your calculation results";
Cin >> S;
if (s = = y1)
{
cout << "The results are correct";
}
Else
{
cout << "Result error, correct answer is" << y1<< "";
}
if (out = = 0)
{
cout << Endl;
}
}

return 0;
}

Operation Result:

Deficiencies in the program:

There is no effort to achieve the calculation of true scores and the computation of results.

Programming Summary Analysis:

This is a pair of development procedures, two people to unite the development, through this experiment, I found that the advantages of the development of the pair is very large, two people ideas open quickly, and check the wrong is more timely, unity of power.

Two pillars arithmetic custom version + upgraded version

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.