Saturday, 23 June 2012

write a c++ program to create a base class round shape(radious). define three different shapes as circle, sphere and cylinder(height) from roundshape.

/*write a c++ program to create a base class round shape(radious). define three different
shapes as circle, sphere and cylinder(height) from roundshape.
class roundshape
{
protected:flaot radious;
public:static flaot pi;
roundshape(float)//default argument
virtual float area()=0;
}
write a c++program to calculate area of circle,sphere and cylinder
*/
#include<iostream.h>
#include<conio.h>
class round
{
protected:float radious;
public:static float pi;
       round(float r=0)
       {
       cout<<"\nenter the radious:-";
       cin>>r;
       radious=r;
       }
       virtual float area()=0;
       };
class circle:public round
{
public:float circle;
       float area()
       {
       circle=pi*radious*radious;
       cout<<"\narea of circle:-"<<circle;
       return 0;
       }
       };
class sphere:public round
{
public:float sph;
       float area()
       {
       sph=4*pi*radious*radious;
       cout<<"\narea of sphere:-"<<sph;
       return 0;
       }
};
class cylinder:public round
{
public:float ac;
       float h;
public:cylinder(float height=0)
       {
       cout<<"\nenter height:-";
       cin>>height;
       h=height;
       }
       float area()
       {
       float tsac,csac,vc,acbc;
       tsac=2*pi*radious*(h+radious);
       csac=2*pi*radious*h;
       vc=pi*radious*radious*h;
       acbc=pi*radious*radious;
       ac=tsac+csac+vc+acbc;
       cout<<"area of cylinder is:-"<<ac;
       return 0;
       }
};
float round::pi=3.14;
int main()
{
int height;
clrscr();
cout<<"\n\t\tto calculate area of circle\n\n";
circle c;
c.area();
cout<<"\n\t\tto calculate area of sphere\n\n";
sphere s;
s.area();
cout<<"\n\t\tto calculate area of cylinder\n\n";
cylinder cl;
cl.area();
getch();
return 0;
}
/*

                to calculate area of circle                                   
                                                                              
                                                                              
enter the radious:-1                                                          
                                                                              
area of circle:-3.14                                                          
                to calculate area of sphere                                   
                                                                              
                                                                              
enter the radious:-1                                                          
                                                                              
area of sphere:-12.56                                                         
                to calculate area of cylinder                                 
                                                                              
                                                                              
enter the radious:-1                                                          
                                                                              
enter height:-1
area of cylinder is:-25.120001
*/

No comments: