In this lab you will create classes needed to represent a tr
In this lab you will create classes needed to represent a triangle w/ points in space. Your tasks is to write the code to implement both the PointClass and TriangleClass described below. Then in main() run a sequence of tests without reading input or writing output. Then, only if all tests pass, write \"ALL TESTS PASSED!\" with endline.
PointClass:
class PointClass { public: void SetCoords(int x, int y); // Sets the value for member variables xCoord and yCoord double GetDistance(PointClass ptB); // Returns the distance to ptB. void Print(); // Print point as \"(xCoord, yCoord)\" with endline int GetXcoord(); // returns xCoord int GetYcoord(); // returns yCoord PointClass operator+(PointClass B); // Overloads \'+\' operator and adds two points: // (x1,y1)+(x2,y2) is (x1+x2, y1+y2) private: int xCoord; int yCoord; };
TriangleClass:
class TriangleClass { public: void SetPoints(PointClass A, PointClass B, PointClass C); double GetArea(); void Print(); private: PointClass A; PointClass B; PointClass C; };
Solution
#include<bits/stdc++.h>
using namespace std;
class PointClass
{
private:
public:
double xCoord , yCoord ;
void SetCoords(int x, int y)
{
xCoord =x;
yCoord =y;
}
double GetDistance(PointClass ptB)
{
return sqrt( (ptB.xCoord-this->xCoord)*(ptB.xCoord-this->xCoord)+(ptB.yCoord-this->yCoord)*(ptB.yCoord-this->yCoord));
}
PointClass operator+(PointClass B)
{
PointClass temp;
temp.xCoord=this->xCoord+B.xCoord;
temp.yCoord=this->yCoord+B.yCoord;
return temp;
}
double GetXcoord()
{
return xCoord;
}
double GetYcoord()
{
return yCoord;
}
void Print()
{
cout<<\"X cordinate \"<<GetXcoord()<<endl;
cout<<\"Y cordinate \"<<GetYcoord()<<endl;
}
};
class TriangleClass
{
private: PointClass A; PointClass B; PointClass C;
public:
void SetPoints(PointClass A, PointClass B, PointClass C)
{
this->A=A;
this->B=B;
this->C=C;
}
double GetArea()
{
double area= 0.5*abs( A.xCoord*(B.yCoord-C.yCoord)+ B.xCoord*(C.yCoord-A.yCoord) + C.xCoord*(A.yCoord-B.yCoord));
return area;
}
};

