#include <iostream.h>#include<stdlib.h>#include<time.h>voidDisplayintNumberintLintMulintNumintNegintremainder)//Print mode control output column Count{ inta[ +],b[ +],c[ +]; intM//control problems to avoid duplication intT//Intermediate Variables for(intI=0; i<number;i++)//Random Two build operation operands{m=1;//InitializeA[i]=rand ()%num; B[i]=rand ()%num; if(mul==0)//no multiplication method .{C[i]=rand ()%2;//randomly generate 0-1 of the numbers, respectively, to indicate the plus and minus } Else if(mul==1)//there is a multiplication method{C[i]=rand ()%4;//randomly generates 0-3 of the numbers, respectively, to represent the plus and minus multiply } for(intj=0; j<i;j++) { if(A[j]==a[i]&&b[j]==b[i]&&c[j]==c[i])//Compare whether the newly generated operand is the same as the original{i=i-1; M=0; } } while(m)//if different, the output { Switch(C[i]) { Case 0: cout<<a[i]<<"+"<<b[i]<<"="; Break; Case 1: if(neg==0)//subtraction No negative numbers { if(a[i]<B[i]) {T=A[i]; A[i]=B[i]; B[i]=T; } cout<<a[i]<<"-"<<b[i]<<"="; Break; } Else if(neg==1)//subtraction has a negative number{cout<<a[i]<<"-"<<b[i]<<"="; Break; } Case 2: cout<<a[i]<<"*"<<b[i]<<"="; Break; Case 3: if(b[i]==0)//a denominator of zero does not count toward the total{i=i-1; Break; } Else if(remainder==0)//Division has no remainder { if(a[i]%b[i]==0) {cout<<a[i]<<"/"<<b[i]<<"="; Break; } Else{i=i-1; Break; } } Else if(remainder==1)//Division Surplus Number { if(a[i]%b[i]!=0) {cout<<a[i]<<"/"<<b[i]<<"="; Break; } Else{i=i-1; Break; } } } if((i+1)%l==0) {cout<<Endl; } Else{cout<<"\ t"; } Break;//Jump out of the loop } }}voidMain () {intNumber//Number of topics intL//number of columns to output intMul//Multiplication Method intNum//range of Values intNeg//Negative number intremainder;//remainder intC//Loop Variable while(c) {Srand ((unsigned) time (NULL));//call a random function generatorcout<<"---------------------------------"<<Endl; cout<<"arithmetic"<<Endl; cout<<"---------------------------------"<<Endl; cout<<"Please enter the number of topics to print:"<<Endl; CIN>>Number ; cout<<"Please enter the number of columns to output (1-10):"<<Endl; CIN>>l; cout<<"whether there is a multiplication law (0 means no; 1 indicates)"<<Endl; CIN>>Mul; Switch(mul) {default: {cout<<"input Error, please re-enter! Whether there is a multiplication law (0 means no; 1 indicates)"<<Endl; CIN>>Mul; } Break; Case 0: Break; Case 1: {cout<<"Divide has no number (0 means no; 1 indicates)"<<Endl; CIN>>remainder; Switch(remainder) {default: {cout<<"input Error, please re-enter! Divide has no number (0 means no; 1 indicates)"<<Endl; CIN>>remainder; } Break; Case 0: Case 1: Break; } } Break; } cout<<"Please enter a numeric range of positive integers (that is, maximum number):"<<Endl; CIN>>num; cout<<"subtraction has no negative number (0 means no; 1 indicates)"<<Endl; CIN>>neg; Display (Number,l,mul,num,neg,remainder); cout<<"continue Please enter 1, exit Please enter 0"<<Endl; CIN>>C; }}
Test:
Input is correct: 20 2 1 1 100 1
Input 200 20 1 1 200 1
At this point, due to the page size limit, the number of columns entered in the output cannot be
When entering letters: a
Input 10000 10 2 0 190 1
may be out of range, the program will run the final error. Stop running ...
Because the program is not well written, there are a lot of problems in testing, and need further improvement.
Arithmetic 2 unit Test