#include <iostream>
// Base class
class Shape {
public:
    virtual double calculateVolume() const = 0;};

// Derived class for Cube
class Cube : public Shape {
private:
    double side;
public:
    Cube(double _side) : side(_side) {}
    double calculateVolume() const override {
        return side * side * side;    }
};

// Derived class for Cuboid
class Cuboid : public Shape {
private:
    double length, width, height;

public:
    Cuboid(double _length, double _width, double _height)
        : length(_length), width(_width), height(_height) {}

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

// Derived class for Cylinder
class Cylinder : public Shape {
private:
    double radius, height;

public:
    Cylinder(double _radius, double _height) : radius(_radius), height(_height) {}

    double calculateVolume() const override {
        return 3.141592653589793 * radius * radius * height;  }
};
int main() {
    Cube myCube(3.0);
    Cuboid myCuboid(2.0, 4.0, 5.0);
    Cylinder myCylinder(2.5, 6.0);

    std::cout << "Volume of Cube: " << myCube.calculateVolume() << std::endl;
    std::cout << "Volume of Cuboid: " << myCuboid.calculateVolume() << std::endl;
    std::cout << "Volume of Cylinder: " << myCylinder.calculateVolume() << std::endl;

    return 0;
}

Embed on website

To embed this project on your website, copy the following code and paste it into your website's HTML: