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

please answer these questions based on the code. Write the set accessor methods

ID: 3575319 • Letter: P

Question


please answer these questions based on the code.

Write the set accessor methods for the fields of class B.

Write out the overridden GetX () and GetY () methods for class C so that they return the x and y from class B.

Write a deep copy overload assignment operator for class A.

class C public B c: public B class B blic A class A blic int x, y co (cout "c" public: public int Getx B A() d (new int), s (0) Hx y 1: cout "B" int cetY fed 2; cout "A" co {cout "c" int Getx() {return x;1 A int Get fre turn y; (delete di cout "A virtual {cout "B"

Explanation / Answer

#include <iostream>
using namespace std;
class A
{
int *d, s;
public:
A(): d(new int), s(0)
{
*d = 2; cout<<"A";
}
~A()
{
delete d; cout<<"A";
}
};
class B   : public A
{
int x, y;
public:
B()
{
x = y = 1; cout<<"B";
}
int GetX() {return x;}
int GetY() {return y;}
//Write the set accessor methods for the fields of class B.
void SetX(int x)
{
this->x = x;
}
void SetY(int y)
{
this->y = y;
}
virtual ~B()
{
cout<<"B";
}
};
class C: public B
{
public:
C()
{
cout <<"C";
}
int GetX();
int GetY();
~C()
{
cout<<"C";
}
};
//Write out the overridden GetX () and GetY () methods for class C so that they return the x and y from class B.int C::GetX()
{
return B::GetX();
}
int C::GetY()
{
return B::GetY();
}