Programming Ideas

The design of this program is mainly based on the application of random numbers generated in C/s + +, in the generation of arithmetic symbols part of the main use of the switch statement, by randomly generating 0-3 of the value to randomly generate "+-*/" character, and the corresponding processing; When working with integer operations, use the Try/throw statement, Avoid division denominator is 0, the statement takes a one-dimensional array, records the answer result, in the processing true fraction part, uses the while statement to produce the reasonable true fraction, uses the two dimensional array to record the answer result.

Program source Code

#include <iostream.h>#include<stdlib.h>#include<conio.h>voidDealfenshu (intMinta[][2]){ for(intp=0;p <m;p++) { intI= (int) rand ()%Ten; intJ= (int) rand ()%Ten; while(j==0|| i>=j) {I=(int) rand ()%Ten; J=(int) rand ()%Ten; } intX= (int) rand ()%Ten; intY= (int) rand ()%Ten; while(y==0|| x>=y) {x=(int) rand ()%Ten; Y=(int) rand ()%Ten; } intK= (int) rand ()% -/ -; Switch(k) { Case 0: cout<<"("<<i<<"/"<<j<<")"<<"+"<<"("<<x<<"/"<<y<<")"<<"="; a[p][0]=i*y+x*J; a[p][1]=j*y; Break; Case 1: cout<<"("<<i<<"/"<<j<<")"<<"-"<<"("<<x<<"/"<<y<<")"<<"="; a[p][0]=i*y-x*J; a[p][1]=j*y; Break; Case 2: cout<<"("<<i<<"/"<<j<<")"<<"*"<<"("<<x<<"/"<<y<<")"<<"="; a[p][0]=i*x; a[p][1]=j*y; Break; Case 3: a[p][0]=i*y; a[p][1]=j*x; cout<<"("<<i<<"/"<<j<<")"<<"/"<<"("<<x<<"/"<<y<<")"<<"="; } if(p%5==4) {cout<<Endl; } Else{cout<<'\ t'; } }}voidDisplayfenshu (inta[][2],intWintm) { if(w==1) { for(intq=0; q<m;q++) { if(a[q][0]==0) cout<<"0"<<'\ t'; Elsecout<<a[q][0]<<"/"<<a[q][1]<<'\ t'; if(q%5==4) {cout<<Endl; } } } Else {};}voidDealint (intMinta[]) { for(intp=0;p <m;p++) { intI= (int) rand ()%Ten; intJ= (int) rand ()%Ten; intK= (int) rand ()% -/ -; Switch(k) { Case 0: cout<<i<<"+"<<j<<"="; A[P]=i+J; Break; Case 1: cout<<i<<"-"<<j<<"="; A[P]=i-J; Break; Case 2: cout<<i<<"*"<<j<<"="; A[P]=i*J; Break; Case 3: Try{A[p]=i/J; cout<<i<<"/"<<j<<"="; } Catch(...) {P--; } } if(p%5==4) {cout<<Endl; } Else{cout<<'\ t'; } }}voidDisplayint (intA[],intWintm) { if(w==1) { for(intq=0; q<m;q++) {cout<<a[q]<<'\ t'; if(q%5==4) {cout<<Endl; } } } Else {};}voidMain () {intp; Do{System ("CLS"); inta[ +],b[ +][2]; intm,n,w; cout<<"Please enter the number of arithmetic questions generated:"; CIN>>m; cout<<Endl; cout<<"Please enter the type of arithmetic you want to generate (enter 1 as an integer, otherwise true):"; CIN>>N; cout<<Endl; if(n==1) {dealint (m,a); cout<<Endl; } Else{Dealfenshu (m,b); cout<<Endl; } cout<<"whether to output the answer (enter 1 to output the answer otherwise do not output the answer)"<<Endl; CIN>>W; if(n==1) {displayint (a,w,m); } Else{Displayfenshu (b,w,m); } cout<<Endl; cout<<"whether to continue generating the operation question (input 1 is generated otherwise not generated)"<<Endl; CIN>>p; cout<<Endl; } while(1==p);}

The reason why the program was not completed on time: Forgot the statement rand () that generated the random number

The first program of the soft worker: like two pillars, spend 20 minutes writing a "software" that automatically generates the arithmetic of a primary school, requiring that the arithmetic of the true score be supported in addition to integers.