Answered step by step
Verified Expert Solution
Link Copied!

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 =0
MyCalc (int v): parameterized constructor to initialize val=v
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 1:57:05
Hide
common function
When overloading operator /, if the divisor is 0, an error message should be printed and we assign the result of the division with value 0, as shown in examples below
We only consider integer calculations. For example, the result of division 10/3 should be 3
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, i.e., addition, subtraction, multiplication, and division.Example-2(Inputs are underlined):Scanned withExample-2(Inputs are underlined):Time left 1:56:58
image text in transcribed

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Security XI Status And Prospects

Authors: T.Y. Lin, Shelly Qian

1st Edition

0412820900, 978-0412820908

More Books

Students also viewed these Databases questions

Question

Show that standard Brownian motion is a Martingale.

Answered: 1 week ago

Question

Determine miller indices of plane X z 2/3 90% a/3

Answered: 1 week ago