Free help with homework

Why join Brainly?

  • ask questions about your assignment
  • get answers with explanations
  • find similar questions

Write a function called power() that takes a double for m and int value for p and returns the result as double value .use of a default argument of 2 for

p,so that if this argument is this omitted ,the number will be squared, write a main() function that gets value from the user to test this function.

write a function that performs same operation as that of above exercise but takes an int value for m.both the function should have the same name . write a main() that calls both the functions .use the concept of function overloding.



This Is a Certified Answer

Certified answers contain reliable, trustworthy information vouched for by a hand-picked team of experts. Brainly has millions of high quality answers, all of them carefully moderated by our most trusted community members, but certified answers are the finest of the finest.
The following is not exactly following the syntax rules of a language.  Please do follow when you write the program.  It is just a pseudo code.

#include <iostream>
#include <string>
#include <sstream>
              // we use string stream function to extract optional exponent values
#include <cmath>
using namespace std;

// function overloading
double power(double m, int p);
int power (int m, int p) ;
double power(double m);
int power (int m);

int  main (char * argv[], int argc)
      double   d_result, d_base, fraction ;
       int     i_result, i_base, exponent;
      string myExp;

               cout << "\nEnter the value of base: ";   cin >> d_base;
               i_base = (int) d_base ;   // integer part of base
               fraction = d_base - i_base;      // fraction part. check for 0 for an integer.
              // another way of checking is reading base as a string and checking for a "." in it.

               cout << "\n Enter the value of exponent: " ;  cin >> myExp;
               if (myExp.empty())     // default exponent   {
                        if (fraction == 0)    power (i_base);
                        else   power (d_base);
               else     {  /// non default integer exponent
                         stringstream(myLine) >> exponent;
                         if (fraction == 0)    i_result =  power (i_base, exponent);
                        else        d_result = power(d_base, exponent);
            cout <<  "\n Answer:  "  <<   (fraction) ?  d_result : i_result  ;

double power(double m, int p)
       return  pow(m, p);           // math

int power (int m, int p)
      return pow(m, p);       // math
double power(double m)
        return pow(m, 2);

int power (int m)
         return pow(m, 2);

1 5 1
click on thanks button above please
The Brain
  • The Brain
  • Helper
Not sure about the answer?
Learn more with Brainly!
Having trouble with your homework?
Get free help!
  • 80% of questions are answered in under 10 minutes
  • Answers come with explanations, so that you can learn
  • Answer quality is ensured by our experts