Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- You are to 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). Reuse/recycle your menu function from Assignment 8.
- 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; and backwards 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
- (see Ch. 6).
- 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
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement