Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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:

  1. The user is asked whether they want to add, subtract, multiply, divide, show stored value, clear stored value, or exit the program
    1. You can use 0 to add, 1 to subtract, 2 to multiply, etc.
    2. You can use chars as well (a to add, s to subtract, etc.)
  2. 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.
  3. If the user selects to show stored value, simply show the value
  4. If the user selects to clear stored value, clear the calculator value back to 0.0 and show the new value
  5. If the user selects exit the program, exit the program
  6. 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

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

Step: 3

blur-text-image

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

Data Management Databases And Organizations

Authors: Richard T. Watson

2nd Edition

0471180742, 978-0471180746

More Books

Students also viewed these Databases questions