CS21: Quiz 3 Study Guide

In addition to the concepts from Quiz 1 and Quiz 2,

You should be able to define the following terms:

You should understand how to make objects from the following graphics library classes and know how to use their methods:

Practice problems:

  1. Write a main program that draws a circle centered in the graphics window with a radius of 100 and draws a line vertically from the top of the graphics window to the bottom. The program should wait for a mouse click to end.
  2. Multiple choice problems 1-5, pg. 192
  3. Discussion problems 1-5, pg. 193
  4. Write a function called avgList that takes a list of numbers as input and returns their average. For example, avgList([5, 10, 5, 4]) should return 6. Write a main program to test the function.
  5. Write a function called maxList that takes a list of numbers as input and returns the largest number in the list. For example, maxList([7,4,8,1]) should return 8. Write a main program to test the function.
  6. Write a function called makeRectangle that takes a graphics window and a string representing a color. It gets two mouse clicks from the user to define the opposite corners of a rectangle. It then draws the rectangle in the window, fills it with the desired color, and returns the Rectangle object. Write a main program to test your function.
  7. Consider the following program.
    def main():
        print "in main"
        test = "whee"
        check = "e"
        answer = helper(test, check)
        print "the answer is", answer
    def helper(word, letter):
        print "in helper"
        print "word:", word
        print "letter:", letter
        x = 0
        for ch in word:
            if ch == letter:
                x = x+1
        # draw stack here
        return x
    • Draw the call stack as it would look just prior to returning from helper.
    • What is the program's output (i.e. what is printed when the program is run)?
    • What does the helper funciton compute?
    • What would helper("moobaalalala", "a") return?
    • What would helper("zoo", "a") return?