Triangle::Triangle() { //Initialise the vertices to have zero for all coordinates.
}
double Triangle::perimeter(Point point1, Point point2, Point point3) {
return (point1.distanceTo(point2) + point2.distanceTo(point3) + point3.distanceTo(point1));
}
double Triangle::area(Point point1, Point point2, Point point3) {
double a, b, c, S; //Variables to store parts of Hero's/Heron's formula.
a = point1.distanceTo(point2);
b = point2.distanceTo(point3);
c = point3.distanceTo(point1);
S = (a + b + c)/2;
return sqrt(S*(S-a)*(S-b)*(S-c)); //Hero's/Heron's formula of coordinate geometry to calculate area of a triangle.
}
void Triangle::print() { //print out the Triangle with the format "( (x1, y1), (x2, y2), (x3, y3) )"
How do I accomplish this??
}
When i test with cout << _point1.print(), there's an error:
[Error] no match for 'operator<<' in 'std::cout << ((Triangle*)this)->Triangle::_point1.Point::print()'
One more thing, don't use the underscore to prefix variables/functions, because some of these are preserved for internal use by many library headers. If you decide to use underscore, use x_ (and not _x).
One more thing, don't use the underscore to prefix variables/functions, because some of these are preserved for internal use by many library headers. If you decide to use underscore, use x_ (and not _x).
All of them are reserved inside the global namespace. As long as your usage is outside of that namespace, using a single underscore followed by a lower case letter (_x) is perfectly fine.