Design ideas:
1. Generate 4 random numbers with random number generation function
2. Intermediate random number processing, in addition to 4, 0,1,2,3 respectively represents subtraction. The last random number is 2, 0 is the integer, and 1 is the false fraction.
3. When generating division, the divisor is not 0.
4. Random topic generation, Cycle 30 topics
5. Output
SOURCE program code:
#include <iostream>using namespacestd; #include<time.h>structyunsuan{intFuhao; intOne ; intboth ; int Select;};intMain () {Yunsuan num[ -]; Srand ((int) Time (NULL)); inti; for(i=0;i< -; i++) {Num[i].one= rand ()% -; Num[i].two= rand ()% -; Num[i].fuhao= rand ()%4; Num[i].Select= rand ()%2; if(num[i].fuhao==3) { if(Num[i].two = =0&&num[i].one <num[i].two) {i=i-1; } } } for(i=0;i< -; i++) { if(Num[i].Select==0) { if(num[i].fuhao==0) {cout<< Num[i].one <<" + "<< Num[i].two <<" = "<<Endl; } if(num[i].fuhao==1) {cout<< Num[i].one <<" - "<< Num[i].two <<" = "<<Endl; } if(num[i].fuhao==2) {cout<< Num[i].one <<" * "<< num[i].two<<" = "<<Endl; } if(num[i].fuhao==3) {cout<< Num[i].one <<" / "<< num[i].two<<" = "<<Endl; } } Else { intNUM1 = rand ()% -+1; intnum2 = num[i].one+1; intnum3 = rand ()% -+1; intNUM4 = num[i].two+1; if(num[i].fuhao==0) {cout<< NUM1 <<"/"<< num2 <<" + "<< num3 <<"/"<< num4 <<" = "<<Endl; } if(num[i].fuhao==1) {cout<< NUM1 <<"/"<< num2 <<" + "<< num3 <<"/"<< num4 <<" = "<<Endl; } if(num[i].fuhao==2) {cout<<"("<< NUM1 <<"/"<< num2 <<") * ("<<NUM3 <<"/"<< num4 <<") = "<<Endl; } if(num[i].fuhao==3) {cout<<"("<< NUM1 <<"/"<< num2 <<") /("<<NUM3 <<"/"<< num4 <<") = "<<Endl; } } }}
Operation Result:
Reasons why the class was not completed on time:
Software Engineering Personal Assignment 01