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

3. Consider the following statements: class yClass { public: void one(); void tw

ID: 3905071 • Letter: 3

Question

3. Consider the following statements:

class yClass

{

public:

void one();

void two(int, int);

yClass();

private:

int a;

int b;

};

class xClass: public yClass

{

public:

void one();

xClass();

private:

int z;

};

yClass y;

xClass x;

a. The private members of yClass are public members of xClass. True or False?

b. Mark the following statements as valid or invalid. If a statement is invalid, explain why.

i. void yClass::one()

{

cout << a + b << endl;

}

ii. y.a = 15;

x.b = 30;

iii. void xClass::one()

{

a = 10;

b = 15;

z = 30;

cout << a + b + z << endl;

}

iv. cout << y.a << " " << y.b << " " << x.z << endl;

Explanation / Answer

a) False b) i) valid ii) invalid variable 'a' is not public. so we can not access it using y.a; variable 'b' is not public. so we can not access it using x.b; iii) invalid variables a, b are not accessible in xClass iv) invalid y.a, y.b and x.z are inaccessible

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