c++ Add a new data member, string color to your Point2D class below and a new ge
ID: 3842533 • Letter: C
Question
c++
Add a new data member, string color to your Point2D class below and a new getter and setter function for color. Create a Point2D object and set its color. Then create a Point3D object and try to set its color. Is the setColor behavior available for a Point3D class? Why or why not?
y = 0;
}
void printLocation() {
cout << "Point at (" << x << ", " << y << ")" << endl;
}
};
int main()
{
Point2D p1;
p1.setX(3); p1.setY(2);
p1.printLocation();
p1.moveHorizontally(5);
p1.printLocation();
p1.moveVertically(5);
p1.printLocation();
return 0;
}
Explanation / Answer
class Point2D
{
//add this code to your Point2D class
private :
string color;
public :
void setter(string c)//method to set the variable color..
{
color =c;
}
string getter()//method to get the value of variable color....
{
return color;
}
};
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.