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

Consider the following class definition: class dClass: bClass { //class members

ID: 3859764 • Letter: C

Question

Consider the following class definition:

class dClass: bClass
{
//class members list
};

The class dClass is derived from the class bClass using the ____ type of inheritance.

static

private

protected

public

1 points   

QUESTION 2

Suppose that bClass is a class. Which of the following statements correctly derives the class dClass from bClass?

class dClass:: public bClass
{
//classMembersList
};

class dClass: private bClass
{
//classMembersList
};

class bClass: public dClass
{
//classMembersList
};

class dClass:: protected bClass
{
//classMembersList
};

1 points   

QUESTION 3

____ is the ability to combine data, and operations on that data, in a single unit.

Inheritance

Composition

Polymorphism

Encapsulation

1 points   

QUESTION 4

What is the output of the following program?

#include <iostream>

using namespace std;

class bClass
{
public:
void print() const;
bClass(int a = 0, int b = 0);
//Postcondition: x = a; y = b;

private:
int x;
int y;
};

class dClass: public bClass
{
public:
void print() const;
dClass(int a = 0, int b = 0, int c = 0);
//Postcondition: x = a; y = b; z = c;

private:
int z;
};

int main()
{
bClass bObject(2, 3);
dClass dObject(3, 5, 8);

bObject.print();
cout << endl;
dObject.print();
cout << endl;

return 0 ;
}

void bClass::print() const
{
cout << x << " " << y << endl;
}

bClass::bClass(int a, int b)
{
x = a;
y = b;
}

void dClass::print() const
{
bClass:print();
cout << " " << z << endl;
}

dClass::dClass(int a, int b, int c)
: bClass(a, b)
{
z = c;
}

2 3

2 3

2 3

3 5 8

3 5 8

3 5 8

5 8

3 5 8

1 points   

QUESTION 5

Consider the following class definitions:

class bClass
{
public:
void set(double a, double b);
//Postcondition: x = a; y = b;
void print() const;

bClass();
//Postcondition: x = 0; y = 0;
bClass(double a, double b);
//Postcondition: x = a; y = b;

private:
double x;
double y;
};

class dClass: public bClass
{
public:
void set(double a, double b, double c);
//Postcondition: x = a; y = b; z = c;
void print() const;

dClass();
//Postcondition: x = 0; y = 0; z = 0 ;
dClass(double a, double b, double c);
//Postcondition: x = a; y = b; z = c;

private:
double z;
};

Which of the following dClass constructor definitions is valid in C++?

dClass::dClass(double a, double b, double c)
: bClass(a, b)
{
z = c;
}

dClass::dClass(double a, double b, double c)
: bClass()
{
x = a;
y = b;
z = c;
}

dClass::dClass(double a, double b)
: bClass()
{
x = a;
y = b;

}

dClass::dClass(double a, double c)
{
x = a;
z = c;
}

a.

static

b.

private

c.

protected

d.

public

Explanation / Answer

1.

class dClass: bClass
{
//class members list
};

The class dClass is derived from the class bClass using the private type of inheritance.

Here we can directly extend the class.

2.

bClass is a class. Which of the following statements correctly derives the class dClass from bClass

Choose option b.

class dClass: private bClass
{
//classMembersList
};

3.

Encapsulation is the ability to combine data, and operations on that data, in a single unit.

Explanation :

It is the process of binding of methods and members is referres as the encapsulation.

4.

#include <iostream>

using namespace std;

class bClass
{
public:
void print() const;
bClass(int a = 0, int b = 0);
//Postcondition: x = a; y = b;

private:
int x;
int y;
};

class dClass: public bClass
{
public:
void print() const;
dClass(int a = 0, int b = 0, int c = 0);
//Postcondition: x = a; y = b; z = c;

private:
int z;
};

int main()
{
bClass bObject(2, 3);          // It contain the value 2, 3
dClass dObject(3, 5, 8);      // It contain the value 3,5,8

bObject.print();
cout << endl;
dObject.print();
cout << endl;

return 0 ;
}

void bClass::print() const
{
cout << x << " " << y << endl;
}

bClass::bClass(int a, int b)
{
x = a;
y = b;
}

void dClass::print() const
{
bClass:print();
cout << " " << z << endl;
}

dClass::dClass(int a, int b, int c)
: bClass(a, b)
{
z = c;
}

Output :

2 3

3 5 8

Option b is correct.

5.

class bClass
{
public:
void set(double a, double b);
//Postcondition: x = a; y = b;
void print() const;

bClass();
//Postcondition: x = 0; y = 0;
bClass(double a, double b);
//Postcondition: x = a; y = b;

private:
double x;
double y;
};

class dClass: public bClass
{
public:
void set(double a, double b, double c);
//Postcondition: x = a; y = b; z = c;
void print() const;

dClass();
//Postcondition: x = 0; y = 0; z = 0 ;
dClass(double a, double b, double c);
//Postcondition: x = a; y = b; z = c;

private:
double z;
};

dClass constructor definitions is

dClass::dClass(double a, double b, double c)
: bClass(a, b)
{
z = c;
}

Option a is correct.

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