6.11 The class of points in a plane 175
6.11 The class of points in a plane
As a further example, we consider the class of points in thexyplane. The loca-
tion of each point is determined by the doublet of real number (x, y) specifying
the Cartesian coordinates. The class definition is:
class point
{
public:
point();
point(double valuex, double valuey);
double getx() const;
double gety() const;
void print() const;
void move(double dx, double dy);
private:
double x;
double y;
};
The implementation of the default constructor is:
point::point()
{
x = 0.0; y = 0.0;
}
The implementation of the parametered constructor is:
point::point(double a, double b)
{
x=a;y=b;
}
The implementation of the non-intrusiveprintfunction is:
void point::print() const
{
cout<<x<<""<<y<<endl;
}
The implementation of the non-intrusivegetxfunction is:
double point::getx() const
{
return x;
}