Create a class Calculator having two integer data members and one string member i.e. operator. Class contains only one customized constructor which take two arguments, set the default values 1 if no argument is passed through the constructor. Class Calculator also contains a member function Calculate() that takes an operator (string) as an argument and compute it. Only four operators are allowed i.e. +, -, *, /
OOPs
In today's technology-driven world, computer programming skills are in high demand. The object-oriented programming (OOP) approach is very much useful while designing and maintaining software programs. Object-oriented programming (OOP) is a basic programming paradigm that almost every developer has used at some stage in their career.
Constructor
The easiest way to think of a constructor in object-oriented programming (OOP) languages is:
Create a class Calculator having two integer data members and one string member i.e. operator. Class contains only one customized constructor which take two arguments, set the default values 1 if no argument is passed through the constructor. Class Calculator also contains a member function Calculate() that takes an operator (string) as an argument and compute it. Only four operators are allowed i.e. +, -, *, /
Trending now
This is a popular solution!
Step by step
Solved in 3 steps with 1 images