Try to write a command-line "software" that automatically generates arithmetic topics for primary schools, respectively, to meet the following requirements:
A) automatic generation of primary arithmetic topics, in addition to integers, but also to support the arithmetic of true scores; using the RAND function in Computer C, Rand is the true random number generator, and Srand () sets the random number seed used by Rand ().
b) can accept the user input answer, use if statement to judge right and wrong. Finally, the total number of errors is given;
c) using a for loop to give a batch of 100 questions, and using the RAND function in Computer C, Rand is the real random number generator, and Srand () sets the random number seed for rand () to ensure that the problem cannot be duplicated.
Program Run Result:
Program code:
#include <iostream>
#include <stdlib.h>
#include <iomanip>
#include <cmath>
#include <time.h>
using namespace Std;
#define RANDOM () (rand ()%100)
void Main ()
{
int s1,s2,s3,s4;
Double s5,s6;
int a,b,c,d,e,f,g;
int right=0;
int wrong=0;
Srand ((int) time (NULL));
for (int i=0;i<100;i++)
{
S1=random ();
S2=random ();
int k= (int) rand ()%5;
Switch (k)
{
Case 0:
{
cout<<s1<< "+" <<s2<< "=";
cin>>s5;
if (S1+S2==S5)
{
cout<< "right!" <<endl;right++;
}
Else
{
cout<< "wrong!" <<endl;wrong++;
}
Break
}
Case 1:
{
cout<<s1<< "-" <<s2<< "=";
cin>>s5;
if (S1-S2==S5)
{
cout<< "right!" <<endl;right++;
}
Else
{
cout<< "wrong!" <<endl;wrong++;
}
Break
}
Case 2:
{
cout<<s1<< "*" <<s2<< "=";
cin>>s5;
if (S1*S2==S5)
{
cout<< "right!" <<endl;right++;
}
Else
{
cout<< "wrong!" <<endl;wrong++;
}
Break
}
Case 3:
{
while (s2==0)
S2=random ();
cout<<s1<< "/" <<s2<< "=";
if (s1%s2==0)
{cin>>s5;
if (S5==S1/S2)
{
cout<< "right!" <<endl;right++;
}
Else
{
cout<< "wrong!" <<endl;wrong++;
}
}
Else
{
cin>>s5;cout<< "/" <<endl;cin>>s6;
A=S1;
B=S2;
for (c=a;c>=1&&c<=a;c--)
{
d=a%c;
e=b%c;
if (d==0&&e==0)
{
F=A/C;
G=B/C;
}
}
if ((F==S5) && (G==S6))
{
cout<< "right!" <<endl;right++;
}
Else
{
cout<< "wrong!" <<endl;wrong++;
}
Break
}
}
Case 4:
{
while (s2==0| | S1>=S2)
{
S1=random ();
S2=random ();
}
S3=random ();
S4=random ();
while (s4==0| | S3>=S4)
{
S3=random ();
S4=random ();
}
int l= (int) rand ()%4;
Switch (L)
{
Case 0:
{
cout<< "(" <<s1<< "/" <<s2<< ")" << "+" << "(" <<s3<< "/" <<s4 << ")" << "=";
cin>>s5;cout<< "/" <<endl;cin>>s6;
A=S1*S4+S2*S3;
B=S2*S4;
if (a>b)
{
for (c=b;c>=1&&c<=b;c--)
{
d=a%c;
e=b%c;
if (d==0&&e==0)
{
F=A/C;
G=B/C;
}
}
}
Else
{
for (c=a;c>=1&&c<=a;c--)
{
d=a%c;
e=b%c;
if (d==0&&e==0)
{
F=A/C;
G=B/C;
}
}
}
if ((F==S5) && (G==S6))
{
cout<< "right!" <<endl;right++;
}
Else
{
cout<< "wrong!" <<endl;wrong++;
}
Break
}
Case 1:
{
cout<< "(" <<s1<< "/" <<s2<< ")" << "-" << "(" <<s3<< "/" <<s4 << ")" << "=";
cin>>s5;cout<< "/" <<endl;cin>>s6;
A=S1*S4-S2*S3;
B=S2*S4;
if (a>b)
{
for (c=b;c>=1&&c<=b;c--)
{
d=a%c;
e=b%c;
if (d==0&&e==0)
{
F=A/C;
G=B/C;
}
}
}
Else
{
for (c=a;c>=1&&c<=a;c--)
{
d=a%c;
e=b%c;
if (d==0&&e==0)
{
F=A/C;
G=B/C;
}
}
}
if ((F==S5) && (G==S6))
{
cout<< "right!" <<endl;right++;
}
Else
{
cout<< "wrong!" <<endl;wrong++;
}
Break
}
Case 2:
{
cout<< "(" <<s1<< "/" <<s2<< ")" << "*" << "(" <<s3<< "/" <<s4 << ")" << "=";
cin>>s5;cout<< "/" <<endl;cin>>s6;
A=S1*S3;
B=S2*S4;
if (a>b)
{
for (c=b;c>=1&&c<=b;c--)
{
d=a%c;
e=b%c;
if (d==0&&e==0)
{
F=A/C;
G=B/C;
}
}
}
Else
{
for (c=a;c>=1&&c<=a;c--)
{
d=a%c;
e=b%c;
if (d==0&&e==0)
{
F=A/C;
G=B/C;
}
}
}
if ((F==S5) && (G==S6))
{
cout<< "right!" <<endl;right++;
}
Else
{
cout<< "wrong!" <<endl;wrong++;
}
Break
}
Case 3:
{
cout<< "(" <<s1<< "/" <<s2<< ")" << "/" << "(" <<s3<< "/" <<s4 << ")" << "=";
cin>>s5;cout<< "/" <<endl;cin>>s6;
A=S1*S4;
B=S2*S3;
if (a>b)
{
for (c=b;c>=1&&c<=b;c--)
{
d=a%c;
e=b%c;
if (d==0&&e==0)
{
F=A/C;
G=B/C;
}
}
}
Else
{
for (c=a;c>=1&&c<=a;c--)
{
d=a%c;
e=b%c;
if (d==0&&e==0)
{
F=A/C;
G=B/C;
}
}
}
if ((F==S5) && (G==S6))
{
cout<< "right!" <<endl;right++;
}
Else
{
cout<< "wrong!" <<endl;wrong++;
}
Break
}
}
}
}
}
cout<< "The number of right answer:" <<right<< "," << "the number of wrong answer:" <<wrong <<endl;
System ("pause");
}
Super Invincible Elementary School arithmetic problem procedure