第3关:计算图像面积
#include <iostream>
using namespace std;
/********* Begin *********/
class Shape
{
public:
virtual void PrintArea()=0;//基类的声明
};
class Rectangle : public Shape
{
public:
float width;
float height;
void PrintArea()
{
cout<<"矩形面积 = "<<width*height<<endl;
}//矩形类的声明
Rectangle(float w,float h)
{
width=w;
height=h;
}
};
//矩形类的定义
class Circle : public Shape
{
public:
float radio;
void PrintArea()
{
cout<<"圆形面积 = "<<radio * radio * 3.14<<endl;
}//圆形类的声明
Circle(float r)
{
radio=r;
}
};
//圆形类的定义
/********* End *********/