39. 定义一个抽象类 Shape 用以计算面积,从中派生出计算长方形、梯形、圆形 面积的派生类。程序中通过基类指针来调用派生类中的虚函数,计算不同形状的 面积。
#include<iostream>
#define pi 3.14
using namespace std;
class Shape
{
public:
virtual float getArea() const = 0;
};
class rectangle: public Shape //长方形
{
private:
float length;
float width;
public:
rectangle(float L,float W);
float getArea() const override;
};
rectangle::rectangle(float L,float W)

最低0.47元/天 解锁文章
1492





