Write a program that declares two classes. The parent class is called Simple that has two data members’ num1 and num2 to store two numbers. It also has four member functions. · The add() function adds two numbers and displays the result. · The sub() function subtracts two numbers and displays the result. · The mul() function multiplies two numbers and displays the result. The div() function divides two numbers and displays the result. The child class is called Complex that overrides all four functions. Each function in the child class checks the value of data members. It calls the corresponding member function in the parent class if the values are greater than 0. Otherwiseit displays error message.
Write a program that declares two classes. The parent class is called Simple that has two data members’ num1 and num2 to store two numbers. It also has four member functions.
·
The add() function adds two numbers and
displays the result.
·
The sub() function subtracts two numbers
and displays the result.
·
The mul() function multiplies two
numbers and displays the result.
The div() function divides two numbers
and displays the result. The child class is called Complex that overrides all four functions. Each function in the child class checks the value of data members. It calls the corresponding member function in the parent class if the values are greater than 0. Otherwiseit displays error message.
Step by step
Solved in 3 steps with 4 images