July 22, March 21: Small Test (Week 4), Week 4 on the 21st
Problem: function for generating the maximum value in unit test
Design Concept: Use the maximum function to generate the maximum value, and then define the function to bring the maximum value into the check to check whether it is the maximum value. Specifically, compare it with the array element in sequence to be greater than or equal to all elements. For inspection.
Program source code:
1 # include <iostream> 2 # include <vector> 3 using namespace std; 4 5 int Largest (vector <int> & list) 6 {7 int max = list [0]; 8 if (list. size () <5) 9 {10 cout <"the number of input digits is less than 5 or the array is empty"; 11} 12 else13 {14 for (int I = 0; I <5; I ++) 15 {16 if (list [I]> max) 17 {18 max = list [I]; 19} 20} 21} 22 return max; 23} 24 void Ceshi (vector <int> & list) 25 {26 cout <Largest (list) <endl; 27 for (int j = 0; j <5; j ++) 28 {29 if (list [j]> Largest (list) 30 Cout <"error! "; 31} 32} 33 void main () 34 {35 vector <int> list (5); 36 Ceshi (list); 37 list [0] = 1; list [1] = 2; list [2] = 3; list [3] = 4; list [4] = 5; 38 Ceshi (list ); 39 list [0] =-1; list [1] =-2; list [2] =-3; list [3] =-4; list [4] =-5; 40 Ceshi (list); 41 list [0] = 2; list [1] = 2; list [2] = 2; list [3] = 2; list [4] = 2; 42 Ceshi (list); 43 list [0] = 1; list [1] = 2; list [2] = 4; list [3] = 3; list [4] = 5; 44 Ceshi (list); 45 list [0] = 5; list [1] = 4; list [2] = 3; list [3] = 2; list [4] = 1; 46 Ceshi (list); 47}
Result:
Result Error Analysis: c ++ still cannot solve the null array problem. In this case, an empty array cannot be defined for the result solved by vector.