Final Exam, Summer 2009


  1. (8 points) Describe at least four ways functions make it easier to produce a working program.

    Note, the question after this uses the answer from this question. Please read both before you answer either

  2. (12 points) Write a complete program, which includes at least one function. This program should print the squares and cubes of the integers 0 through 10. Your output should look like this
    n      n^2     n^3
    0       0       0
    1       1       1
    2       4       8
    3       9      27
    4      16      64
          ...
    10    100    1000
    
  3. (10 points) Clearly label each of the following elements in your program from the previous question. Describe the purpose of each.
    1. Function Prototype
    2. Function Invocation
    3. Function Definition
    4. Formal Parameter List
    5. Actual Parameter List
  4. (10 points) What is the difference between a variable, or pass by reference, and a value or pass by value parameter? When is each used? Give an example of a function which employs both.
  5. (4 points) How must actual and formal parameters correspond?
  6. (2 points) What is the difference between a local variable and a parameter?
  7. (2 points) What is the scope of a variable?
  8. (2 points) What is the lifetime of a variable?
  9. (4 points) Give the syntax and describe the flow of control for the switch statement.

  10. (10 points) Write a routine what takes an integer as input, between 0 and 9, and returns the English word (zero, one, ... nine) for that integer. You must use a switch statement in this routine.
  11. (6 points) What is a stub routine, what is a test driver? Explain how and why each is used.
  12. (5 points) Describe characteristics of documented code. Give examples of both good and poor comments.
  13. (5 points) Describe self documenting code. Give examples.