CPSC 110 Spring 2012 Quiz 3
Answer Key

    Instructions: The first two problems ask you to read a Pseudocode function definitions. 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
    
    To functionA(a):
       Return: a * a - a
    














  2. What value would mystery(3,3) return? What value would mystery(2,5) return?
    # Comment: A mystery function
    
    To mystery(X, Y):
       If X = Y then do:
          Return X * Y
       If X > Y then do:
          Return X - Y
       else do:
          Return Y - X
    




     

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

  3. Define a function named areaOfCircle that computes the area of a circle with radius, r. Recall that A = π r2. You can use 3.14 as the value of π. This function should take 1 argument, r.




















  4. Define a function named mpg that calculates miles per gallon. This function should take two arguments, mi for miles traveled, and g, for gallons of gas used. It should the average number of miles per gallon used by the car.