1. A pointer variable to a char contains _________ A) The address of a string va
ID: 3645341 • Letter: 1
Question
1. A pointer variable to a char contains _________
A) The address of a string varaible.
B) The address of a char variable.
C) The address of a double variable.
D) A value of a character the pointer points to.
E) None of the above.
2. The default constructor is the only constructor that ______ .
A) contains the same name as its class.
B) is declared public in the class definition.
C) specifies no parameters or parameter(s) with default value(s).
D) specifies one or more parameters.
3. The expression x = &y can be used to ______.
A) assign the value of y to variable x.
B) assign the value of y to pointer variable x.
C) assign the address of x to the variable y.
D) assign the address of y to pointer variable x.
E) assign the value of the variable to which y points to the variable to which x points.
4. Abstract classes
A) must explicitly include a pure virtual function.
B) can have objects instantiated from them if the proper permissions are set.
C) cannot have abstract derived classes.
5. If objects of classes all derived from the same base class all need to draw themselves,
the draw() function would most likely be
A) private
B) virtual
C) protected
D) global
6. virtual functions are required to
A) be defined in every derived class.
B) be declared virtual in every derived class.
C) be declared virtual in the base class.
D) be declared virtual in the base class and the devired classes.
7. What is wrong with the following abstract class definition?
class Shape
{
public:
virtual double print() const;
double area() const
{ return base * height;
}
private:
float base;
float height;
}
A) There is no pure virtual function.
B) There is a non-virtual function.
C) Private variables are being accessed by a public function.
D) Nothing wrong.
8. Classes cannot
A) Be derived from other classes.
B) Initialize data members in the class definition.
For example:
private:
int x = 0;
C) Be used to model attributes and behaviors of objects.
D) Include objects from other classes as members.
9. Based on the code segments below, which of the following classes illustrates object
composition?
class One
{
protected:
string name;
};
class Two : public One
{
double name;
};
class Three
{
private:
One myObject;
};
A) One
B) Two
C) Three
D) All classes
E) None of the above.
10. Overloaded functions must have:
A) Different parameter lists.
B) Different return types.
C) The same number of parameters.
D) The same number of default arguments.
11. Based on the code segments below, which of the following classes illustrates inheritance?
class One
{
protected:
string name;
};
class Two : public One
{
double name;
};
class Three
{
private:
One myObject;
};
A) One
B) Two
C) Three
D) One and Two
E) None of the above.
12.
Calling a member function of an object ( that is a pointer) requires which item?
A)
The dot operator . For example ptr.func();
B)
The -> operator. For example: ptr->func();
C)
The class name . For example : classname.func();
D)
All of the above.
13.
Based on the code segments below, what is the base class.
class One
{
protected:
string name;
};
class Two : public One
{
double name;
};
class Three
{
private:
One myObject;
};
A) One
B) Two
C) Three
D) One and Two
E) None of the above.
14. Copy constructor requires
A) an object to be copied of the class to be a parameter.
B) an value to be copied of the class to be a parameter.
C) no parameter.
D) None of the above.
15. Dynamic binding is the same as compile-time binding.
A) True
B) False
16.
Given the declaration
class myClass
{
public:
void print();
private:
int x;
};
myClass AA; //declared in the main( ) function.
The following statement is legal.
AA.x = 10;
A) True
B) False
17.
Given the declaration
class myClass
{
public:
void print( int a )
{ x = a; cout << x << endl; }
private:
int x;
};
myClass AA; //declared in main
The following statement is valid in C++.
AA.print( 5 );
A) True
B) False
18.
A derived class cannot _________ access __________ members of its base class.
A)
directly, protected
B)
ever, private
C)
indirectly, public
D) directly, private
19.
protected base class members can be accessed by
A) derived class member functions
B) derived class objects
C) a friend function of the class
D) All of the above
20.
When an object of a derived class is instantiated, the __________ constructor must
be called for the _________ members.
A) base class, base class
B) derived class, base class
C) base class, derived class
D) derived class, public
E) None of the above
21. A function template can be overloaded by
A) using other function templates with the same function name and parameters.
B) using non-template functions with the same name and different parameters.
C) using non-template functions with the same name and the same parameters.
D) using other function templates with a different name but the same parameters.
22. Class templates
A)
may include the statement template< class Type > anywhere.
B)
must include template< class Type > before the class definition.
C)
must put template< class Type > inside the class definition.
D)
have the option of including the statement template< class Type >.
23.
For a template class, the binary scope resolution
operator (::) is needed
A) only in the definitions of the member functions.
B) only in the definitions of friend functions declared in the class.
C) only if there are multiple class templates.
D) in neither the definition nor prototype of member functions.
24. The following structure is typically used for a node in a linked list:
struct Node
{ char gender;
string name;
Node myNode;
};
A) True
B) False
25. The vector class is not a standard template library.
A) True
B) False
26. If a vector , vecList, contains elements,the following statement is valid:
cout << vecList[0] ;
A) True
B) False
27. The new keyword is not needed when allocating a node in a linked list at run time.
A) True
B) False
Explanation / Answer
1.
Answer: B
Explanation: A pointer variable holds the address of the variable of same data type. Therefore, pointer variable to a char contains the address of a char variable.
2.
Answer: A
Explanation: A constructor is executed at the time of object creation. It must have same class name and it have no return type.
3.
Answer: B
Explanation: Consider the statement x=&y
x is a pointer variable and y is a normal variable and & refers to the address of the other variable. So the statement defines as, assign the value of y to the pointer variable x.
4.
Answer: B
Explanation: Abstract classes need to be extended. But cannot be instantiated from the other classes. But they can be used as subclasses.
5.
Answer: B
Explanation: Here draw() function defined in base class and overridden in subclass. So that draw() function used as virtual.
6.
Answer: A
Explanation: If a function is declared as virtual in base class, then it becomes virtual in every derived class
7.
Answer: A
Explanation: From the given code, pure virtual function is not there. If a pure virtual function or abstract class is declared then assigning 0 to the function.
Here: virtual double print()=0;
8.
Answer: B
Explanation: Classes cannot not initialize the data members in the class definition as like the given example. Classes can be derived from the other classes and it consists of data members and member functions (acessors & mutators )and objects of the other classes also.
9.
Answer: B
Explanation: Object composition means to combine classes and object to become more complex. Those are building blocks of the data structures also. Here class Two combine with class one
10.
Answer: A
Explanation: Overloading function must have different parameter lists and different implementation. Selection of appropriate overloaded function is also termed as Overload resolution.
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.