Computer Science 2610
Fall 2000
Practice questions for quiz 3

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

  2. What is the responsibility of a constructor for a class?

  3. 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. Some operations on circles are provided. For example, function area returns the area of a circle. Write the definition of function area, as it would occur in file circle.cc. Use approximation 3.1416 for pi.
      class Circle 
      {
        public:
          Circle(Point center, double radius);
          double area();
          ...
        private:
          Point myCenter;
          double myRadius;
      };
    

  4. Write a C++ declaration for an array called Yarn that holds 25 integers.

  5. Suppose that array A contains the following.
        i      A[i]
        0       3
        1       7
        2       8
        3       5
    
    Function mystery is shown below. What is in array A after running mystery(A,4)?
       int mystery(int B[], int n)
       {
         int k;
         for(k = 0; k < n; k++) {
           B[k] = B[k] + k;
         }
       }
    

  6. Write a function that computes the sum of all of the numbers in an array of integers. There should be two parameters, the array A and the size n of the array. A function heading is provided.
      int sum(int A[], int n)
    

  7. You would like to set variable s to the sum of all of the integers in array Fish, which has 12 members. What statement would you write to use function sum to do the computation?

  8. Write a function that has a single null-terminated string parameter. It should return 1 if the string contains an 'a', and 0 if it has no occurrences of the letter 'a'. Call it anyAs. For example, anyAs("cat") = 1, but anyAs("dog") = 0.

  9. 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?

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

  11. 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?

  12. 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?

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

  14. When passing an array as a parameter to a function, you usually also pass the logical size of an array. That is not necessary when the array is a null-terminated string? Why not?

  15. What is the difference between the logical and physical size of an array?