Answer to Question #209011 in C++ for Shema

Question #209011

Define the class point2D(x,y) for

the x, y coordinates. The class has x, y

and color as member variables and as

member function has setXY(x1,y1),

setColor(pColor), MoveRel(Dx,Dy),

getX(), getY(), getColor(pColor), Print(),

the constructers point2D(),

point2D(x1,y1,pColor), the destructor

-point2D(). The MoveRel(Dx, Dy)

function changed the x, y coordinates

by the amount of Dx, and Dy,

respectively (ex: x=x+Dx, y=Y+Dy).

Determine which function is accessor

and which one is mutator.


1
Expert's answer
2021-06-20T18:14:38-0400
#include <iostream>
#include <string>
using namespace std;
class point2D{
    float x, y;
    string color;
    public:
    point2D(float x1, float y1, string pColor): x(x1), y(y1), color(pColor){}
    void setXY(float x1, float y1){
        x = x1;
        y = y1;
    }
    void setColor(string pColor){
        color = pColor;
    }
    float getX(){
        return x;
    }
    float getY(){
        return y;
    }
    string getColor(){
        return color;
    }
    void MoveRel(float Dx, float Dy){
        x += Dx;
        y += Dy;
    }
    void Print(){
        cout<<"X: "<<x<<endl;
        cout<<"Y: "<<y<<endl;
        cout<<"Color: "<<color<<endl;
    }
    ~point2D(){}
};

accessors

getX()

getY()

getColor()


mutators

setXY(float x1, float y1)

setColor(string pColor)

MoveRel(float Dx, float Dy)


Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS