Attached Files Point_header.txt (0.321 KB) Point_implementation.txt (0.448 KB) T
ID: 3622161 • Letter: A
Question
Attached Files Point_header.txt (0.321 KB) Point_implementation.txt (0.448 KB) The text to create the header (Point.h) and implementation (Point.cpp) files for the class that represents a point in 2D space can be found in the attached documents. Using this class, build another class that represents a triangle in 2D space. Private attributes of the triangle should include the coordinates of the three vertices (each of which is a type Point), the length of the three sides, and the angles (in degrees) opposite each side.
The methods should include the following:
- functions to create default triangles (vertices at [0,0], [1,0] and [0,1]) and to allow initial coordinates of the vertices to be entered
- functions to change the vertices (mutator methods)
- functions to get the coordinates of the vertices (accessor methods)
- functions to get the lengths of the sides and the three angles (accessor methods)
- a function to get the area of the triangle (accessor method).
Remember that whenever the coordinates of a vertex are changed, the lengths of the sides and the values of the angles must be updated.
Point_header.txt is :.................................................................................................
class Point
{
// Declaration of attributes
private:
double xCoord, yCoord;
// Function prototypes
public:
double getX() const; // Returns x value
double getY() const; // Returns y value
void setX(double newX);
void setY(double newY);
// Distance between two points
double Point::distance(const Point rhs) const;
};
and Point_implementation.txt is :....................................................................................
#include "Point.h"
#include
using namespace std;
double Point::getX() const
{
return xCoord;
}
double Point::getY() const
{
return yCoord;
}
void Point::setX(double newX)
{
xCoord = newX;
}
void Point::setY(double newY)
{
yCoord = newY;
}
double Point::distance(const Point rhs) const
{
double t1, t2, d;
t1 = rhs.xCoord - xCoord; // (x2 - x1)
t2 = rhs.yCoord - yCoord; // (y2 - y1)
d = sqrt(pow(t1,2) + pow(t2,2));
return d;
}