176 Introduction to C++ Programming and Graphics
The implementation of the non-intrusivegetyfunction is:
double point::gety() const
{
return y;
}
The implementation of the mutatormovefunction is:
void point::move(double dx, double dy)
{
x = x+dx;
y = y+dy;
}
The main function is allowed to make any of the following calls:
- Define the default pointA, shift it, and print the original and new coor-
dinates:
point A = point();
A.print();
A.move(-0.2, 0.4);
A.print();
- Define point B, shift it, and print the original and new coordinates:
point B = point(1, 2);
B.print();
B.move(0.3, 0.4);
B.print();
An alternative to the first statement is:
point B(1, 2);
- Print the coordinates of point (10, 15):
point(10, 15).print();
- Print the coordinates of the default point:
point().print();
- Setaequal to thexcoordinate of pointA:
doublea=A.getx();