Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Analyze this C++ fuction, float compute_bill(char c, float x, float y){ if ((x>=

ID: 3578198 • Letter: A

Question

Analyze this C++ fuction,

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

if ((x>=0.0) && (x<=10.))

                ret = 8.0*x;

                ret = 5.0*x;

if ( c == 'c' )

                ret = ret +y;

else if ( c == 'p')

                ret = ret +0.5*y;

                else if ( c == 'v')

                ret = ret +0.2*y;

else if ( c == 's')

ret = ret +0.1*y;

else {

cout << "Invalid input";

In order to have branch coverage in white box testing on the function, list the input and the expected outputs of every test case:

Explanation / Answer

Test cases

1.when x=-1.0, y=1.0 and c='c'

In this case since x<0, So the output will be "Invalid Input".

2.when x=2.0, y=1.0 and c='c'

In this case since x> 0 and x<10, So
ret=8.0*2.0=16.0
ret=5.0*2.0=10.0
Then c='c' So,
ret=10.0+1.0=11.0

Therefore the ouput in this case is 11.0

3.when x=3.0, y=1.0 and c='p'

In this case since x> 0 and x<10, So
ret=8.0*3.0=24.0
ret=5.0*3.0=15.0
Then c='p' So,
ret=15.0+0.5(1.0)=15.5

Therefore the ouput in this case is 15.5

4.when x=4.0, y=2.0 and c='v'

In this case since x> 0 and x<10, So
ret=8.0*4.0=32.0
ret=5.0*4.0=20.0
Then c='v' So,
ret=20.0+0.2(2.0)=20.4

Therefore the ouput in this case is 20.4

5.when x=5.0, y=2.0 and c='s'

In this case since x> 0 and x<10, So
ret=8.0*5.0=40.0
ret=5.0*5.0=25.0
Then c='s' So,
ret=25.0+0.1(2.0)=25.2

Therefore the ouput in this case is 25.2

6.when x=3.0, y=1.0 and c='n'

In this case since x> 0 and x<10, So
ret=8.0*3.0=24.0
ret=5.0*3.0=15.0
Then c='n' So,the output will be "Invalid input"


Therefore the ouput in this case is "Invalid input"

7..when x=-1.0, y=1.0 and c='z'


In this case since x<0, So the output will be "Invalid Input".