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

C++ P2 1)Who can access private data in a class? a)members of the class b)friend

ID: 3866054 • Letter: C

Question

C++

P2

1)Who can access private data in a class?

a)members of the class

b)friends of the class

c)members of the class and of derived classes

d)members of the class and friends

2)C++ vectors are generally preferred to dynamic arrays because

a)arrays cannot contain object elements

b)vectors can grow and shrink

c)all choices are true

d)vectors can never be empty

3)A derived class has access to

a)the public functions and variables of its ancestor classes

b)private and public functions and variables of its ancestor classes

c)private and protected functions and variables of its ancestor classes

d)the private functions and variables of its ancestor classes

4)Operators can be overloaded as

a)friends of a class

b)members of a class

c)data members of a class

d)members or friends of a class

5)Functions should normally be made virtual

a)if they are friend functions

b)if they are private functions

c)always

d)if they are meant to be overriden

6)When calling a function on an object pointed to by a pointer variable, we use operator

a)=

b).

c)::

d)->

7)What is the value of str after the following code?

string str;

a)garbage

b)uninitialized

c)null

d)empty string

8)If you define a function in the derived class that has the same function signature as a function in

the base class, this is known as

a)reloading

b)overwriting

c)redefinition

d)overloading

9)When an unusual situation or error occurs

a)the exit statement is executed

b)the try statement is executed

c)the catch statement is executed

d)the throw statement is executed

Explanation / Answer

1.

d)members of the class and friends

friend classes and friend functions can also access private data of a class

2.

b)vectors can grow and shrink

3.

a)the public functions and variables of its ancestor classes

derived class cannot access private members

4.

d)members or friends of a class

5.

d)if they are meant to be overriden

eg area() function in base class Shape is overriden in rectangle class

6.

d)->

7.

d)empty string

8.

c)redefinition

9.

d)the throw statement is executed

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote