Please answer Question1 only Question I Triangles and Circle
Please answer Question1 only.
Question I: Triangles, and Circles are Shapes, geometric objects which can have their perimeter and area calculated. Implement a Shape abstract class, which can be used in the following manner: void describeShape (Shape &s;) double areas.getArea ); string type = s.getType(); double perim = s.get Perimeter(); coutSolution
class Shape{
public:
string type;
virtual double getArea() = 0;
virtual string getType() = 0;
virtual double getPerimeter() = 0;
};
class Triangle: public Shape{
public:
double a, b, c;
Triangle(){
type = \"Triangle\";
}
double getArea(){
double s = (a + b + c) / 2;
return sqrt(s * (s - a) * (s - b) * (s - c));
}
double getPerimeter(){
return (a + b + c);
}
};
class Circle: public Shape{
public:
double radius;
Circle(){
type = \"Circle\";
}
double getArea(){
return 3.14 * radius * radius;
}
double getPerimeter(){
return 2 * 3.14 * radius;
}
};
