One, my program does not use the function, all the code in the main function, so it can only be used in the written part of the program to test.
Second, the source code
#include"stdafx.h"#include<iostream.h>#include<stdlib.h>#include<time.h>intMainintargcChar*argv[]) {Srand (Time (NULL)); intph[Ten];//create a capture array to hold the input selection intpway,num1,num2;//used to indicate how to print inti,j; printf ("The following 0 indicates "No" and 1 means "yes" \ n"); printf ("Please enter the number of topics to print:"); scanf ("%d", &ph[0]);//A[0] The number of printed questions storedprintf"Please enter how to print (Number of columns):"); scanf ("%d", &ph[1]);//A[1] Represents the number of columns enteredprintf"Please enter whether there is a multiplication method:"); scanf ("%d", &ph[2]);//A[2] Represents a multiplication methodprintf"Please enter a range of values:"); scanf ("%d", &ph[3]); for(i=0; i<ph[0]; i++) {NUM1= rand ()% (ph[3]+1); Num2= rand ()% (ph[3]+1); Switch(ph[2]) { Case 0://if there is no multiplication methodPway = rand ()%2;//construct random functions, output only add-subtract operations if(Pway = =0)//addition{printf ("<%d>%d+%d=\t", i+1, num1,num2); if((i+1)%ph[1] ==0) {printf ("\ n"); } } Else{printf ("<%d>%d-%d=\t", i+1, num1,num2); if((i+1)%ph[1] ==0)//determine if line breaks{printf ("\ n"); } } Break; Case 1://output with the multiplication methodPway = rand ()%4; Switch(pway) { Case 0://additionprintf"<%d>%d+%d=\t", i+1, num1,num2); if((i+1)%ph[1] ==0) {printf ("\ n"); } Break; Case 1: if(ph[4] ==0) { if(NUM1<NUM2)//determine minuend greater than meiosis, other controls such as the above subtraction control{i= I1; } Else{printf ("<%d>%d-%d=\t", i+1, num1,num2); if((i+1)%ph[1] ==0) {printf ("\ n"); } } } Else{printf ("<%d>%d-%d=\t", i+1, num1,num2); if((i+1)%ph[1] ==0) {printf ("\ n"); } } Break; Case 2://multiplicationprintf"<%d>%dx%d=\t", i+1, num1,num2); if((i+1)%ph[1] ==0) {printf ("\ n"); } Break; Case 3://Division if(num2 = =0)//the divisor cannot be zero{i= i-1; } Else{printf ("<%d>%d÷%d=\t", i+1, num1,num2); if((i+1)%ph[1] ==0) {printf ("\ n"); } } Break; default: printf ("Error! \ n"); Break; } Break; default: printf ("Error! \ n"); Break; } } return 0;}
Third, test data and results
1. Test data: 1,2,0,10, that is, the number of topics 1, the printing method is 2 columns, there is no multiplication method, the value range is less than 10 non-negative.
2. Test data: 30,4,0,20, that is, the number of topics 30, the printing method is 4 columns, there is no multiplication method, the value range is less than 20 non-negative.
3. Test data: 30,5,1,40, that is, the number of topics 30, the printing method is 5 columns, there is multiplication method, the value range is less than 40 non-negative.
Iv. description
In the test results of this program, there is no error, the input to the edge data as shown in the slice. However, the code does not implement the ability to handle exceptions.
For example, when the input is not a number but a character, so in this respect did not do the corresponding test.
Arithmetic test procedure