This is the first code written in software engineering, the main idea is to use random numbers to produce integer true fractions and four of the numbers representing the operation symbols, the only complex point to determine whether the divisor is zero, integer operations using the method of re-generation of random numbers, the division of the real fractional operation is zero using the numerator denominator plus 1 method processing.
This procedure mainly uses the
RAND ()%100 generates random numbers
Srand ((int) time (NULL));
Write ideas in class time 30 minutes during the actual writing process through the online information to ask students to learn the above two code to write 1.5 hours.
#include <iostream>
#include <ctime>
#include <stdlib.h>
using namespace std;
int main ()
{
int num1, num2, sym;
Srand ((int) time (NULL));
for (int i = 1; i < i++)
{
Num1 = rand ()%;
num2 = rand ()% 100;
int k = rand ()% 2;
Sym = rand ()% 4;
if (k = = 1)//-------------------integer operation
{
if (sym = = 0)
{
cout << num1 << "+" << num2 << "=" << Endl;
}
if (sym = = 1)
{
cout << num1 << "-" << num2 << "=" << Endl;
}
if (sym = = 2)
{
cout << num1 << "*" << num2 << "=" << Endl;
}
if (sym = = 3)
{
if (num2 = = 0)
{
num2 = rand ()% + 1;
cout << num1 << "/" << num2 << "=" << Endl;
}
Else
cout << num1 << "/" << num2 << "=" << Endl;
}
}
if (k = = 0)//-------------------True fractional operation
{
int A, B, C, D;
A = rand ()% 100;
B = rand ()% 100;
C = rand ()% 100;
D = rand ()% 100;
for (;;)
{
if (> B&&b!=0 && (c>d&&d!=0))
{
Num1 = b/a;
num2 = d/c;
break;
}
Else
A = rand ()%;
b = rand ()% 100;
C = rand ()% 100;
D = rand ()%;
}
if (sym = = 0)
{
cout <<b<< "/" <<a<< "+" << d<< "/" <<c << "=" << Endl;
}
if (sym = = 1)
{
cout << B << "/" << a << "-" << D << "/" << c << "=" << Endl;
}
if (sym = = 2)
{
cout << B << "/" << a << "*" << D << "/" << c << "=" << Endl;
}
if (sym = = 3)
{
if (d = = 0)
{
num2 = (d+1)/(c+1);
cout << B << "/" << a << "/" << D << "/" << c << "=" << Endl;
}
Else
cout << B << "/" << a << "/" << D << "/" << c << "=" << Endl;
}
}
}
return 0;
}
Randomly generates 30 to integer true fraction arithmetic