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

Please help with a couple quick and easy questions. Any explaination would be gr

ID: 3788284 • Letter: P

Question

Please help with a couple quick and easy questions. Any explaination would be greatly appreciated.

1) If you do not write one of these, a default will be provided for you by the compiler.

a) copy constructor

b) constructor

c) destructor

d) All of these

None of these

2) A class member that is to be shared among all objects of a class is called

a) A constant member

b) A reference member

c) A static member

d) A function member

3) Which of the following is correct syntax to declare C++ class B to be a public base class for

derived class D

public base class B: class D {/*…*/};

class D : public class B {/* … */};

class D : public B {/* … */};

class B: public D { };

None of the above

4) ________ members of a base class are never accessible to a derived class.

A) Public

B) Private

C) Protected

D) A, B, and C

E) None of these

5) Consider the class inheritance.

class B

{

public:

B();

B(int nn);

void f();

void g();

private:

int n;

};

class D: private B

{

public:

D(int nn, float dd);

void h();

private:

double d;

};

Which of the following functions can be invoked by an object of class D?

a) f()

b) g()

c) h()

d) All the above

6) A derived class object inherits all the members of the base class. Which of these remarks about the

inherited member variables is not true?

a) Inherited members are need to be allocated memory and should be initialized at creation of a

derived class object.

b) Inherited members are will be automatically managed by the C++ runtime system, so can be

safely ignored.

c) Inherited members’ memory allocation must be done by the base class constructor for the base

class, which must be called.

d) The base class constructor is the most convenient place to initialize these inherited variables.

7) The function

int fact(int k) {

return k*fact(k-1);

if (k==0) return 1;

}

a) works for all non-negative values of k, but not for negative numbers.

b) returns the value 1 if it is passed a value of 0 for the parameter k.

c) does not correctly handle its base case.

d) computes the factorial on an integer k passed to it as parameter.

e) None of the above.

Explanation / Answer

1 Ans) 'b'

Explanation:- Constructor in a class is used to initialise some variables and do some processing while creating the object of that class. If you do not define any constructor compiler will provide a default constructor to your class from which your super class constructor will be called.

2 Ans) 'C'

   Explanation:- A static member is something which is accessible to any class without the use of object and its value will be same across all objects. So, a static member will be shared among all objects instead of each object having one static member

3 Ans) 'D'

   Explanation:- Base classes are declared normally without any reference to the derived classes like below:-

4 Ans) 'B'

   Explanation:- private members are accessible only to the class in which they are defined.

protected memebers are accessible to the defining class and the derived classes

public members are accessible to every class

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