Answered step by step
Verified Expert Solution
Question
1 Approved Answer
[ Program Development ] Implement a class MyCalc, whose object can be used to perform calculations including addition, subtraction, multiplication, and division. The class contains
Program Development
Implement a class MyCalc, whose object can be used to perform calculations including addition, subtraction, multiplication, and division. The class contains one private member variables as following:
val: an int variable, storing the value of an integer number
Complete the class definition of MyCalc do NOT change any identifiers given above and do NOT add any extra members and then implement the following public member functions:
MyCalc : default constructor to initialize val
MyCalc int v: parameterized constructor to initialize valv
Further overload the calculation operators as following:
operator: take another object of class MyCalc as input to display the result of adding val of new object to val of the current object return type: void
operator: take another object of class MyCalc as input to display the result of subtracting val of new object from val of the current object return type: void
ope rator: take another object of class MyCalc as input to display the result of multiplying val of new object to val of the current object return type: void
operator: take another object of class MyCalc as input to display the result of dividing val of new object from val of the current object return type: void
operator: print the value of val. The overloaded operator should support chain function calls.
Implement the first four operators as member functions and the last operator as a common function
Scanned with
Implement the first four operators as member functions and
Time left ::
Hide
common function
When overloading operator if the divisor is an error message should be printed and we assign the result of the division with value as shown in examples below
We only consider integer calculations. For example, the result of division should be
Read two integers to create two objects of MyCalc. Use to display the values of these two objects and then print the results of the four calculations, ie addition, subtraction, multiplication, and division.ExampleInputs are underlined:Scanned withExampleInputs are underlined:Time left ::
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started