1 /******************************************************* 2 * Finds and prints n prime integers3 * Jeff Offutt, Spring 20034 ******************************************************/ 5 Public Static voidPrintprimes (intN)6 { 7 intCurprime;//Value currently considered for primeness8 intNumprimes;//Number of primes found so far.9Boolean isprime;//Is curprime prime?Ten int[] primes =New int[Maxprimes];//The list of prime numbers. One A //Initialize 2 into the list of primes. -primes [0] =2; -Numprimes =1; theCurprime =2; - while(Numprimes <N) - { -curprime++;//next number to consider ... +IsPrime =true; - for(inti =0; I <= numprimes-1; i++) +{//For each previous prime. A if(Isdivisible (primes[i], curprime)) at{//Found a divisor, curprime is not prime. -IsPrime =false; - Break;//Out of loop through primes. - } - } - if(IsPrime) in{//Save It! -Primes[numprimes] =Curprime; tonumprimes++; + } -}//End while the * //Print all the primes out. $ for(inti =0; I <= numprimes-1; i++) Panax Notoginseng { -System. out. println ("Prime:"+Primes[i]); the } +}//End Printprimes
A. Drawing the control flow diagram of a function
B. Design a t2= (n=5) to discover but t1= (n=3) can not find the error
If the function's first line if (isdivisible (primes[i], curprime)) is mistakenly written as if (Isdivisible ( Primes[0], Curprime), which is thedetection of whether each subsequent number is a prime, only checks if it can be divisible by 2 . when n = 3 , the identified prime number is 2,3,5 and no error occurs, but when n = 5 , the prime number to be found is 2,3,5,7,9 Error occurred
C. Finding a set of test cases that do not pass through a while loop
n = 1
D. Find all the TR (test requirements) covered by the point overlay, Edge overlay, and master path
- Node coverage: [1,2,3,5,6,9,5,6,8,10,11,2,4,12,13,14]
Side overlay:[1,2,3,5,6,9,5,6,8,10,11,2,4,12,13,14]
[1,2,3,5,10,2,4,12,14]
Main path: [1,2,3,5,6,8,10,11]
[1,2,3,5,10,11]
[1,2,3,5,6,9]
[5,6,9,5]
[2,3,5,6,8,10,2]
[2,3,5,6,8,10,11,2]
[2,3,5,10,2]
[2,3,5,10,11,2]
[1,2,4,12,13,14]
[1,2,4,12,14]
[3,5,6,8,10,11,2,4,12,13,14]
[3,5,6,8,10,2,4,12,13,14]
[3,5,10,11,2,4,12,13,14]
[3,5,10,2,4,12,13,14]
[3,5,6,8,10,11,2,4,12,14]
[3,5,6,8,10,2,4,12,14]
[3,5,10,11,2,4,12,14]
[3,5,10,2,4,12,14]
[9,5,6,8,10,11,2,4,12,13,14]
[9,5,6,8,10,2,4,12,13,14]
[9,5,6,8,10,11,2,4,12,14]
[9,5,6,8,10,2,4,12,14]
Main path Overrides:
[0,1,2,3,5,6,8,10,11,2,4,12,13,14]
[0,1,2,3,5,6,8,10,11,2,4,12,14]
[0,1,2,3,5,6,8,10,2,4,12,13,14]
[0,1,2,3,5,6,8,10,2,4,12,14]
[0,1,2,3,5,6,9,5,6,8,10,11,2,4,12,13,14]
[0,1,2,3,5,6,9,5,6,8,10,2,4,12,13,14]
[0,1,2,3,5,6,9,5,6,8,10,11,2,4,12,14]
[0,1,2,3,5,6,9,5,6,8,10,2,4,12,14]
[0,1,2,3,5,10,11,2,4,12,13,14]
[0,1,2,3,5,10,2,4,12,13,14]
[0,1,2,3,5,10,11,2,4,12,14]
[0,1,2,3,5,10,2,4,12,14]
Software Engineering HOMEWORK3