1. Title: Randomly generate 30 to arithmetic questions, which cannot exceed 2-bit operations, including true fractions.
2. Design Ideas
(1) The first four numbers are randomly generated, the first two numbers are used as the arithmetic of integers, and then the first two numbers are then used as the second score, and the next two numbers as the number two.
(2) Each case is represented by the Switch\case function, and the remainder by dividing by 7 represents a different case in 8, the first four represents an integer subtraction operation, and the last four subtraction operations that represent fractions.
(3) Generate 30 expressions with a for loop.
3. Program code:
2016/3/3 Wang Zongze #include<iostream> #include <cstdlib> #include <ctime>using namespace Std;int main () { Srand ((unsigned) time (NULL)), int i;for (i=0;i<30;i++) {int Firstnum=rand ()%100;int Secondnum=rand ()%100;int Thirdnum=rand ()%100;int Forthnum=rand ()%100;switch (int (firstnum%7)) {case 0:cout<<firstnum<< "+" < <secondnum<< "=" <<endl; Break;case 1:cout<<firstnum<< "-" <<secondnum<< "=" <<endl; Break;case 2:cout<<firstnum<< "*" <<secondnum<< "=" <<endl; Break;case 3:cout<<firstnum<< "/" <<secondnum<< "=" <<endl; Break;case 4:if ((firstnum>secondnum) | | (Thirdnum>forthnum)) {i=i-1;} else cout<< "(" <<firstnum<< "/" <<secondnum<< ")" << "+" << "(" << thirdnum<< "/" <<forthnum<< ")" << "=" <<endl; Break;case 5:if ((firstnum>secondnum) | | (Thirdnum>forthnum)) {i=i-1;} else cout<< "(" <<firstnum<< "/"<<secondnum<<") "<<"-"<<" ("<<thirdnum<<"/"<<forthnum<<") "< < "=" <<endl; Break;case 6:if ((firstnum>secondnum) | | (Thirdnum>forthnum)) {i=i-1;} else cout<< "(" <<firstnum<< "/" <<secondnum<< ")" << "*" << "(" << thirdnum<< "/" <<forthnum<< ")" << "=" <<endl; Break;case 7:if ((firstnum>secondnum) | | (Thirdnum>forthnum)) {i=i-1; }else cout<< "(" <<firstnum<< "/" <<secondnum<< ")" << "/" << "(" << thirdnum<< "/" <<forthnum<< ")" << "=" <<endl; Break }}}
4. Program Operation Result:
Randomly generate 30 arithmetic topics