The procedure of randomly producing 30 pupils arithmetic. It is encoded here in C + +.
Design ideas: Comprehensive student examples and Baidu. The function that generates the random number first is rand (), with a for loop of 30 times to 30 questions. The arithmetic is randomly defined by case. Only ask for a question, so direct output random number and random operation symbol. Because primary arithmetic do not involve negative numbers, the comparison size ensures that the subtraction does not produce negative numbers.
//randomly generate 30 primary arithmetic#include<iostream>#include <cmath>
using namespacestd;voidMain () {intA,b,i,r,y; for(i=0;i< -; i++) {a=rand ()% -; b=rand ()% -; Y=rand ()%4; Switch(y) { Case 0: cout<<" "<<a<<"+"<<b<<"="<<Endl; Break; Case 1: if(a<b) {R=A; A=b; b=R; }//Avoid negative numberscout<<" "<<a<<"-"<<b<<"="<<Endl; Break; Case 2: cout<<" "<<a<<"*"<<b<<"="<<Endl; Break; Case 3: cout<<" "<<a<<"/"<<b<<"="<<Endl; Break; } }}
Test results:
Post-Program sense: Did not write this procedure in the specified time, first of all because of poor design thinking, not a good idea and reflective ability to start the topic. I belong to the teacher said the poor programming ability, the main reason is that the programming thinking is not agile. The mind does not build a good programming thinking system, the brain is not enough, the hands are not enough. The next is the usual programming relies on Baidu, always first through the construction of Baidu General thinking and then change. When faced with a blank, in addition to the basic structure of the program can be thought of, there is no better idea. For their own recognition of deficiencies and shortcomings, will be squeezed through spare time.
Introduction to Software engineering first week comprehensive test