Problem: Design a procedure, give second grade pupil randomly produce arithmetic topic.
First, Design thinking questions:
1. Arithmetic requires two operands and an operator.
2. How do I generate random numbers?
3. How to achieve random generation of arithmetic?
4. Is the topic in line with pupils ' learning scope? (Subtraction and division)
Second, the program source code:
#include <iostream.h>
#include <stdlib.h>
#include "time.h"
int main ()
{
cout<< "--------arithmetic--------" <<endl;
cout<<endl;
Srand ((unsigned) time (NULL));//The random number seed is the current computer.
int i,a,b,j,n,t;
cout<< "Please enter the number of questions to generate N:" <<endl;//Select the number of topics.
cin>>n;
for (j=0;j<n;j++)
{
Generates a random number.
A=rand ()%100;
B=rand ()%100+1;//guarantees that the divisor is not 0.
I=rand ()%4;
t=j%2;
if (t<=0)
cout<<endl;
Switch (i)
{
Case 0:
cout<<a<< "+" <<b<< "=" << "";
Break
Case 1:
if (a>=b)
cout<<a<< "-" <<b<< "=" << "";
Else
cout<<b<< "-" <<a<< "=" << "";//guaranteed minuend greater than or equal to meiosis.
Break
Case 2:
cout<<a<< "*" <<b<< "=" << "";
Break
Case 3:
cout<<a<< "/" <<b<< "=" << "";
Break
}
}
cout<<endl;
return 0;
}
Third, the experiment:
Iv. reasons for not completing the class:
Do not know the random function header file, long time no program, thinking a little slow.
30 Arithmetic topics---classroom assignments-Software engineering C + +