Write a program c to compute the power of base raised to an

Write a program c++ to compute the power of base raised to an exponent expo similar to the pow function. Your program should ask for the base which can be a decimal and the exponent expo which is an integer value. You will create a function called myPower which will be called to compute and return the value of base raised to the power expo.
Special cases:

1) if (base=0 and expo<=0) display UNDEFINED.

Below is the myPower function - complete it and incorporate into your main program. The function uses the absolute value founction abs which is found in the cmath library.

// start of myPower function  
double myPower(double base, int exponent)
{

(fill in the statements required)


} // end of myPower

For any other value call on myPower to compute and return the result.
Use the built-in pow function to verify that the result is correct. Try your program for each of the following values:
a) base=0 and expo=-3
myPower gives ???       and pow gives ???
b) base=0 and expo=7
myPower gives ???       and pow gives ???
c) base=2.5 and expo=5
myPower gives ???       and pow gives ???
d) base=2.0 and expo=-3
myPower gives ???       and pow gives ???
e)base=34.5 and expo= 6
myPower gives ???       and pow gives ???

Solution

#include <iostream>
#include <cmath>
#include<conio.h>
using namespace std;
double myPower(double , int);
int main(){
   double base;
   int expo;
   cout<<\"Enter expo:\";
   cin>>expo;
   cout<<\"Enter base:\";
   cin>>base;
   if (base=0 and expo<=0){
       cout<<\"display UNDEFINED.\"<<endl;
}
   myPower(base , expo);
  

   getch();
   return 0;
}

// start of myPower function
double myPower(double base, int exponent)
{
double result= pow(base,exponent);
   cout<<\"\ Result \"<<pow(base,exponent);
return 0;


} // end of myPower

Write a program c++ to compute the power of base raised to an exponent expo similar to the pow function. Your program should ask for the base which can be a dec
Write a program c++ to compute the power of base raised to an exponent expo similar to the pow function. Your program should ask for the base which can be a dec

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site