#include<iostream>
using namespace std;
const double pi=3.14;
class Base{
protected:
double h;
public:
Base(double high)
{
h=high;
};
virtual double disp()=0;
};
class Cuboid:public Base{
protected:
double l;
double w;
public:
Cuboid(double high,double length,double width):Base(high)
{
l=length;w=width;
}
double disp()
{
double i;
i=h*l*w;
return i;
}
void show()
{
cout<<"高为"<<h<<"长为"<<l<<"宽为"<<w<<"的长方体体积为:";
}
};
class Cylinder:public Base{
protected:
double r;
public:
Cylinder(double high,double r1):Base(high)
{
r=r1;
}
double disp()
{
double j;
j=pi*r*r*h;
return j;
}
void show()
{
cout<<"高为"<<h<<"半径为"<<r<<"的圆柱体体积为:";
}
};
int main()
{
Base *p;
Cuboid c(5.3,4.5,7.3);
Cylinder y(4.2,3.7);
p=&c;
c.show();cout<<p->disp()<<endl;
p=&y;
y.show();cout<<p->disp()<<endl;
system("pause");
return 0;
}
6.13
最新推荐文章于 2024-06-16 13:04:38 发布