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

1/ What is the output of the following function and function call ? void calcula

ID: 3625163 • Letter: 1

Question

1/ What is the output of the following function and function call ?

void calculateCost(int count,float&subTotal,float&taxCost);

float tax=0.0
subTotal=0.0
calculateCost(15,subTotal,tax);
cout<<"The cost for 15 items is"<<subtotal
<<",and the tax for"<<subTotal<<"is"<<tax<<endl;
//end of fragment

void calculatetCost)int count,float&subTotal,float&taxCost)
{
if ( count <10)
{
subTotal= count*0.50;
}
else
{
subTotal = count*0.20;
}
taxCost=0.1*subTotal;
}
a. The cost for 15 items is 3.00, and the tax for 3.00 is 0.30;
b. The cost for 15 items is 0.00, and the tax for 3.00 is 0.00
c.The cost for 15 items is 0.00, and the tax for 3.00 is 0.30;
d. The cost for 15 items is 3.00 and the tax for 3.00 is 0.00;

2/ What is the value of i after the following function call ?
//function definition
int dosomething(int value)
{
value=35;
return value;
value=13
}
//fragment of main program
int i=0
cout<<doSomething(i);
a. 13 b.35 c.48 d.0

3/ What is the output of the following function call ?
//function body
int factorial(int n)
{
int product=);
while(n>0)
{
product=product*n;
n+;
}
return product;
}
//fucntion call
cout<<factorial(4);

a.4 b.0 c.24 d.48

4/ Given the function definition

void something ( int a, int& b)
{
int c;
c=a+2;
a=a*3;
b=c+a;
}
what is the output of the following code fragment that invokes something ?
(All variable are type int.)
r=1;
s=2;
t=3;
something(t,s);
cout<<r<<"<<s<<"<<t<<endl;

a. 1 14 3 b.1 10 3
c.5 14 3 d. 1 14 9
e. none of the above

Explanation / Answer

please rate - thanks

1/ What is the output of the following function and function call ?

void calculateCost(int count,float&subTotal,float&taxCost);

float tax=0.0
subTotal=0.0
calculateCost(15,subTotal,tax);
cout<<"The cost for 15 items is"<<subtotal
<<",and the tax for"<<subTotal<<"is"<<tax<<endl;
//end of fragment

void calculatetCost(int count,float&subTotal,float&taxCost)
{
if ( count <10)
{
subTotal= count*0.50;
}
else
{
subTotal = count*0.20;          15*.2=3
}
taxCost=0.1*subTotal;          3*.1=.3
}
a. The cost for 15 items is 3.00, and the tax for 3.00 is 0.30;     reference parameters so both change
b. The cost for 15 items is 0.00, and the tax for 3.00 is 0.00
c.The cost for 15 items is 0.00, and the tax for 3.00 is 0.30;
d. The cost for 15 items is 3.00 and the tax for 3.00 is 0.00;

2/ What is the value of i after the following function call ?
//function definition
int dosomething(int value)
{
value=35;
return value;
value=13                                 //never reached 35 returned
}
//fragment of main program
int i=0
cout<<doSomething(i);
a. 13 b.35 c.48 d.0

3/ What is the output of the following function call ?
//function body
int factorial(int n)
{
int product=);                 I assume product=1    and n+ should be n--
while(n>0)  
{
product=product*n;
n+;
}
return product;
}
//fucntion call
cout<<factorial(4);               if my assumptions are correct 4*3*2*1=24

a.4 b.0 c.24 d.48

4/ Given the function definition

void something ( int a, int& b)
{                a=3      b=2         c
int c;
c=a+2;                                         5
a=a*3;              9
b=c+a;                           14                 only b goes back to s since it's referece t in main won't change
}
what is the output of the following code fragment that invokes something ?
(All variable are type int.)
r=1;
s=2;
t=3;
something(t,s);
cout<<r<<"<<s<<"<<t<<endl;

a. 1 14 3 b.1 10 3
c.5 14 3 d. 1 14 9
e. none of the above