Create a class Triangle. Include overloaded functions for calculating area. Overload
assignment operator and equality operator.
class Triangle
{
private:
float side1, side2, side3;
public:
Triangle(float firstSide, float secondSide, float thirdSide)
{
side1 = firstSide;
side2 = secondSide;
side3 = thirdSide;
}
float GetFirstSide()
{
return side1;
}
float GetSecondSide()
{
return side2;
}
float GetThirdSide()
{
return side3;
}
float CalculateHalfPerimeter()
{
return (GetFirstSide() + GetSecondSide() + GetThirdSide())/2;
}
float CalculateArea()
{
float halfPerimeter = CalculateHalfPerimeter();
return sqrt(halfPerimeter * (halfPerimeter - GetFirstSide()) * (halfPerimeter - GetSecondSide())
* (halfPerimeter - GetThirdSide()));
}
Triangle& operator= (const Triangle &triangle)
{
this->side1 = triangle.side1;
this->side2 = triangle.side2;
this->side3 = triangle.side3;
return *this;
}
bool operator== (const Triangle &triangle)
{
return this->side1 == triangle.side1 && this->side2 == triangle.side2 && this->side3 == triangle.side3;
}
};
Comments
Leave a comment