// fourArithmeticOperation.cpp : 定义控制台应用程序的入口点。
//

include "stdafx.h"

include

using namespace std;
int TureQuestion = 0;
int main()
{
cout << "" << endl;
cout << "
/
除法先输入商,在输入余数
/ " << endl;
cout << "
/
真分数先输入分子,再输入分母
/ " << endl;
cout << "
/
假分数先输入整数,再输入分子,最后输分母
/
" << endl;
cout << "
" << endl;
cout << "
/
0是整数运算
/ " << endl;
cout << "
/
1是分数运算
/ " << endl;
cout << "
******************************" << endl << endl;
void IntType();
void TureScoreType();
int ReductionOfAFraction(int number_1, int number_2);
cout << "输入运算题目数量:";
int num;
cin >> num;
for (int i = 0; i < num; i++)
{
cout << "输入运算类型:";
int num;
cin >> num;
switch (num)
{
case 0:IntType(); break;
case 1:TureScoreType(); break;
default:cout << "输入错误";
}
}
double ture = TureQuestion * 100 / num;
cout << "本次一共答题" << num << "道,答对" << TureQuestion << "道,正确率" << ture << "%" << endl;
return 0;
}
void IntType()
{
int Operator = rand() % 4;
switch (Operator)
{
case 0: //加法
{
int number_1 = rand() % 100;
int number_2 = rand() % 100;
int result_ = number_1 + number_2;
int UserResult_;
cout << number_1 << "+" << number_2 << "=";
cin >> UserResult_;
if (result_ == UserResult_)
{
cout << "正确" << endl;
TureQuestion++;
}
else
cout << "错误,正确答案:" << result_ << endl;
}break;
case 1: //减法
{
int number_1 = rand() % 100;
int number_2 = rand() % 100;
int result_ = number_1 - number_2;
int UserResult_;
cout << number_1 << "-" << number_2 << "=";
cin >> UserResult_;
if (result_ == UserResult_)
{
cout << "正确" << endl;
TureQuestion++;
}
else
cout << "错误,正确答案:" << result_ << endl;
}break;
case 2://乘法
{
int number_1 = rand() % 10;
int number_2 = rand() % 10;
int result_ = number_1 * number_2;
int UserResult_;
cout << number_1 << "
" << number_2 << "=";
cin >> UserResult_;
if (result_ == UserResult_)
{
cout << "正确" << endl;
TureQuestion++;
}
else
cout << "错误,正确答案:" << result_ << endl;
}break;
case 3: //除法
{
int number_1 = rand() % 10 + 1;
int number_2 = rand() % 10 + 1;
if (number_2 > number_1)
{
int temp = number_1;
number_1 = number_2;
number_2 = temp;
}
int result_1 = number_1 / number_2;
int result_2 = number_1 % number_2;
int UserResult_1, UserResult_2;
cout << number_1 << "/" << number_2 << "=";
cin >> UserResult_1 >> UserResult_2;
if (result_1 == UserResult_1&&result_2 == UserResult_2)
{
cout << "正确" << endl;
TureQuestion++;
}
else
cout << "错误,正确答案:" << result_1 << "余" << result_2 << endl;
}break;
default:cout << "error";
}
}
int ReductionOfAFraction(int number_1, int number_2)
{
while (number_1 != number_2)
if (number_1 > number_2)
number_1 -= number_2;
else
number_2 -= number_1;
return number_1;
}
void TureScoreType()
{
int Operator = rand() % 4;
switch (Operator)
{
case 0://加法
{
int number_1 = rand() % 10 + 1;
int number_2 = rand() % 10 + 1;
int number_3 = rand() % 10 + 1;
int number_4 = rand() % 10 + 1;
if (number_1 > number_2)
{
int temp = number_2;
number_2 = number_1;
number_1 = temp;
}
if (number_3 > number_4)
{
int temp = number_3;
number_3 = number_4;
number_4 = temp;
}
cout << number_1 << "/" << number_2 << "+" << number_3 << "/" << number_4 << "=";
int UserResult_1, UserResult_2, result_1, result_2, molecule, Denominator;
molecule = number_1
number_4 + number_2
number_3;
Denominator = number_2
number_4;
int num = ReductionOfAFraction(molecule, Denominator);
result_1 = molecule / num;
result_2 = Denominator / num;
if (result_1 > result_2)
{
int result_0 = result_1 / result_2;
result_1 %= result_2;
int UserResult_0;
cin >> UserResult_0 >> UserResult_1 >> UserResult_2;
if (result_0 == UserResult_0&&result_1 == UserResult_1&&result_2 == UserResult_2)
{
cout << "正确" << endl;
TureQuestion++;
}
else
cout << "错误,正确答案是:" << result_0 << "'" << result_1 << "/" << result_2 << endl;
}
else
{
cin >> UserResult_1 >> UserResult_2;
if (result_1 == UserResult_1&&result_2 == UserResult_2)
{
cout << "正确" << endl;
TureQuestion++;
}
else
cout << "错误,正确答案是:" << result_1 << "/" << result_2 << endl;
}
}break;
case 1://减法
{
int number_1 = rand() % 10 + 1;
int number_2 = rand() % 10 + 1;
int number_3 = rand() % 10 + 1;
int number_4 = rand() % 10 + 1;
if (number_1 > number_2)
{
int temp = number_2;
number_2 = number_1;
number_1 = temp;
}
if (number_3 > number_4)
{
int temp = number_3;
number_3 = number_4;
number_4 = temp;
}
cout << number_1 << "/" << number_2 << "-" << number_3 << "/" << number_4 << "=";
int UserResult_1, UserResult_2, result_1, result_2, molecule, Denominator;
molecule = number_1
number_4 - number_2
number_3;
Denominator = number_2
number_4;
int num = ReductionOfAFraction(molecule, Denominator);
result_1 = molecule / num;
result_2 = Denominator / num;
if (result_1 > result_2)
{
int result_0 = result_1 / result_2;
result_1 %= result_2;
int UserResult_0;
cin >> UserResult_0 >> UserResult_1 >> UserResult_2;
if (result_0 == UserResult_0&&result_1 == UserResult_1&&result_2 == UserResult_2)
{
cout << "正确" << endl;
TureQuestion++;
}
else
cout << "错误,正确答案是:" << result_0 << "'" << result_1 << "/" << result_2 << endl;
}
else
{
cin >> UserResult_1 >> UserResult_2;
if (result_1 == UserResult_1&&result_2 == UserResult_2)
{
cout << "正确" << endl;
TureQuestion++;
}
else
cout << "错误,正确答案是:" << result_1 << "/" << result_2 << endl;
}
}break;
case 2://乘法
{
int number_1 = rand() % 10 + 1;
int number_2 = rand() % 10 + 1;
int number_3 = rand() % 10 + 1;
int number_4 = rand() % 10 + 1;
if (number_1 > number_2)
{
int temp = number_2;
number_2 = number_1;
number_1 = temp;
}
if (number_3 > number_4)
{
int temp = number_3;
number_3 = number_4;
number_4 = temp;
}
cout << "(" << number_1 << "/" << number_2 << ")
(" << number_3 << "/" << number_4 << ")" << "=";
int UserResult_1, UserResult_2, result_1, result_2, molecule, Denominator;
molecule = number_1
number_3;
Denominator = number_2
number_4;
int num = ReductionOfAFraction(molecule, Denominator);
result_1 = molecule / num;
result_2 = Denominator / num;
if (result_1 > result_2)
{
int result_0 = result_1 / result_2;
result_1 %= result_2;
int UserResult_0;
cin >> UserResult_0 >> UserResult_1 >> UserResult_2;
if (result_0 == UserResult_0&&result_1 == UserResult_1&&result_2 == UserResult_2)
{
cout << "正确" << endl;
TureQuestion++;
}
else
cout << "错误,正确答案是:" << result_0 << "'" << result_1 << "/" << result_2 << endl;
}
else
{
cin >> UserResult_1 >> UserResult_2;
if (result_1 == UserResult_1&&result_2 == UserResult_2)
{
cout << "正确" << endl;
TureQuestion++;
}
else
cout << "错误,正确答案是:" << result_1 << "/" << result_2 << endl;
}
}break;
case 3://除法
{
int number_1 = rand() % 10 + 1;
int number_2 = rand() % 10 + 1;
int number_3 = rand() % 10 + 1;
int number_4 = rand() % 10 + 1;
if (number_1 > number_2)
{
int temp = number_2;
number_2 = number_1;
number_1 = temp;
}
if (number_3 > number_4)
{
int temp = number_3;
number_3 = number_4;
number_4 = temp;
}
cout << "(" << number_1 << "/" << number_2 << ")/(" << number_3 << "/" << number_4 << ")" << "=";
int UserResult_1, UserResult_2, result_1, result_2, molecule, Denominator;
molecule = number_1
number_4;
Denominator = number_2
number_3;
int num = ReductionOfAFraction(molecule, Denominator);
result_1 = molecule / num;
result_2 = Denominator / num;
if (result_1 > result_2)
{
int result_0 = result_1 / result_2;
result_1 %= result_2;
int UserResult_0;
cin >> UserResult_0 >> UserResult_1 >> UserResult_2;
if (result_0 == UserResult_0&&result_1 == UserResult_1&&result_2 == UserResult_2)
{
cout << "正确" << endl;
TureQuestion++;
}
else
cout << "错误,正确答案是:" << result_0 << "'" << result_1 << "/" << result_2 << endl;
}
else
{
cin >> UserResult_1 >> UserResult_2;
if (result_1 == UserResult_1&&result_2 == UserResult_2)
{
cout << "正确" << endl;
TureQuestion++;
}
else
cout << "错误,正确答案是:" << result_1 << "/" << result_2 << endl;
}
}break;
default:cout << "error";
}
}