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(); cout

Solution


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;
   }
};

Please answer Question1 only. Question I: Triangles, and Circles are Shapes, geometric objects which can have their perimeter and area calculated. Implement a S

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site