/*
*作者:lws
*完成时间:2014/6/12
*输入:长方体的长,宽,高
*输出:长方体的体积
*/
#include <iostream>
using namespace std;
class Rectangle //矩形类
{
public:
Rectangle():length(0),width(0){}
Rectangle(int l,int w):length(l),width(w){}
int getArea(); //求面积
private:
int length;
int width;
};
int Rectangle::getArea()
{
return length*width;
}
class Bulk:public Rectangle //立方体类
{
public:
Bulk():Rectangle(0,0),height(0){}
Bulk(int l,int w,int h):Rectangle(l,w),height(h){}
int getVolume();
private:
int height;
};
int Bulk::getVolume()
{//在派生类的各个成员函数不能访问基类的私有成员,所以用getArea()代替长*宽
return getArea()*height;
}
int main()
{
int x,y,z;
cin>>x>>y>>z;
Bulk b(x,y,z);
cout<<b.getVolume()<<endl;
return 0;
}
运行结果: