I. Design ideas:
1 topics Avoid duplication: Create two arrays, the rand () function determines the random number, adds the two numbers to two arrays, repeats the random number, determines whether the two numbers are the same as the values of two arrays to avoid duplication, and outputs the problem without repetition.
2 Customizable (Qty/print): quantity and printing use the macro definition to determine how many rows and columns are output.
3 Is there a multiplication method: Define an array of arithmetic characters, the first two represent the plus minus, the latter two represent multiplication, and the random number range to determine whether there is multiplication.
4 Value range: the rand () function determines the range of values.
5 if Else statement to determine whether the plus minus has negative numbers and the division has no number.
Two. Code implementation:
#include <iostream>
#include <cmath>
using namespace Std;
void Main ()
{
int m,n,min,max,g,s,l; M is the number of topics, n is the printing method, the lower bounds of the value range, and Max is the upper bounds of the value range
int a1,a2,a3,i,j,t,a[10000],b[10000];
cout<< "Please enter the number of questions and how to print:" <<endl; How many questions are printed in a group
cin>>m>>n;
cout<< "Please enter a range of values:" <<endl;
cin>>min>>max;
if (Min>max)
{
G=min;
Min=max;
max=g;
}
s=max-min+1;
cout<< "There is no multiplication method?" (1/0) "<<endl;
cin>>a1;
cout<< "plus minus is there a negative number?" (1/0) "<<endl;
cin>>a2;
if (a1==1)
{
cout<< "Multiplication have no number? (1/0) "<<endl;
cin>>a3;
}
cout<<endl;
for (i=1;i<=m;i++)
{
A[i]=min+rand ()%s;
B[i]=min+rand ()%s;
for (j=0;j<i;j++)//judgment repetition
{
while (A[j]==a[i]&&b[j]==b[i])
{
A[i]=min+rand ()%s;
B[i]=min+rand ()%s;
}
}
}
for (i=1;i<=m;i++)
{
if (a1==0)
{
T=rand ()%2;
if (a2==0)
{
if (t==0) cout<<a[i]<< "+" <<b[i];
if (t==1)
{
if (A[i]>b[i]) cout<<a[i]<< "-" <<b[i];
else cout<<b[i]<< "-" <<a[i];
}
}
if (a2==1)
{
L=rand ()%3;
if (l==0) a[i]=a[i]*-1;
if (l==1) b[i]=b[i]*-1;
if (l==2) a[i]=a[i]*-1,b[i]=b[i]*-1;
if (t==0) cout<<a[i]<< "+" <<b[i];
if (t==1) cout<<a[i]<< "-" <<b[i];
}
}
if (a1=1)
{
T=rand ()%4;
if (a2==0)
{
if (t==0) cout<<a[i]<< "+" <<b[i];
if (t==1)
{
if (A[i]>b[i]) cout<<a[i]<< "-" <<b[i];
else cout<<b[i]<< "-" <<a[i];
}
if (t==2) cout<<a[i]<< "*" <<b[i];
if (t==3)
{
while (b[i]==0) {B[i]=min+rand ()%s;}
if (a3==1)
{
while (a[i]%b[i]==0) {B[i]=min+rand ()%s,a[i]=min+rand ()%s;}
cout<<a[i]<< "/" <<b[i];
}
if (a3==0)
{
while (a[i]%b[i]!=0) {B[i]=min+rand ()%s,a[i]=min+rand ()%s;}
cout<<a[i]<< "/" <<b[i];
}
}
}
if (a2==1)
{
L=rand ()%4;
if (l==0) a[i]=a[i]*-1;
if (l==1) b[i]=b[i]*-1;
if (l==2) a[i]=a[i]*-1,b[i]=b[i]*-1;
if (t==0) cout<<a[i]<< "+" <<b[i];
if (t==1) cout<<a[i]<< "-" <<b[i];
if (t==2) cout<<a[i]<< "*" <<b[i];
if (t==3)
{
while (b[i]==0) {B[i]=min+rand ()%s;}
if (a3==1)
{
while (a[i]%b[i]==0) {B[i]=min+rand ()%s,a[i]=min+rand ()%s;}
cout<<a[i]<< "/" <<b[i];
}
if (a3==0)
{
while (a[i]%b[i]!=0) {B[i]=min+rand ()%s,a[i]=min+rand ()%s;}
cout<<a[i]<< "/" <<b[i];
}
}
}
}
cout<< "=" <<endl;
if (i%n==0) cout<<endl;
}
}
Three.:
Four. Summary:
This problem has two difficulties, that is, to avoid duplication and conditional judgment whether there is multiplication, plus or minus negative numbers, division has the total number of zero. Avoid the repetition of the number, you can immediately take two random numbers into two arrays, each time the random number can be compared with the number of the array, if the repetition of the random number, until the repetition condition, the jump out of the loop. Set the variable to indicate whether there is no multiplication method, there is no negative and there is no multiplication method, respectively, using if statement nested to determine if the conditions are met. In general, two random numbers are taken first, and then the output problem is determined based on the values of each variable.
Five. Time History log
Date |
Start time |
End time |
Interrupt Time |
NET time |
Activities |
Note |
3/14 |
8:00 |
9:40 |
10 |
100 |
Design |
Thinking about design ideas |
|
15:20 |
16:10 |
|
50 |
Programming |
The implementation of the topic is not repeated |
3/15 |
9:10 |
9:35 |
|
25 |
Thinking discussion |
How to nest conditional judgments |
|
9:30 |
10:25 |
5 |
55 |
Programming |
Realization of condition judgment |
3/16 |
17:10 |
18:23 |
|
73 |
Programming |
Implementing Output Printing methods |
3/18 |
10:20 |
11:20 |
10 |
60 |
Write an experiment report |
Summary and Reflection |
|
|
|
|
|
|
|
Solve two pillar problems