Question: Objectives: Write C++ programs Compile C++ programs Implement programs that use functions Implement programs that read and write to files Create a program that asks

Objectives:

  1. Write C++ programs
  2. Compile C++ programs
  3. Implement programs that use functions
  4. Implement programs that read and write to files

Create a program that asks the user to input a base number and a power, and displays the result of that base number raised to the power.

Create a function named power that computes the value of a base raised to a power.

The function should accept two parameters, a double and an int to represent the base and the power values, respectively. The function should return a double value after performing the operation.

Hint: Be careful with your local variable names. If you use the same name for a local variable as the function name, the compiler will assume you are referring to the local variable when you try to call the function. This has to do with scope. Your function's name should be power, so the local variables need to be something else.

Make sure that you write the power function prototype in power.hpp and its implementation in power.cpp, and call the function from prob-04-main.cpp. You'll find that skeleton code has already been provided for prob-04-main.cpp and you simply need to call the function and include the necessary header files.

SKELETON CODE:

#include #include

int main() { double base_input = 0; int power_input = 0;

std::cout << "Please enter the base number: "; std::cin >> base_input; std::cout << "Please enter the power: "; std::cin >> power_input;

// Call your power function, pass the necessary arguments, then assign // its returned value to result.

double result;

std::cout << std::setprecision(2) << std::fixed; std::cout << base_input << " ^ " << power_input << " = " << result << " ";

return 0; }

Please see the samples below. Note that bold values in the samples represent input by the user.

Sample input/output:

please enter the base number: 5

please enter the power: 3

5 ^ 3 = 125

Sample #2

please enter the base number: 2.5

please enter the power: 3

2.5 ^ 3 = 15.625

Sample with negative power

please enter the base number: 4

please enter the power: -2

4 ^ - 2 = 0.06

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!