Answer the question
In order to leave comments, you need to log in
How to calculate Perimeter and Area of a triangle in Class?
class Point {
protected:
double x, y;
public:
Point(double x = 0, double y = 0)
{
this->x = x;
this->y = y;
}
~Point() {}
double getX() {
return x;
}
double getY() {
return y;
}
void setX(double x) {
this->x = x;
}
void setY(double y) {
this->y = y;
}
};
class Line: public Point {
private:
Point a;
public:
Line(Point a,Point b): Point(b) {
this->a = a;
}
~Line() {}
Point getA() {
return a;
}
void setA(Point a) {
this->a = a;
}
double lineLength() {
double L = sqrt(pow(a.getX() - getX(), 2) + pow(a.getY() - getY(), 2));
return L;
}
};
class Triangle: public Point {
private:
Point a, b;
public:
Triangle(Point a, Point b): Point(c)
{
this->a = a;
this->b = b;
}
~Triangle() {}
Point getA() {
return a;
}
Point getB() {
return b;
}
void setA(Point a) {
this->a = a;
}
void setB(Point b) {
this->b = b;
}
double Area() {
}
double Perimeter() {
}
};
Answer the question
In order to leave comments, you need to log in
Inheritance implies an "is" relationship. Is the line a point? No. Is a triangle a point? No. So why the hell are you inheriting them like that? A triangle is three points. And not any, but three different points that do not lie on one straight line. The triangle must satisfy these invariants.
Area and perimeter are calculated from three points.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question