Super Invincible Elementary School arithmetic problem procedure

Source: Internet
Author: User

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&GT;=S2)
{
S1=random ();
S2=random ();
}
S3=random ();
S4=random ();
while (s4==0| | S3&GT;=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

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.