#include
using namespace std;
//基类
class shape
{
public:
void setWidth(int w)
{
width=w;
}
void setHeight(int h)
{
height=h;
}
protected:
int width;
int height;
};
//派生类
class Rectangle:public shape
{
public:
int getArea()
{
return(width*height);
}
};
int main()
{
Rectangle Rect;
Rect.setWidth(2);
Rect.setHeight(10);
//输出对象面积
cout<<“Total Area=”<<Rect.getArea()<<endl;
return 0;
}
程序运行结果如下: