39. Given the function prototype, what is wrong with the following function call
ID: 3559774 • Letter: 3
Question
39. Given the function prototype, what is wrong with the following function call? float aFunction(int, int&, float); // function prototype float y = aFunction(b, a + b, 3.7); // function call
38.
What is the output of the following function call given the function definition below?
cout << myFunction(8); // function call
37.
What is wrong with the following code?
36.
What is the output of the following code?
35.
What is the value of x after the following code segment executes, if y is 20 and z is 2?
34.
Write in C++ code:
age is outside the range p to q
33. Functions like length, at and erase are called _________________________ of the string class.
30. Write the following statement in C++: x = 3y/(5-z)
Explanation / Answer
39. Given the function prototype, what is wrong with the following function call?
float aFunction(int, int&, float); // function prototype
float y = aFunction(b, a + b, 3.7); // function call
second argument should be a variable as it is reference...so it can not be a+b
38. What is the output of the following function call given the function definition below?
cout << myFunction(8); // function call
int myFunction(int x) // function definition
{
bool flag = false;
while (!flag)
{
x = x + 1;
flag = ((x%2 == 0) && (x%3 == 0));
}
return x;
}
myFunction(8)
x = 8+1 = 9
flag = ((9%2==0) && (9%3==0) = false;
x = 9+1 = 10
flag = ((10%2==0) && (10%3==0) =false;
x = 10+1=11
flag = ((11%2==0) && (11%3==0)=false;
x = 11+1 = 12
flag = ((12%2==0) && (12%3==0)=true;; while loop breaks here.
function returns 12.
37.What is wrong with the following code?
int total, number;
int counter = 0;
while (counter < 10)
{
cin >> number;
total = total + number;
counter = counter + 1;
}
total is not intialized with zero.
36.What is the output of the following code?
int a = 3, b = 2;
int c = 0;
while (c < 3)
{
a = a + b;
cout << a << " ";
c = c + 1;
}
cout << b;
a = a+b = 3+2 = 5
c = 1
a = 5+2 = 7
c = 2
a = 7+2 = 9
c = 3
b = 2 so OUTPUT IS 5 7 9 2
35.What is the value of x after the following code segment executes, if y is 20 and z is 2?
switch (y - z)
{
case 20: x = Y + z; break;
case 21: x - y; break;
case 22: x = z; break;
default: x = y * 2;
}
y-z = 20-2 = 18 since case 18 is not there..it go to default statement thus x = y*20 = 2*20 = 40;
value of x is 40;
34. Write in C++ code: age is outside the range p to q
if(age <p || age > q)
33. Functions like length, at and erase are called methods of the string class.
30. Write the following statement in C++: x = 3y/(5-z)
x = (3*y)/(5-z);
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.