rectangle:length=3, width=4, area=12
程序:
#include
using namespace std;
#define PI 3.14
class shape{
protected:
double x,y;
public:
shape(){}
shape(double _x,double _y)
{
x = _x;
y = _y;
}
double getarea()
{
return 0.0;
}
};
class circle:public shape{
public:
using shape::x;
using shape::y;
circle(double r);
double getarea();
double getradius();
};
circle::circle(double r)
{
x = r;
}
double circle::getarea()
{
return PI*x*x;
}
double circle::getradius()
{
return x;
}
class Rectangle:public shape{
public:
using shape::x;
using shape::y;
Rectangle(double l ,double w)
{
x = l;
y = w;
}
double getarea()
{
return x*y;
}
double getlength()
{
return x;
}
double getwidth()
{
return y;
}
};
int main()
{
circle c1(1);
c1.getradius();
c1.getarea();
cout <<"circle: "<< "r = "<