AreaCacul 类就是你的Shape抽象类,主控函数最下方 类中现在计算的是矩形和三角形两个继承类的面积。你参考改下!
class Areaclass{
public:
Areaclass(double x = 0, double y = 0): height(x), width(y) {}
protected:
double height, width;
};
class AreaCacul : public Areaclass
{
public:
AreaCacul(double x, double y):Areaclass(x,y){}
virtual double Area()=0;
};
class Box : public AreaCacul
{
public:
Box(double x,double y):AreaCacul(x,y){};
virtual double Area()
{
return height*width;
}
};
class Isosceles : public AreaCacul
{
public:
Isosceles(double x,double y):AreaCacul(x,y){};
virtual double Area()
{
return (height*width)/2;
}
};
#include
#include "test_class.h"
using namespace std;
int main(int argc, char *argv[])
{
AreaCacul *temp[] = {new Box(10,10),new Isosceles(10,10)};
cout<
return 0;
}