Software Engineering Section, the teacher through an example of what is the program, program and software differences, require us to write a short time a programming problem,
The topic is to write 30 pupils arithmetic questions. Here is the source code:
#include <iostream.h>
#include <stdlib.h>
#include <time.h>
void demo (void) // Randomly generated arithmetic
{
int m,n,k; //random number M,n, Count
m=rand ()%100;//generate random number
n= Rand ()%100;
k=rand ()%5;
switch (k) //Four operations random selection
{
case 1:cout<<m<< "+" <<n << "=" <<endl;break;
case 2:cout<<m<< "-" <<n<< "=" <<endl;break;
case 3:cout<<m<< "x" <<n<< "=" <<endl;break;
case 4:cout<<m<< "÷" <<n<< "=" <<endl;break;
}
}
int main () //main function for cycle times
{
int i=1; //Cycles
srand (( unsigned) time (NULL));//generate different random seeds for the rand () function
cout<< "30 100 Subtraction Arithmetic:" <<ENDL;
while (i<=38)
{
demo (); //Call function
i++;
}
return 0;
}
Code results:
Thought: The demo function is used to generate the immediate operation, and the main function is used to control the number of meta-calculations.
30 Elementary school students arithmetic problem-C + + programming