CPSC 110 Spring 2012 Quiz 3 Practice Problems
Answer Key

    Instructions: The first three problems ask you to read a Pseudocode function definition. Trace through each of them by hand, keeping track of the variables, to determine the answer to the question.

  1. What value would functionA(5) return?
    # Comment: A function definition that takes 1 argument named a
    
    To functionA(a):
       Return: a + 100
    
  2. What value would inchesToCm(10) return?
    # Comment: Convert inches to centimeters
    # There are 2.54 centimeters per inch
    
    To inchesToCm(in):
      Return in * 2.54
    
  3. What value would mystery(3,2) return? What value would mystery(2,3) return?
    # Comment: A mystery function with 2 arguments
    
    To mystery(x, y):
       Set M to x
       If y < x then do:
          Set M to y
       Return M
    




    Instructions: The next three problems ask you to define a function in Pseudocode. Model your answers after the Pseudocode algorithms in the first 3 questions.

  4. Define a function named avg3 that will compute and return the average of any three numbers. You function should have 3 arguments named a, b, and c.








  5. Define a function named kmToMiles that will convert kilometers to miles. 1 kilometer is 0.62 miles. This function should have one argument named km.











  6. Define a function named circumference that will compute the circumference of a circle with radius r. The formula for computing circumference is C = 2 × π × r. Use 3.14 as the value of π. This function should have 1 argument named r.








    Click here for the solutions. But no peeking until after you've tried the problems.