OJ-練習-長方形から継承
1428 ワード
/*
* Copyright (c) 2013,
* All rights reserved.
* :
* :2014 5 20
* :v1.0
* :
* :
* :
* :
* Rectangle , Bulk , (1)-(6) ,
* 、 、 。
*/
#include <iostream>
using namespace std;
class Rectangle //
{
private:
int length; //
int width;
public:
Rectangle();
Rectangle(int l,int w); // ,l、w
int getArea(); //
};
class Bulk: public Rectangle //
{
public:
Bulk(); //
Bulk(int l, int w,int h); //
int getVolume();
private:
int height; // , 、
};
//Rectangle
Rectangle::Rectangle():length(0),width(0){}
Rectangle::Rectangle(int l,int w):length(l),width(w){}
int Rectangle::getArea()
{
int s;
s=length*width;
return s;
}
//Bulk
Bulk::Bulk():Rectangle(){}
Bulk::Bulk(int l, int w,int h):Rectangle(l,w),height(h){}
int Bulk::getVolume()
{
int v;
v=height*getArea();
return v;
};
int main()
{
int x,y,z;
cin>>x>>y>>z;
Bulk b(x,y,z);
cout<<b.getVolume()<<endl;
return 0;
}
実行結果: