I am writing a project to calculate the area and volume of 2d and 3d shapes. I have a class hierarchy with my abstract base class called 'shape'. I want to make a separate class to calculate a prism of a specified depth from any 2d shape, yet am unsure how to do this.
Any help will be greatly appreciated.
This example is for a circle, yet I want to be able to do this for all 2d shapes.
(Relevant code)
header
template <class prism> class prism
{
private:
double depth;
public:
prism(){depth=0;}//default constructor
prism(double depth1, shape* sha): shape(area){depth=depth 2; area=sha.getarea();}
};
then in main
if (choice=='c')
{
double depth(0.);
a.push_back(new circle());
vector<shape*>::const_iterator it;
it = a.begin();
(*it)->info();
cout<<"Enter the depth for a prism"<<endl;
cin>>depth;
circle c(1);
prism <shape*> b(depth, c);
delete *it;
a.pop_back();
}