Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Please help me with the following program. I am having trouble starting as well

ID: 3621493 • Letter: P

Question

Please help me with the following program. I am having trouble starting as well as completing the program. Thanks!

Write a program utilizing reference parameters. Your program should have

the following four functions: menu, sum, power, gcd. Your program should first call

menu, and display the options for your program – to find the power of x raised by y;

the max power x can be without exceeding y, and printing out a number backwards.

The choice is sent back via reference parameter (so it should be an argument).

Next, your program should prompt for value(s) and then will perform the

calculations for power, maxPower, or backwards (which is just printing out the

number in reverse). The functions power and maxPower have return type int, while

backwards has a return type of void. The power function will have two arguments:

the number to raise and the power to raise the number to; the maxPower function

will have two arguments: the number to raise and the number not to exceed;

andbackwards has one argument, the number to print out in reverse.

Your program should print out the result to the screen. Last, your program should

ask the user to select an option from the menu of four choices.


One other note: each of the functions must solve its calculation/output recursively

Brief descriptions:

Power: the power of x raised by y

Power(3,4) = 3*3*3*3 = 81

maxPower: the power of x raised by ? not to exceed y

maxPower (2, 31) = 4

maxPower(5, 125) = 3

backwards(123456789) prints out 987654321

Sample run:

1) Find the power of x raised by y.

2) Find the maximum power of y that does not exceed x.

3) Print out a number backwards.

4) Quit

2

Enter the number to raise: 5

Enter the number not to exceed: 624

Result: 3

1) Find the power of x raised by y.

2) Find the maximum power of y that does not exceed x.

3) Print out a number backwards.

4) Quit

1

Enter the number to raise: 2

Enter the power to raise to: 8

Result: 256

1) Find the power of x raised by y.

2) Find the maximum power of y that does not exceed x.

3) Print out a number backwards.

4) Quit

3

Enter the number: 90210

Result: 01209

1) Find the power of x raised by y.

2) Find the maximum power of y that does not exceed x.

3) Print out a number backwards.

4) Quit

3

Enter the number: 37419

Result: 91473

1) Find the power of x raised by y.

2) Find the maximum power of y that does not exceed x.

3) Print out a number backwards.

4) Quit

4

Explanation / Answer

please rate - thanks

sorry, I can't do maxpower recursively, so I skipped it

at least this gets you started

#include <iostream>
using namespace std;
void menu(int&);
int power(int,int);
int maxpower(int,int);
void reverse(int);
int main()
{int choice,x,y;
menu(choice);
while(choice!=4)
{switch(choice)
      {case 1:cout<<"Enter the number to raise: ";
              cin>>x;
              cout<<"Enter the power to raise to: ";
              cin>>y;
              cout<<"Result: "<<power(x,y)<<endl<<endl;
                break;
       case 2: cout<<"Enter the number to raise: ";
               cin>>x;
               cout<<"Enter the number not to exceed: ";
               cin>>y;
               cout<<"Result: "<<maxpower(x,y)<<endl<<endl;
                break;
       case 3: cout<<"Enter the number: ";
               cin>>x;
               cout<<"Result: ";
               reverse(x);
               cout<<endl<<endl;
            break;
       }
menu(choice);
}
return 0;
}
void menu(int &n)
{cout<<"1) Find the power of x raised by y. ";
cout<<"2) Find the maximum power of y that does not exceed x. ";
cout<<"3) Print out a number backwards. ";
cout<<"4) Quit ";
cin>>n;
}
int power(int num1,int num2)
{if(num2==0)
    return 1;
else if (num2==1)
    return num1;
else
    return num1 * power(num1, num2-1);
}
int maxpower(int num1,int num2)
{
    return 0;
}
void reverse(int x)
{if(x==0)
    return;
cout<<x%10;
if(x!=0)
    {x/=10;
    reverse(x);
    }
}