Create an abstract class MathSymbol may provide a pure virtual function doOperation(), and create two more classes Plus and Minus implement doOperation() to provide concrete implementations of addition in Plus class and subtraction in Minus class.
#include <iostream>
class MathSymbol {
public:
virtual float doOperation(float x, float y) = 0;
};
class Plus: public MathSymbol {
float doOperation(float x, float y) {
return (x + y);
}
};
class Minus: public MathSymbol {
float doOperation(float x, float y) {
return (x - y);
}
};
Comments
Leave a comment