面试题答案
一键面试#include <iostream>
class Shape {
private:
// 假设这里有一个表示面积计算相关的成员变量,比如半径(如果是圆形)
double radius;
public:
Shape(double r = 0) : radius(r) {}
double calculateArea() {
// 这里以圆形为例简单实现,实际根据需求修改
return 3.14 * radius * radius;
}
};
int main() {
Shape circle(5);
std::cout << "The area of the shape is: " << circle.calculateArea() << std::endl;
return 0;
}