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.
#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)
Comments
Leave a comment