Answered You can hire a professional tutor to get the answer.

QUESTION

-Focusing on Intermediate Programming 1. When two or more functions have the same name, how does the compiler determine which one to use for a

-Focusing on Intermediate Programming

1. When two or more functions have the same name, how does the compiler determine which one to use for a particular function call?

2. Write a void function called Order that takes two integer reference parameters a and b, and sets their values such that a is the smaller and b is the larger. Write another Order function that takes two double arguments. Write a short main function that calls both functions and demonstrates that they work. Cout statements should only appear in function main.

3. Rewrite your answer for the previous question, using a single Order template instead of two Order functions. If done correctly, the main() function should not change.

4. What value is returned by the call F(4) where F is the recursive function given by the following code? Explain how you arrived at your answer.

int F (int N)

{

     if (N == 0)

         return 1;

     else

         return (3 * F(N - 1));

}

5. Consider the following function:

int mystery(int number) {

        if (number == 1)

              return 1;

        else

              return number * mystery(number -1 );

}

a. What value does function mystery return when called with a value of 5?

b. What is the base case for function mystery?

6. Write an iterative (non-recursive) function that takes a number of years and a compound interest rate (as a percentage) and computes what a $1000 investment would have grown to in that many years at that interest. For example, given 3 for years and .1 (representing 10%) as the rate, the result would be $1331. Use a loop to calculate the result (don't use the pow function).

7. a. Rewrite your function for the previous question as a recursive function.

b. Which function do you think is easier to read?

c. Which function do you find easier to write?

8. What does it mean to modularize a program? What are the benefits? Are there any penalties for modularization?

9. Consider a program that reads two whole numbers from the user, computes the greatest common divisor, and displays the results to the user. Write a program for this task where all code is within the main function.

10. a. Rewrite your solution to the previous question as a modular program, using additional functions as much as possible.

    b. Which version of the program is shortest? Which version is easiest to read--and why?

-Focusing on Intermediate Programming 1. When two or more functions have the same name, how does the compiler determine which one to use for a particular function call? Ans. Depending on the no. of...
Show more
LEARN MORE EFFECTIVELY AND GET BETTER GRADES!
Ask a Question