第38798题 单选题
关于下面代码,说法错误的是( )。 {}
class Shape {
protected:
    string name;

public:
    Shape(const string& n) : name(n) {}

    virtual double area() const {
        return 0.0;
    }
};

class Circle : public Shape {
private:
    double radius; // 半径

public:
    Circle(const string& n, double r) : Shape(n), radius(r) {}

    double area() const override {
        return 3.14159 * radius * radius;
    }
};

class Rectangle : public Shape {
private:
    double width; // 宽度
    double height; // 高度

public:
    Rectangle(const string& n, double w, double h) : Shape(n), width(w), height(h)

    double area() const override {
        return width * height;
    }
};

int main() {
    Circle circle("MyCircle", 5.0);
    Rectangle rectangle("MyRectangle", 4.0, 6.0);

    Shape* shapePtr = &circle;
    cout << "Area: " << shapePtr->area() << endl;

    shapePtr = &rectangle;
    cout << "Area: " << shapePtr->area() << endl;

    return 0;
}
{{ option.label }}
子题{{ index + 1 }} {{ child.type_label }}
{{ option.label }}
✓ 正确 ◐ 部分正确 ✗ 错误
程序运行统计
暂无判题统计
知识点:
提交{{ questionInfo.stats ? questionInfo.stats.submit_count : 0 }}次 正确率{{ statsAccuracy }}%
答案解析