721
edits
Line 83: | Line 83: | ||
Extend our Point2D class to have the following functions: | Extend our Point2D class to have the following functions: | ||
<code> | <code> | ||
Point2D operator+(Point2D& p2); | Point2D operator+(Point2D& p2); | ||
</code> | </code> | ||
This function should add up two points and return a new Point2D, which is the sum of the two points. | This function should add up two points and return a new Point2D, which is the sum of the two points. | ||
If you implement this function you can then simply write: Point2D sum = p0 + p1; (where p0 and p1 are of the class Point2D) | If you implement this function you can then simply write: Point2D sum = p0 + p1; (where p0 and p1 are of the class Point2D) | ||
<code> | <code> | ||
Point2D operator/(float f); | Point2D operator/(float f); | ||
</code> | </code> | ||
This function should divide a point by the number f and return a new Point2D which is the divided point. | This function should divide a point by the number f and return a new Point2D which is the divided point. | ||
If you implement this function you can then simply write: | If you implement this function you can then simply write: | ||
<code> | <code> | ||
Point2D div = p0 / 5; | Point2D div = p0 / 5; | ||
</code>(where p0 is of class Point2D) | </code>(where p0 is of class Point2D) | ||
Write an algorithm that calculates the centroid of the given points | Write an algorithm that calculates the centroid of the given points |