【Q1】Which of the following must be ensured in order to implement a polymorphic function in C++?
A. There has to be a pointer of the derived class that has implemented the polymorphic function that holds the address of the derived class object.
B. The function must be declared as virtual in both the base class and in the derived class that overrides the function.
C. The function must be declared as pure virtual.
D. There has to be a base class pointer holding the address of a base or derived class object that has implemented the polymorphic function.
E. The function must be declared as virtual in the base class.
A. There has to be a pointer of the derived class that has implemented the polymorphic function that holds the address of the derived class object.
B. The function must be declared as virtual in both the base class and in the derived class that overrides the function.
C. The function must be declared as pure virtual.
D. There has to be a base class pointer holding the address of a base or derived class object that has implemented the polymorphic function.
E. The function must be declared as virtual in the base class.
【Q2】Which of the following statements accurately describe what it means for a class to grant friend status to a function in C++?
A. The function has been granted access to all the members of the class.
B. The function has been granted access only to the protected data and functions of the class.
C. The function has been granted access only to the private functions of the class.
D. The function has been granted access only to the protected functions of the class.
E. The function has been granted access only to the private data and functions of the class.
【Q3】A C++ developer wants to further throw an exception that is caught in an exception variable excep. Which of the following statements can the developer use to achieve
A. throw;
B. catch excep;
C. next;
D. throw next;
E. throw excep;
A. throw;
B. catch excep;
C. next;
D. throw next;
E. throw excep;
【Q4】What's the output of following C++ code excerpt?
#include <iostream>
template<class T> class Some
{
public:
static int stat;
};
template<class T>
int Some<T>::stat = 10;
int main(void)
{
Some<int>::stat = 5;
std::cout << Some<int>::stat << std::endl;
std::cout << Some<char>::stat << std::endl;
std::cout << Some<float>::stat << std::endl;
std::cout << Some<long>::stat << std::endl;
}
A. The output will be:
5
10
10
10
B. The output will be:
5
10
10
5
C. The output will be:
5
5
5
5
D. The output will be:
10
10
10
10
template<class T> class Some
{
public:
static int stat;
};
template<class T>
int Some<T>::stat = 10;
int main(void)
{
Some<int>::stat = 5;
std::cout << Some<int>::stat << std::endl;
std::cout << Some<char>::stat << std::endl;
std::cout << Some<float>::stat << std::endl;
std::cout << Some<long>::stat << std::endl;
}
A. The output will be:
5
10
10
10
B. The output will be:
5
10
10
5
C. The output will be:
5
5
5
5
D. The output will be:
10
10
10
10
E. The output will be:
10
5
5
10
10
5
5
10
【Q5】When a Copy Constructor is NOT written for a class, the C++ compiler generates one. Which of the following statements correctly describe the actions of this compilergenerated Copy Constructor when invoked?
A. The compilergenerated Copy Constructor performs a memberwise copy of the object passed to it as an argument, into the object being constructed.
B. The compilergenerated Copy Constructor makes the object being constructed, a reference to the object passed to it as an argument.
C. The compilergenerated Copy Constructor tags the object as having been CopyConstructed by the compiler.
D. The compilergenerated Copy Constructor does not do anything by default.
E. The compilergenerated Copy Constructor invokes the assignment operator of the class.
A. The compilergenerated Copy Constructor performs a memberwise copy of the object passed to it as an argument, into the object being constructed.
B. The compilergenerated Copy Constructor makes the object being constructed, a reference to the object passed to it as an argument.
C. The compilergenerated Copy Constructor tags the object as having been CopyConstructed by the compiler.
D. The compilergenerated Copy Constructor does not do anything by default.
E. The compilergenerated Copy Constructor invokes the assignment operator of the class.
【Q6】The variables x, y, and z are integer variables that have been properly declared and initialized in C++. Which of the following statements can call the macro below without
cted results?
#define YEAR_LENGTH 365
#define MONTH_LENGTH 30
#define DAYCALC(y, m, d) ((y * YEAR_LENGTH) + (m * MONTH_LENGTH) + d)
A. DAYCALC(x * 3, y % 3, z);
B. DAYCALC(x, 40y, 3+z);
C. DAYCALC(x+12, y, 300);
D. DAYCALC(x, y, (z + 50));
E. DAYCALC(4 % x, y++, z);
cted results?
#define YEAR_LENGTH 365
#define MONTH_LENGTH 30
#define DAYCALC(y, m, d) ((y * YEAR_LENGTH) + (m * MONTH_LENGTH) + d)
A. DAYCALC(x * 3, y % 3, z);
B. DAYCALC(x, 40y, 3+z);
C. DAYCALC(x+12, y, 300);
D. DAYCALC(x, y, (z + 50));
E. DAYCALC(4 % x, y++, z);
【Q7】Which of the following are valid statements considering the C++ code snippet below?
int foo(longg l);
//...
int i = 12;
foo(i);
A. The function foo is invoked with an int that has a value of "12".
B. The function foo is invoked with a long that has an undefined value.
C. The compiler instantiates a new function that accepts an int instead of a long.
D. The function foo is invoked with a long that has a value of "12".
E. i is promoted to a long to invoke the function foo.
int foo(longg l);
//...
int i = 12;
foo(i);
A. The function foo is invoked with an int that has a value of "12".
B. The function foo is invoked with a long that has an undefined value.
C. The compiler instantiates a new function that accepts an int instead of a long.
D. The function foo is invoked with a long that has a value of "12".
E. i is promoted to a long to invoke the function foo.
【Q8】Which of the following are accurate statements concerning the behavior of the dynamic_cast operator in C++?
A. The dynamic_cast operator fails if used for upcasting.
B. The dynamic_cast operator returns the object's address if the operation succeeds.
C. The dynamic_cast operator may return 0 if the operation fails.
D. The dynamic_cast operator's behavior is a subset of the reinterpret_cast operator's behavior.
E. The dynamic_cast operator throws an invalid_cast exception if the operation fails.
A. The dynamic_cast operator fails if used for upcasting.
B. The dynamic_cast operator returns the object's address if the operation succeeds.
C. The dynamic_cast operator may return 0 if the operation fails.
D. The dynamic_cast operator's behavior is a subset of the reinterpret_cast operator's behavior.
E. The dynamic_cast operator throws an invalid_cast exception if the operation fails.
【Q9】A C++ developer wants to convert a userdefined type into a basic data type. Which of the following methods can the developer use to do this?
A. Write a conversion function to convert the userdefined class to a builtin data type.
B. Write a constructor that accepts the userdefined type as an argument.
C. Write a virtual constructor.
D. Write a constructor that accepts the basic data type as an argument.
E. Overload the assignment operator for the userdefined class.
【Q10】For the C++ code below, which of the following assignments for r will produce the value "6"?
int r = 0;
int arr[5] = {2,4,6};
int* p = arr;
A. r = p[2];
B. r = *(arr+2);
C. r = *arr[2];
D. r = *(arr+*p);
E. r = p+2;
int r = 0;
int arr[5] = {2,4,6};
int* p = arr;
A. r = p[2];
B. r = *(arr+2);
C. r = *arr[2];
D. r = *(arr+*p);
E. r = p+2;
#include <iostream>
#include <fstream>
int main(int argc, char* argv[])
{
using namespace std;
fstream log("log.txt", ios::out);
streambuf* clog_buf = clog.rdbuf(log.rdbuf());
clog << "Test the logger" << endl;
//*****
}
A. Nothing is missing.
B. exit();
C. clog.rdbuf(clog_buf);
D. clog.rdbuf(0);
E. log.rdbuf(0);