Answer to Question #205578 in C++ for Ali

Question #205578

Implement the following hierarchy.


· Make Shape, TwoDimensionalShape, and ThreeDimensionalShape as abstract class


· Add virtual functions of calculateArea() and perimeter() in TwoDimensionalShape.


· Implement the above functions in child classes Circle, Square , Triangle. Take help from Google to find the formulas.


· add virtual functions of calculateSurfaceArea() and calculateVolume() in ThreeDimensionalShape


Implement all functions in child classes Sphere, cube, and tetrahedron.


1
Expert's answer
2021-06-11T00:10:35-0400
#include <iostream>
using namespace std;
class Shape{
  };
class TwoDimensionalShape{
  virtual double calculateArea()=0; 
  virtual double perimeter()=0;
};
class ThreeDimensionalShape{
   
};
class Circle{
  int r;
  public:
    double calculateArea(){
      return (3.142*r*r);
    }
    double perimeter(){
      return (2*3.142*r);
    }
};
class Square{
  int s;
  public:
    double calculateArea(){
      return (s*s);
    }
    double perimeter(){
      return (4*s);
    }
};
class Triangle{
  double b,h,hy;
  public:
    double calculateArea(){
      return (0.5*b*h);
    }
    double perimeter(){
      return (b+h+hy);
    }
};
int main()
{
return 0;
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog