Computer Science 2310
Spring 2005
Practice questions for quiz 3

This will be a closed book quiz. You may bring one 8.5x11 page of prepared notes, written on both sides.

  1. Suppose that you have an object called cal, of class Calendar. Object cal contains a public variable called day, of type int. What should you write to add 1 to the day variable in object cal?

  2. Suppose object cal of the preceding question also has a method called setDay that takes a single integer parameter, and that produces a void result. What would you write to ask cal to run its setDay method with parameter 5?

  3. What is the difference between an object and a class?

  4. What is the responsibility of a constructor for a class? What do you use it for?

  5. A circle in the plane can be described by its center point and its radius. Class Circle describes objects that are circles in the plane, and its definition is partially given below. Class Circle provides some operations on circles. For example, function area returns the area of a circle. Write the definition of function area. Use 3.14159 as an approximation of pi.

      class Circle 
      {
        public Circle(Point center, double radius)
        {
          myCenter = center;
          myRadius = radius;
        }
    
        public double area()
        {
        
    
    
    
    
    
        }
    
        private Point myCenter;    // center of this circle
        private double myRadius;   // radius of this circle
      }
    

  6. To within a constant factor (that is, in terms of proportionality) how much time does it take to sort an array of n integers using insertion sort, in the worst case?

  7. To within a constant factor, how much time does it take to sort an array of n integers using quicksort, in the average case?

  8. To within a constant factor, how long does it take to do a linear search of an array of n integers, in the worst case?

  9. To within a constant factor, how long does it take to do a binary search of a sorted array of n integers, in the worst case? (Note: each time around the loop, the size of the part that needs to be searched is cut in half. If you start with n, and each time around the loop you cut the size in half, how many times do you go around the loop before there is only one left?)

  10. With an error of no more than 1/2, what is log base 2 of 2000?