CS 101 (Fall 2000)
Quiz 7: ADTs and Subclassing

Quiz Posted
(Thursdays)
Given in class
(Thursdays)
12 Oct 26 Oct

Information about quizzes:

The questions are intended to be straightforward. If you keep up with the material in the class, almost no preparation may be necessary. The Collaboration Policy allows you to study in groups for the quizzes, but you are on your own when you take the quiz.

You will fare better on the quiz if you try working the problems before looking at the solutions. If you don't understand the question or its answer, please get help.

  1. Define the class StackBasedQueueOfInts given the class StackOfInts.
  2. Define the class QueueBasedStackOfInts given the class QueueOfInts.
  3. Why can't we implement StackBasedQueueOfInts and QueueBasedStackOfInts in terms of each other?
  4. Consider the class
    public class Rectangle {
       protected int length, width;
       protected Rectangle() {
          length = 0;
          width  = 0;
       }
       public Rectangle(int length, int width) {
          this.length = length;
          this.width  = width;
       }
       public int area()      { return length * width;     }
       public int perimeter() { return 2*length + 2*width; }
    }
    

    Write a class for a Square by extending this class.


[ solution ]


Last modified 14:26:17 CST 12 March 2000 by Ron K. Cytron