# CS 1410 Introduction to Computer Science ­ CS2 Assignment #0 solution

\$30.00

Category:

## Description

Assignment:
Write a simple C++ calculator program. This program will consist of a single Calculator class
that keeps track of the running total. The total will be initialized to zero. The Calculator class
will consist of the following methods:
void subtract(double value);
void multiply(double value);
void divide(double value);
double getTotal() const;
The program must offer a user interface, using cin and cout, to allow the user the ability to
manipulate the total. The user interface must look like the following:
*** Calculator ***
S: Subtract a value
M: Multiply by a value
D: Divide by a value
T: Get the total
Q: Quit
Section:
You should write your program and break out the definitions and implementations into
main.cpp, Calculator.hpp, and Calculator.cpp.
1. [5 points] Create your main
2. [5 points] Create the user interface
a. Using cin and cout, create the user interface listed above.
b. The user input should be case insensitive
3. [30 points] The Calculator structure
a. Create a constructor
b. Create a destructor
c. Define each of the above listed functions
Execution Example:
Run 0)
*** Calculator ***
S: Subtract a value
M: Multiply by a value
D: Divide by a value
T: Get the total
Q: Quit
Current Total: 0.0
Selection: A
Value: 1.1
0.0 + 1.1 = 1.1
*******
Run 1)
*** Calculator ***
S: Subtract a value
M: Multiply by a value
D: Divide by a value
T: Get the total
Q: Quit
Current Total: 1.1
Selection: S
*** Subtract selected ***
Value: 0.2
1.1 ­ 0.2 = 0.9
******
Run 2)
*** Calculator ***
S: Subtract a value
M: Multiply by a value
D: Divide by a value
T: Get the total
Q: Quit
Current Total: 0.9
Selection: M
*** Multiply selected ***
Value: 2.2
0.9 * 2.2 = 1.98
******
Run 3)
*** Calculator ***
S: Subtract a value
M: Multiply by a value
D: Divide by a value
T: Get the total
Q: Quit
Current Total: 1.98
Selection: d
*** Divide selected ***
Value: 2.2
1.98 / 2.2 = 0.9
******
Run 4)
*** Calculator ***
S: Subtract a value
M: Multiply by a value
D: Divide by a value
T: Get the total
Q: Quit
Current Total: 0.9
Selection: T
*** Total selected ***
Total Value: 0.9
******
Run 5)
*** Calculator ***