All submissions
/******************************************************************************

Welcome to GDB Online.
  GDB online is an online compiler and debugger tool for C, C++, Python, PHP, Ruby, 
  C#, OCaml, VB, Perl, Swift, Prolog, Javascript, Pascal, COBOL, HTML, CSS, JS
  Code, Compile, Run and Debug online from anywhere in world.

*******************************************************************************/
#include<iostream>
#include<string>
using namespace std;

class Operation
{
    public:
        virtual int apply (int c) const =0;
};

class SquareOp: public Operation
{
    public:
        int apply(int x) const override
        {
            return x*x;
        }
};

class CubeOp: public Operation
{
    public:
        int apply (int x) const override
        {
            return x*x*x;
        }

};

int main()
{
    int n;
    string opName;

    cin>>n>>opName;

    Operation *op =nullptr;

    if (opName == "sqaure")
    {
        op = new SquareOp;
    }
    else if(opName == "cube")
    {
        op = new CubeOp;
    }

    if(op)
    {
        cout<<op->apply(n);
        delete op;

    }
}
Loading...

Input

5 square

Expected Output

25