Question


3. Using one of the loop structures, and function overloading, write function mypower(int x,int y) which calculates X, and w

3. Using one of the loop structures, and function overloading, write function mypower(int x,int y) which calculates X', and write another function in the same code called mypower(double x,int y) which calculates X'. Test both in the main. Note: y can be negative value. Hint: x-Y =

0 0
Add a comment Improve this question Transcribed image text
Answer #1
 #include  using namespace std; class powers { private: long int result1; double result3; double result2; public: powers() { result1=1; } powers(double rst) { result2=rst; } void mypower(int x,int y) { int flag=0; if(y<0) { y=y*(-1); flag=1; } for(int i=0; i

#include
using namespace std;

class powers
{
private:
long int result1;
  
double result2;
double result3;

public:
powers()
{
result1=1;
  
  
}
powers(double rst)
{
result2=rst;
  
}
void mypower(int x,int y)
{ int flag=0;
  
if(y<0)
{ y=y*(-1);
flag=1;
}
  
  
for(int i=0; i {
result1*=x;
  
}
if(flag==1)
{ result3= 1/(double)result1;
cout<< " result is "<   
}
else
cout<<"result is int "<   
cout<   
}
  
void mypower(double x,int y)
{
int flag=0;
  
if(y<0)
{ y=y*(-1);
flag=1;
}
  
for(int i=0; i {
result2*=x;
  
}
if(flag==1)
{ result3= 1/(double)result2;
cout<< " result is "<   
}
else
cout<<"result is int "< cout<
}
  
};


int main() {

powers p1;
p1.mypower(32,-2);
  
double zz=1.0000;
powers p2(zz);
p2.mypower(5.0,-2);
  


   return 0;
}

#include <iostream> using namespace std; class powers //class for overloadding function created { private: long int result1;OG Binary Search Tree Set 1 (s x CC Code, Compile & Run | Code X C There Is Alreday A Solution x (399) CORONA- Ei ose X COVIDint flag=0; 52 53 54 TL LLLLL // doulble value wala ovverloaded mypow function 55 - if(y<0) { y=y*(-1); flag=1; 56 57 58 for78 - int main() { powers pl; pl.mypower(32,-2); //calling the function I double zz=1.0000; powers p2 (zz); p2.mypower(5.0,-2)

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT