#include<iostream>
using namespace std;
const double b=3.14;
class base{
public:
base(double h1)
{ h=h1;}
virtual void disp()=0;
protected:
double h;
};
class cuboid:public base{
public:
cuboid(double h1,double w1,double k1):base(h1)
{w=w1;
k=k1;}
void disp()
{
cout<<"长方体的体积:"<<h*w*k<<endl;
}
protected:
double w;
double k;
};
class cylinder:public base{
public:
cylinder(double r1,double h1):base(h1)
{r=r1;}
void disp()
{cout<<"圆柱体的体积:"<<r*r*h*b<<endl;
}
protected:
double r;
};
int main ()
{
base *ptr;
cuboid c1(2.1,3.1,4.0);
cylinder l1(3.3,4.2);
ptr=&c1;
ptr->disp();
cout<<"*************************"<<endl;
ptr=&l1;
ptr->disp();
return 0;
}
c++ 6.14
最新推荐文章于 2024-06-14 20:25:18 发布