#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <string>
#include <iostream>
using namespace std;
int main()
{
int x1_Value;
int x2_Value;
int Constant1_Value;
int Constant2_Value;
string Operation;
string Operation1;
string Operation2;
string Operation3;
string AnswerConstant1;
string AnswerConstant2;
string Answer;
srand( (unsigned)time(NULL));
for(int i=0; i<10 ; ++i){
x1_Value = rand() % 200 + 1 - 100;
x2_Value = rand() % 200 + 1 - 100;
Constant1_Value = rand() % 200 + 1 - 100;
Constant2_Value = rand() % 200 + 1 - 100;
Operation1 = to_string(x1_Value * x2_Value);
if((x1_Value * Constant2_Value)+(x2_Value * Constant1_Value)>0)
{
Operation2 = "+"+to_string((x1_Value * Constant2_Value)+(x2_Value * Constant1_Value));
}
else
{
Operation2 = to_string((x1_Value * Constant2_Value)+(x2_Value * Constant1_Value));
}
if(Constant1_Value * Constant2_Value>0)
{
Operation3 = "+"+to_string(Constant1_Value * Constant2_Value);
}
else
{
Operation3 = to_string(Constant1_Value * Constant2_Value);
}
Operation = Operation1+"x^2"+Operation2+"x"+Operation3;
if(Constant1_Value>0)
{
AnswerConstant1 = "+"+to_string(Constant1_Value);
}
else
{
AnswerConstant1 = to_string(Constant1_Value);
}
if(Constant2_Value>0)
{
AnswerConstant2 = "+"+to_string(Constant2_Value);
}
else
{
AnswerConstant2 = to_string(Constant2_Value);
}
Answer = "("+to_string(x1_Value)+"x"+AnswerConstant1+")"+"("+to_string(x2_Value)+"x"+AnswerConstant2+")";
std::cout << "Operation: " << Operation+"\n";
std::cout << "Answer: " << Answer+"\n";
}
}
我閒閒沒事用C++寫的但我覺得係數用到-+100學生就會算到哭出來了吧
所以就沒設定到1000了
執行完效果跑10次迴圈
Operation: -770x^2-2035x+2310
Answer: (77x-66)(-10x-35)
Operation: -370x^2+7251x-5546
Answer: (5x-94)(-74x+59)
Operation: -3672x^2-8601x-5005
Answer: (72x+91)(-51x-55)
Operation: 2700x^2+94x-3904
Answer: (-50x-61)(-54x+64)
Operation: -426x^2+4025x-4459
Answer: (6x-49)(-71x+91)
Operation: 1012x^2-4652x+3280
Answer: (11x-41)(92x-80)
Operation: 1386x^2-6035x+5500
Answer: (-77x+100)(-18x+55)
Operation: 810x^2-1449x-153
Answer: (27x-51)(30x+3)
Operation: 5265x^2+725x-500
Answer: (-81x+20)(-65x-25)
Operation: -1000x^2+4910x-5934
Answer: (-40x+86)(25x-69)
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <string>
#include <iostream>
using namespace std;
int
main ()
{
int x1_Value;
int x2_Value;
int Constant1_Value;
int Constant2_Value;
string Operation;
string Operation1;
string Operation2;
string Operation3;
string AnswerConstant1;
string AnswerConstant2;
string Answer;
int QuestionType;
srand ((unsigned) time (NULL));
for (int i = 0; i < 100; ++i)
{
x1_Value = rand () % 200 + 1 - 100;
x2_Value = rand () % 200 + 1 - 100;
Constant1_Value = rand () % 200 + 1 - 100;
Constant2_Value = rand () % 200 + 1 - 100;
QuestionType = rand () % 2;
if (QuestionType == 1)
{
x2_Value = x1_Value;
Constant2_Value = Constant1_Value;
}
if (x1_Value * x2_Value != 0)
{
Operation1 = to_string (x1_Value * x2_Value) + "x^2";
}
else
{
Operation1 = "";
}
if ((x1_Value * Constant2_Value) + (x2_Value * Constant1_Value) > 0)
{
Operation2 =
"+" + to_string ((x1_Value * Constant2_Value) +
(x2_Value * Constant1_Value)) + "x";
}
else if ((x1_Value * Constant2_Value) + (x2_Value * Constant1_Value) <
0)
{
Operation2 =
to_string ((x1_Value * Constant2_Value) +
(x2_Value * Constant1_Value)) + "x";
}
else
{
Operation2 = "";
}
if (Constant1_Value * Constant2_Value > 0)
{
Operation3 = "+" + to_string (Constant1_Value * Constant2_Value);
}
else if (Constant1_Value * Constant2_Value < 0)
{
Operation3 = to_string (Constant1_Value * Constant2_Value);
}
else
{
Operation3 = "";
}
Operation = Operation1 + Operation2 + Operation3;
if (Constant1_Value > 0)
{
AnswerConstant1 = "+" + to_string (Constant1_Value);
}
else
{
AnswerConstant1 = to_string (Constant1_Value);
}
if (Constant2_Value > 0)
{
AnswerConstant2 = "+" + to_string (Constant2_Value);
}
else
{
AnswerConstant2 = to_string (Constant2_Value);
}
Answer =
"(" + to_string (x1_Value) + "x" + AnswerConstant1 + ")" + "(" +
to_string (x2_Value) + "x" + AnswerConstant2 + ")";
std::cout << "Operation: " << Operation + "\n";
std::cout << "Answer: " << Answer + "\n";
}
}
又再加了個亂數
依亂數判斷是(ax+b)(cx+d)或(ax+b)^2