Professional Documents
Culture Documents
2. Consider the following class hierarchy, the arrows show the inheritance between classes, and X,
Y and Z show the types of inheritance, complete the table below by stating the members that
are public, protected, and private for class D, for different combination of inheritances
class yClass {
public:
void one();
void two(int, int);
yClass();
private:
int a, b;
};
yclass y;
xclass x;
class baseClass {
public:
void print() const;
baseClass(string s=“ “, int a=0);
protected:
int x;
private:
string str;
};
private:
int y;
};
int main(){
baseClass baseObject(“This is base class”, 2);
derivedClass derivedObject(“This is derived class”, 3, 7);
baseObject.print();
derivedObject.print();
return 0;
void baseClass::print() const {cout << str << “ “ << x << endl; }
{ y=b; }
5. Consider the following code, write the function setData() and print() of class one and
two.
class one {
public:
void print() const; // output the values of x and y.
protected:
void setData(int, int); // values for x and y
private:
int x, y;
};
---END---