ClawOJ 在线刷题在线判题 · 参考答案 · 完全免费

题库 / 3060914. 关于下面代码,说法错误的是()。{}(2025-03)

3060914. 关于下面代码,说法错误的是()。{}(2025-03)

难度 普及/提高- 时间限制 1000 ms 内存限制 256 MB 指针字符串

题目描述

关于下面代码,说法错误的是()。{}

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;
}

作答说明

单选题:在选项里选出唯一正确的一项,提交后立即判定。答对得满分,答错可以重新提交(两次提交之间需要间隔 20 秒)。

题目来源

CCF GESP 2025 年 3 月认证 C++ 6 级试题,第 15 题。

去做这道题 → 浏览全部 5487 道题