编写程序,声明一个基类Shape,再派生出Rectangle类和Circle类,二者都有GetArea()函数;计算对象的面积。使用程序Rectangle类创建一个派生类Square。
#include <iostream>
using namespace std;
class Shape//基类
{
private:
double R;
double l;
double w;
double s;//私有数据,分别为半径,长宽,面积
public:
Shape(double a,double b,double c,double d)
{
R=a;
l=b;
w=c;
s=d;
}//构造函数初始化
Shape(){
};//构造函数
};
class Rectangle:public Shape//长方形类
{
public:
Rectangle() {
};//构造函数
void getArea(double a,double b