Question #58468

class point {
private:
string mytype;
int x;
public:
point()
{
int getx()const{cout<<"point ::getx()const";return 10;}//statement A
int getx() {cout<<"point ::getx()"; return x;}//statement B
virtual string isa()const{return "point";} //statement c
};
class circle:protected point
{
public:
circle():point ()
virtual string isa() const{return "circle";} //statement D
void setr(int y=200){r=y;};
protected:
int getr()const {cout<<"\n circle::getr()"; return r;}
private:
int r;
};
answer the following
a)what is the relationships between "statement C"and "statement D"?
b)what is the relationships between "statement A"and "statement B"?
c)what is the relationships between point and circle classes?
d)what is the relationships between point and mytype classes?

Expert's answer

Answer on Question #58468 - Programming & Computer Science / C++

Question

class point {
private:
    string mytype;
    int x;
public:
    point() { }
    int getX() const { cout << "point :: getX() const"; return 10; }
    int getX() { cout << "point :: getX() "; return x; }
    virtual string isa() const { return "point"; }
};
class circle : protected point {
public:
    circle() : point() {
        virtual string isa() const { return "circle"; }
        void setr(int y = 200) { r = y; }
    protected:
        int getr() const { cout << "\n circle :: getr()"; return r; }
    private:
        int r;
    };
answer the following
a)what is the relationships between "statement C" and "statement D"?
b)what is the relationships between "statement A" and "statement B"?
c)what is the relationships between point and circle classes?
d)what is the relationships between point and mytype classes?

Solution

a) D method in class circle will override C method from base class;

b) A will be called on "const" objects, B will be called on objects without const modifier;

c) Point is base class; Circle is derived class of point;

d) No relationships;

http://www.AssignmentExpert.com/

LATEST TUTORIALS
APPROVED BY CLIENTS