One: Design ideas:
1. Randomly generates 2 random numbers from 0 to 99, used as operands, and randomly generates 1 to 0 numbers representing operator +,-,*,/.
2.if....else .... Statement controls the output of the calculation, for loop output 30 questions.
3. When the operator is "/", you need to determine whether the divisor is 0, and if 0, the number of loops plus one.
4. To ensure that the random seed is different, the Srand (Time (NULL)) function is required.
5. Loop through the questions that have already been made to see if there are any re-titles.
Two: Source program:
#include <iostream>using namespacestd; #include<string>#include<time.h>voidMain () {Srand (Time (NULL)); stringMark; intKey_one; intDividend,divider; stringresult[ -]; for(intI=0;i< -; i++) {Key_one=rand ()%4; Dividend=rand ()% -; Divider=rand ()% -; if(key_one==0) {cout<< Dividend <<"+"<< Divider <<"= ?"<<Endl; Result[i]=dividend +divider; } Else if(key_one==1) {cout<< Dividend <<"-"<< Divider <<"= ?"<<Endl; Result[i]=dividend-divider; } Else if(key_one==2) {cout<< Dividend <<"*"<< Divider <<"= ?"<<Endl; Result[i]=dividend *divider; } Else if(key_one==3) { if(divider==0) {i++; Break; } cout<< Dividend <<"/"<< Divider <<"= ?"<<Endl; Result[i]="Dividend/divider"; } Elsecout<<"Please try again!"<<Endl; }}
III: Results:
Four: The reason why the class did not finish the homework on time:
Do not seriously think about the problem, the blind knock Code, the idea is not clear, just want to write a step, once the error can only find changes from scratch, wasting a lot of time.
Introduction to Software engineering Personal Assignment 01