Question
2. Create a calculator that takes a number, a basic math operator (+,-,*,/,%,^), and a second number all from user input, and have it print
2. Create a calculator that takes a number, a basic math operator (+,-,*,/,%,^), and a second number all from user input, and have it print the result of the mathematical operation. The mathematical operations should be wrapped inside of functions. You may write separate function for separate operation and make sure the program will work either for integer or floating point numbers. So, probably it is better to declare two numbers as floating point numbers and not integers. Your program of C++ should have this structure: Write functions Add, Subtract, Multiply, Divide, Modulus, Power that will take two floating point numbers x and y as inputs, and returns the result for each. For doing the Modulus, you may like to use fmod(x, y) (this is math function, hence should include cmath). Power function should use pow built-in function. From main you need to call a void function DisplayOperation which will display the following when being called: Enter + for addition Enter for subtraction Enter * for multiplication Enter / for division Enter % for mudlulus Enter ^ for power Then ask the user to enter the symbol for the operation and store in the character variable operation. Now write a switch statement, that will use the character variable operation as controlling variable, and design various cases, +, - etc, and within each case call the appropriate function and store the value in result and display the result at the end of the switch statement. For the division function, inside the function, make sure to check if y is not zero, then only compute x/y, otherwise, display getting divided by 0 and return FLT_MAX (a large value)
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