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

Write the function setXY in dClass which sets the value of x to init_x and the v

ID: 3556595 • Letter: W

Question

Write the function setXY in dClass which sets the value of x to init_x and the value of y to init_y using bClass and dClass provided. Will the function you wrote in the previous question work if the data member x (in bClass) if changed to private and why?

// Class: bClass (base class)

class bClass

{

          public:

                   bClass();

void setX(int init_x);

                   void print() const;

          protected:

                   int x;

};

// Class: dClass (derived class)

class dClass : public bClass

{

          public:

                   dClass();

                   void setXY(int init_x, int init_y);

                   void print() const;

          private:

                   int y;

};

Explanation / Answer

void setXY(int init_x, int init_y){

setX(init_x);

y = init_y;

}

If x is private then we cannot set value of x since only public and protected member are inherited, private are not.