A. Design Miss
The first thought is to use random number function to get multiple sets of random numbers. In order to avoid the repetition of the problem think of a two-dimensional array to save the random number to ensure that each row corresponding to the column value is different. The range of random numbers is changed by controlling the random number function rand ()%m One of the m . By adding another random number to determine the positive or negative value of a number, a conditional statement is adopted to determine whether the result has a remainder. To determine the operator also requires the random number function rand ()%4 to get (0,1,2,3) separately to control (+,-, *,/). finally through a Switch statement to control the output.
Two. Summary
In the random number of this algorithm does not find the simplest algorithm, through the discussion between students to get a more simple control of the range of random numbers of the algorithm. Another problem is that the interface is not implemented, and the problem continues to improve over the next time ( because C + + does not interface ). In addition, the use of some statements is still not very skilled still need to practice.
Three. Event Log table
Student: DUYONGSU Course : Introduction to Software engineering Mission: arithmetic
Date |
Start time |
End time |
Interrupt Time |
NET time |
Activities |
Note |
2015-3-13 |
Ten:xx |
12:00 |
Ten minutes |
min |
Class |
Introduction to Software Engineering |
2015-3-14 |
14:00 |
16:30 |
minutes |
minutes |
Programming |
Complete the topic to avoid duplication of requirements |
2015-3-15 |
9:00 |
10:00 |
|
minutes |
Online Enquiry |
How queries use random numbers to determine ranges |
2015-3-15 |
10:30 |
11;30 |
|
minutes |
Programming |
Complete the determination of the random number range requirement |
2015-3-16 |
16:00 |
17:00 |
|
minutes |
Programming |
Complete the positive and negative requirements of random numbers and whether operators have multiplication method |
2015-3-18 |
14:00 |
17:00 |
minutes |
minutes |
Programming |
The completion of the division is required and the completion of the main function of the overall loop completion program can be recycled to slightly compensate for the problem of no interface. |
Four. Code
#include <iostream> #include <ctime> #include <cmath> #define N 100using namespace std;//generates a random number void set ( int M,int M,int A[n][3],int i) {int x,y,t; Randomly generated t set value is positive or negative, X, Y is the absolute value of the range of int a,b,c; c is used for operator (1,2,3,4) (+,-, *,/), and A, B is two random number//for random generation operator C=rand ()%4; X=abs (m); Y=abs (m); if (m>=0) {//generates a random number A=rand ()% (y+1); B=rand ()% (y+1);//Judging whether it meets the requirements while (a<m| | B<m) {A=rand ()% (y+1); B=rand ()% (y+1);}} else if (m<=0) {A=-rand ()% (x+1); B=-rand ()% (x+1); while (a>m| | B>m) {A=-rand ()% (x+1); B=-rand ()% (x+1);}} Else{t=rand ()%2;if (t==0) {A=rand ()% (x+1), while (a>m) A=rand ()% (x+1);} Elsea=-rand ()% (x+1); T=rand ()%2;if (t==0) B=rand ()% (y+1); Else{b=-rand ()% (y+1); while (b<m) B=-rand ()% (y+1);} The number of random numbers that meet the requirement is deposited into array a[i][0]=a; A[i][1]=c; A[i][2]=b;} Loop produces random number void Setnumber (int m,int m,int n,int a[][3]) {//define variable int i; Used for cyclic judgment//Loop generation N set for (i=0;i<n;i++) {set (M,m,a,i), while (A[i+1][0]==a[i][0]&&a[i+1][2]==a[i][2]) {Set (M,m,a,i); //Take advantage of function nesting}}}//outputs void output (int n,int a[][3]) {int i; I for Loop for (i=0;i<n;i++) {if (a[i][2]>0) {switch (a[i][1]) {case 0:{cout<<a[i][0]<< "+" <<a[i][ 2]<< "=" <<ENDL;} Break Case 1:{cout<<a[i][0]<< "-" <<A[i][2]<< "=" <<ENDL;} Break Case 2:{cout<<a[i][0]<< "*" <<A[i][2]<< "=" <<ENDL;} Break Case 3:{cout<<a[i][0]<< "/" <<A[i][2]<< "=" <<ENDL;} Break }}else if (a[i][2]<0) {switch (a[i][1]) {case 0:{cout<<a[i][0]<< "+ (" <<A[i][2]<< ") =" <& Lt;endl;} Break Case 1:{cout<<a[i][0]<< "-(" <<A[i][2]<< ") =" <<ENDL;} Break Case 2:{cout<<a[i][0]<< "* (" <<A[i][2]<< ") =" <<ENDL;} Break Case 3:{cout<<a[i][0]<< "/(" <<A[i][2]<< ") =" <<ENDL;} Break }}}}//random number Range set void Setlong (int &m,int &m) {cout<< "Please enter a value range: (e.g. 1-100 input 1,100)!"; Value range setting Cin>>m>>m;while (m>m) {cout<< "M<m,please input seconds!" <<endl<<endl;cin>>m>>m;}} Set whether there is multiplication void setysf (int n,int a[][3]) {cout<< "Close multiplication Method!" <<endl;int i;int C;srand (Unsigned (Time (NULL))); for (i=0;i<n;i++) {c=rand ()%2; A[i][1]=c;}} Set arithmetic Division no remainder void setcomplementation (int m,int m,int n,int a[][3]) {cout<< "Division does not exist remainder!" <<endl<<endl;int i;for (i=0;i<n;i++) {while (a[i][0]%a[i][2]!=0) {set (M,m,a,i),//avoids repeated occurrences of a number while (a[i+ 1][0]==a[i][0]&&a[i+1][2]==a[i][2]) {set (M,m,a,i);}}} void Main () {//define variable int a[n][3]; Store random number//int a,b,c; Random number variable int n=30; n is the number of output lines (can be set by the input, the program is not set by simple) int m=1,m=99; The default range for random numbers is 1-99srand (unsigned (Time (NULL))); Changes in system time to random seed guarantee number//loop int q=1;while (q!=5) {cout<<endl<<endl;cout<< "--------------------------- ---------------"<<endl;cout<<"-----------1: Set the range of random numbers---------------"<<endl;cout<<"------ ------------------------------------"<<endl;cout<<"-----------2: Set operator results---------------"<<endl;cout << "------------------------------------------" <<endl;cout<< "-----------3: Set the random number plus---------------<<endl;cout<<------------------------------------------"<<endl;cout <<---------4: Set the remainder of division-----------<<endl;cout<<------------------------------------------ "<<endl;cout<<"-----------------5: End-------------------"<<endl;cout<<"---------------- --------------------------"<<endl;cin>>q;switch (q) {case 0:break;return;case 1:setlong (m,m); setnumber (m,m,n,a); output (n,a); Break;case 2:setlong (M,m); Setnumber (m,m,n,a); SETYSF (n,a); output (n,a); Break;case 3:setlong ( M,M), if (m<0) M=0;setnumber (m,m,n,a), Output (n,a), Break;case 4:setlong (m,m); Setnumber (m,m,n,a); Setcomplementation (n,m,n,a); output (n,a); break;}}}
Five. Results (this is only a function)
Introduction to Software Engineering-arithmetic