Question
C++ ONLY Write a function calculator that takes two floating numbers and one operator and prints out the answer based on arithmetic. Assume that there
C++ ONLY
Write a function calculator that takes two floating numbers and one operator and prints out the answer based on arithmetic. Assume that there are no overflow, underflow and division by zero cases.
- Your function should be named calculator
- Your function takes three input parameter: two double numbers and one char operator
- Your function does not return anything
- Your function prints answer in the format specified below
- Your function should set precision point to 2
Note: You must use a switch case for this problem. if/else statements are not allowed.
The format of the output should be
If the function is called with (3, 7, '+') as the input argument:
3 + 7 = 11
If the function is called with (3, 7, '-') as the input argument:
3 - 7 = -4
If the function is called with (3, 7, '*') as the input argument:
3 * 7 = 21
If the function is called with (3, 7, '/') as the input argument:
3 / 7 = 0.43
If the function is called with (3, 7, '!') as the input argument:
Invalid operator!
Note: You do not need to write the main(), the include, or namespace commands, you only need to write the function definition.
For example:
Test | Result |
---|---|
calculator(3, -7, '+'); | 3 + -7 = -4 |
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