#include<iostream.h>
using namespace std;
const float PI = 3.14;
class shape
{
protected :
float radius;
float height;
float side;
public :
virtual float volume () = 0; || pure virtual function
void getdata (float r, float h)
{
radius = r;
height = h;
}
void getdata1 (side)
{
side = S;
}
};
class Cone : public shape
{
public :
float volume ()
{
return (1/3*PI*radius^2*height);
}
};
class Cylinder : public shape
{
public :
float volume ()
{
return(PI*radius^2*height);
}
};
class Cube : public shape
{
public :
float volume ()
{
return (side*side*side);
}
};
int main (void)
{
Cone con;
Cylinder cyl;
Cube cub;
con.getdata (5,9)
cout << "volume of cone :"<< con. volume () << "\n";
cyl. getdata (4,5)
cout << "volume of cylinder :"<<cyl. volume ()<<"\n";
cub.getdatal (3)
cout << "volume of cube :"<<cub.volume () <<"\n";
return 0;
}
प्रोग्राम का आउटपुट होगा
Volume of cone=235.5
Volume of cylinder =251.2
Volume of cube = 27