class Box {
public:
Box(double l, double w, double h) : length(l), width(w), height(h) {}
double area() const {
return 2 * (length * width + width * height + height * length);
}
double volume() const {
return length * width * height;
}
private:
double length, width, height;
};
class IAnimal {
public:
virtual void shout() const = 0; // 纯虚函数
virtual ~IAnimal() {} // 虚析构函数
};
class Cat : public IAnimal {
public:
void shout() const override {
cout << "喵喵喵" << endl;
}
};
class Dog : public IAnimal {
public:
void shout() const override {
cout << "汪汪汪" << endl;
}
};