Using Polymorphism and inheritance
Write a C++ program that creates a base class calledMathOperations that includes two pieces of information as datamembers, namely: • num1 (type int) • num2 (type int) Programrequirements (MathOperations class): • Provide setter and gettermember functions for each data member. • Your class should have aconstructor with two parameters (one for each data member) and itmust use the setter member functions to initialize the two datamembers. • Provide a pure virtual member function by the nameoperation() that returns an integer. Program requirements (Additionclass): • Create a derived class called Addition that inheritspublicly from MathOperations. • Your class should have aconstructor that calls the base class constructor • Provide avirtual member function by the name operation that returns(num1+num2) Program requirements (Subtraction class): • Create aderived class called Subtraction that inherits publicly fromMathOperations. • Your class should have a constructor that callsthe base class constructor • Provide a virtual member function bythe name operation that returns (num1-num2) Write a main programthat demonstrates the polymorphism capabilities, by: – Creating anobject of type Addition with the numbers (10,5) – Creating anobject of type Subtraction with the numbers (10,5) – Create ONEpointer to MathOperations (it means MathOperation* data type) -Make the pointer point to the Addition object – Call the functionoperation() and print the result of the addition – Make the pointerpoint to the Subtraction object – Call the function operation() andprint the result of the subtraction The following is an example ofhow your program should run: Addition: (10 + 5) = 15 Subtraction:(10 – 5) = 5
Expert Answer
Answer to Using Polymorphism and inheritance Write a C++ program that creates a base class called MathOperations that includes two…