CSSE 120 — Introduction to Software Development

Homework 8

Reminder: for each class session and associated homework:

  1. Complete the assigned reading for the next session: Zelle, Sections 5.6-5.10.
  2. (15 points) In Angel, complete the Reading Quiz over the above reading.
  3. Solo Programming: The remaining exercises are to be done in the 08-DecisionStructures project that you checked out in class. There's a lot here. Our intention is that during the next week oyu will be up to speed for next week's exam. The mainl way to prepare for an exam in this class is to practice. 
    1. (15 Points) Complete the exercise that you started in class in the countPassFail.py module, per the TODO's in the module.
    2. (40 points) Do the exercise in the circleOfCircles.py module, per the following instructions:

      Create a function called circleOfCircles that takes five parameters (as described below) and draws n circles whose centers are equally spaced around a (usually) larger circle, as in this example where n is 12:

      Sample display of the circleOfCircles function

      Note that, as the image shows, you do not actually draw the larger circle that the n circles are spaced around.

      The parameters must be as follows, in the order listed:

      • A GraphWin object onto which the function will draw the circles.
      • n, the number of circles to draw.
      • A Point that is the center of the “big” circle that the other circles surround.
      • The radius of the “big” circle.
      • The radius of each of the “small” circles that your function draws.

      Additional requirements:

      • If the entire “circle of circles” will not fit inside the GraphWin that it is given, the circleOfCircles function must print an appropriate message to the console instead of drawing the “circle of circles.”
        • Hint 1: use an IF statement!
        • Hint 2: you will want to use the getHeight and getWidth methods that a GraphWin has.
        • With this and the other additional requirements, the graphics window SHOULD appear — that's OK!
      • If the parameter n is not greater than 2, the circleOfCircles function must print an appropriate message to the console instead of drawing the “circle of circles.”
      • Optional (but easy): If the parameter n is not an integer, the circleOfCircles function should print an appropriate message to the console instead of drawing the “circle of circles.”
        • Hint: here is how to do this, where n is the variable being used for the parameter:
              if type(n) != int:
                  # Print the error message to the console
              elif:
                  # ...
          

      We supplied a displayOneCircleOfCircles that main calls to test your circleOfCircles function. The first test will display the example “circle of circles” shown above, if your implementation is correct. You must supply additional tests in main as appropriate.

      Finally, note that tracing out a circle is straightforward if you use polar coordinates. For an example of using polar coordinates, see the calculateVertices function in the pizzaPolyStar.py module:

      def calculateVertices(center, radius, number):

          '''Returns a list of 'number' points evenly spaced around the

          circumference of a circle with the given location and radius.'''

          centerX = center.getX()

          centerY = center.getY()

         

          # Builds vertices list

          vertices = []

          for i in range(number):

              x = radius * cos(2 * pi * i / number) + centerX

              y = radius * sin(2 * pi * i / number) + centerY

              vertices.append(Point(x, y))

             

          return vertices