Answer to Question #346534 in C++ for Anonymous

Question #346534

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.


1
Expert's answer
2022-05-31T10:03:59-0400
#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);
    }
};

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS