CSCI 2610
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. You would like to open a file called "mydata.txt" for reading. Write a declaration that will create a object that can be used to read from that file, in a way similar to the way the object cin is used to read from the standard input.

  4. You would like to open a file called "myout" for writing. Write a declaration that will create an object that can be used to write to that file, in a way similar to the way the object cout is used to write to the standard output.

  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. 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.
      class Circle 
      {
        public:
          Circle(Point center, double radius);
          double area();
          ...
        private:
          Point myCenter;
          double myRadius;
      };
    

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

  7. 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;
         }
       }
    

  8. 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)
    

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