#include

class Point { public: Point(float a, float b) { x = a; y = b; }

private: float x, y; };

class Circle { public: Circle(float r) { radius = r; }

float getArea() {
    return 3.14159 * radius * radius;
}

private: Point point{0, 0}; // 圆心的初始坐标为 (0, 0) float radius; // 半径 };

int main(int argc, char* argv[]) { Circle circle(10); std::cout << circle.getArea() << std::endl; return 0; }

请注意,这里假设您已经包含了正确的头文件,如 <iostream>。这样您就可以使用 coutendl 来进行输出操作了。同时,我在计算圆的面积时使用了近似值 3.14159 作为圆周率。如果需要更准确的值,您可以使用更多的小数位数或使用预定义的常量 M_PI(在 cmath 头文件中定义)作为圆周率的近似值。


原文地址: https://www.cveoy.top/t/topic/bx5P 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录