Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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 an invalid operator is passed to the function, it should print "Invalid operator!"

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

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

Repairing And Querying Databases Under Aggregate Constraints

Authors: Sergio Flesca ,Filippo Furfaro ,Francesco Parisi

2011th Edition

146141640X, 978-1461416401

More Books

Students also viewed these Databases questions

Question

4. Evaluation is ongoing and used to improve the system.

Answered: 1 week ago

Question

How is network availability calculated?

Answered: 1 week ago