· 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.
#include <iostream>
using namespace std;
class Shape{
};
class TwoDimensionalShape{
virtual double calculateArea()=0;
virtual double perimeter()=0;
};
class ThreeDimensionalShape{
};
//classes Circle, Square
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;
}
Comments
Leave a comment