#include <iostream>
// Base class
class PowerCalculator {
public:
    virtual double calculatePower(double base, int exponent) {
        return 1.0; 
        // Default implementation for the base class
    }
};// Derived class inheriting from PowerCalculator
class PowerExponentiator : public PowerCalculator {
public:
    double calculatePower(double base, int exponent) override {
        double result = 1.0;
        for (int i = 0; i < exponent; ++i) {
            result *= base; }
        return result; }
};
int main() {
    double base;
    int exponent;
  // Get user input for base and exponent
    std::cout << "Enter the base: ";
    std::cin >> base;
    std::cout << "Enter the exponent: ";
    std::cin >> exponent;
 // Create an instance of the derived class
    PowerExponentiator powerExponentiator;

    // Calculate and display the result
    std::cout << base << " raised to the power " << exponent << " is: "
              << powerExponentiator.calculatePower(base, exponent) << 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: