Question
Create a class named Calculator in C++ with a data member named mValue which has a default value of 0.0 (double). This Calculator class should
Create a class named Calculator in C++ with a data member named mValue which has a default value of 0.0 (double). This Calculator class should have the functions to add, subtract, multiply, and divide into mValue. For example, using the add function with an argument of 10.0 would cause mValue to be added 10.0 into (0.0 + 10.0). If then, the subtract function with an argument of 5.0 is called, the new value in mValue would then be 5.0 (10.0 5.0). The same logic applies to multiplication and division. Your Calculator class should also have functions to get the number stored in mValue and a way to clear its value back to 0.0.
After your class is complete, write code to let the user use this calculator as follows:
- The user is asked whether they want to add, subtract, multiply, divide, show stored value, clear stored value, or exit the program
- You can use 0 to add, 1 to subtract, 2 to multiply, etc.
- You can use chars as well (a to add, s to subtract, etc.)
- If the user selects to add, subtract, multiply, or divide, the user is asked to enter the number they wish to add, subtract, multiply, or divide with. Apply the operation and show the user the new value stored in the calculator.
- If the user selects to show stored value, simply show the value
- If the user selects to clear stored value, clear the calculator value back to 0.0 and show the new value
- If the user selects exit the program, exit the program
- If the user selects anything else, inform the user they have selected an incorrect option and to select again
Hard Requirements
Your Calculator class should have its data members private. It should also have the 6 specified functions listed in the Problem Description (no other functions are required). The user should continue to use the operation until the user selects to exit.
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