Thursday, October 28, 2010

Abstract Class Solid

#include

#include

class solid

{

public:

virtual void volume()=0;

};

class cone : public solid

{

int a,r,h;

public:

void volume()

{

cout<<"\n enter radius and height";

cin>>r>>h;

a=(1*3.14*r*r*h)/3;

cout<<"\n volume of cone is :"<

}

};

class cylender : public solid

{

int a1,r1,h1;

public:

void volume()

{

cout<<"\n enter radius and height";

cin>>r1>>h1;

a1=3.14*r1*r1*h1;

cout<<"\n volume of cylender"<

}

};

class sphere : public solid

{

int a2,r2;

public:

void volume()

{

cout<<"\n enter radius";

cin>>r2;

a2=(4/3)*3.14*r2*r2;

cout<<"\n volume of sphere"<

}

};

void main()

{

clrscr();

solid *sptr;

cone c;

cylender cy;

sphere s;

sptr=&c;

sptr->volume();

sptr=&cy;

sptr->volume();

sptr=&s;

sptr->volume();

getch();

}

OUTPUT

Enter radius and height 5

6

Eolume of cone is :157

Enter radius and height 4

5

Volume of cylender251

Enter radius 5

Volume of sphere78

No comments:

Post a Comment