I. Which of the following function headings are valid? If they are invalid, explain why.
a. One(int a, int b) valid invalid
b. int ThisOne(char x) valid invalid
c. char Another(int a, b) valid invalid
d. double YetAnother valid invalid
II. Consider the following statements:
double num1 = 5.0; int int1 = 4; int value;
double num2 = 6.0; int int2 = 7;
double num3 = 3.0; int int3 = 8;
and the function prototype:
double Cube(double, double, double);
Which of the following statements are valid? If they are invalid, explain why?
a. value = Cube(num1, 15.0, num3); valid invalid
b. cout << Cube(num1, num3); valid invalid
c. cout << Cube(num1, int2, num3); valid invalid
d. value = Cube(int1, int2, int3); valid invalid
III. Consider the following functions:
int Secret( int x) int Another(int a, int b)
{ {
int i; int i;
int j; int j;
i = 2 * x; j = 0;
if ( i > 10) for ( i = a; i <= b; i++)
j = x / 2; j = j + 1;
else return j;
j = x / 3; }
return j – 1;
}
What is the output of each of the following program segments?
a. x = 10;
cout << Secret(x) << endl;
b. x = 5;
y = 8;
cout << Another(x, y) << endl;
IV. Consider the following function”
int Secret(int one)
{
int i;
int product = 1;
for ( i = 0; i <= 3; i++)
product = product * one;
return product;
}
What is the output of the following C++ statements?
a. cout << Secret(5) << endl;
b. cout << 2 * Secret(6) << endl;
V. Show the output of the following program
#include <iostream>
using namespace std;
int Mystery(int);
int main( )
{
int n;
for ( n = 1; n <= 5; n++)
cout << Mystery(n) << endl;
return 0;
}
int Mystery( int k)
{
int x;
int y;
y = k;
for ( x = 1; x <= (k – 1); x++)
y = y * (k – x);
return y;
}
VI. Show the output of the following program.
#include <iostream>
using namespace std;
bool Strange(int);
int main( )
{
int num = 0;
while (num <= 29)
{
if (Strange(num))
cout << “True” << endl;
else
cout << “False” << endl;
num = num + 4;
}
return 0;
}
bool Strange(int n)
{
if ( n % 2 == 0 && n % 3 == 0)
return true;
else
return false;
}
which of the following function headings are valid
- Technology: Multiple-Choice-Questions
- Code: SHC_MCQ_10006
-
$9.99
Tags: Multiple choice question, MCQ, c++, cpp, object oriented programming, oop