oj-1-長方形継承矩形
1708 ワード
01./*
02.* :
03.* Copyright (c) 2011,
04.* All rights reserved.
05.* :test.cpp
06.* :
<pre class="cpp" name="code">07.* :2014 6 10
08.* :v1.0
09.* :
10.* :
11.* :
12.* :
13.* :
14.* :
15.*/
<pre class="cpp" name="code">#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; // , 、
};
// begin end
//*********** begin *************
//Rectangle
Rectangle::Rectangle():length(0),width(0){}
Rectangle::Rectangle(int l,int w):length(l),width(w) {}
int Rectangle::getArea()
{
return length*width;
}
//Bulk
Bulk::Bulk():Rectangle(),height(0){}
Bulk::Bulk(int l, int w,int h):Rectangle(l,w),height(h){}
int Bulk::getVolume()
{
int s;
s=getArea();
return s*height;
};
//*********** end ***************
int main()
{
int x,y,z;
cin>>x>>y>>z;
Bulk b(x,y,z);
cout<<b.getVolume()<<endl;
return 0;
}