cs 3420 intro to software enginering c function carefully fl

cs 3420 intro to software enginering

c++ function carefully

float compute_bill(char c, float x, float y )

{

float ret;

if (( x> = 0.0)&& ( x<= 10.0))

ret = 8.0 *x;

else

}

return(ret);

}

in order to have branch coverage in white box testing on the function , list the inputs and the expected output of every test case.

Solution

First of all the written code will not compile as there is a curly brace problem. Now, considering the below code correct here are the test cases.

float compute_bill(char c, float x, float y )
{
float ret;
if (( x> = 0.0)&& ( x<= 10.0))
ret = 8.0 *x;
else
{
  
}
return(ret);
}

/*
There are two branches in above code.
first is If branch and the other is without if branch
  
for first condition:
Input x = 5
since 5>=0 && 5<=10
if branch evaluates to true
and res = 8*5 = 40.0
  
output returned is 40.0;
  
For second condition
Input x = 11
11>=0 && 11<=10
if branch evaluates to false and else block has nothing to execute.
random value of ret variable will be returned to the caller function
*/

cs 3420 intro to software enginering c++ function carefully float compute_bill(char c, float x, float y ) { float ret; if (( x> = 0.0)&& ( x<= 10.

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site