Department of Statistics,
University of California - 
Los Angeles
STAT 13 
Statistical Methods
Fall Quarter 2001
Name: ........................
Student ID#: ......................
Section/TA: ......................
Score: ......../100
Program in Computing

Mid-Term Exam, Friday, Nov. 02, 2001, 12:00-12:50 PM

FRANZ 1260
Instructor: Prof. Ivo D. Dinov
TAs: Katie Tranbarger & Scott Spicer
URL:: http://www.stat.ucla.edu/~dinov/


Instructions: Please write clearly and diligently. You may use the reverse pages if you need extra space, provided you make a comment on the front page. If this is still not enough please raise your hand and request more paper. You should NOT use your own scratch paper. You need to complete 10 out of the 11 problems to get full credit. This test booklet contains 4 pages.

1.Explain the difference between:

  1. char short_string1[] = "abc";
  2. char short_string2[] = { 'a', 'b', 'c'};
  3. string short_string3("abc");



2.Describe the functions strlen, strcat, strcpy and strcmp. Give

  1. the arguments for each function

  2.  
  3. the type of the return value for strlen and tell what this return value means.

  4.  
  5. the type of the return value for strcmp and tell what this return value means.

  6.  
  7. the action of strcpy

  8.  
  9. the action of strcat

  10.  

3.Assume this code fragment is embedded in a complete, correct program. What is the output from this code fragment?

int array[4][4];
int index1, index2;
   for (index1 = 0; index1 < 4; index1++)
     for (index2 = 0; index2 < 4; index2++)
       array[index1][index2] = index2*index1;
   for (index1 = 0; index1 < 4; index1++)
   {
     for (index2 = 0; index2 < 4; index2++)
      cout << array[index1][index2] << " ";
      cout << endl;
   }
 
 
 


4. Write a complete program which declare an array of 4 String objects named list. Prompt the user for and accept 4 names, one per line, from the standard input. Order the strings in lexicographical order and report the ordered list of 4 strings. [Hint: use a single pointer to a string object and initialize it to contain 4 objects, then use the standard comparison functions (< and >) to properly order the 4 strings.]
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 


5. Explain the definition of the multi-dimensional array int myIntArray3D[10][15][20]; Order the indices fast-to-slow, elaborate on the very definition of a 3D array - its meaning. If the address of the first element is in memory location 10,000, compute the starting location for the element myIntArray3D[3][5][10].
 
 
 
 
 
 
 


6. Let p1 and p2 be two pointers to double type objects and v1 and v2 be two double variables.

  1. Write the declarations for all 4 variables:

  2.  
  3. Make p1 point to v1:

  4.  
  5. Instantiate p2 and assign the value 56.3 to the location it points to:

  6.  

     
     
     
     
     
     
     
     
     
     
     
     
     
     


7. Again p1 and p2 are two pointers to double type objects and A is a 1D array of doubles.

  1. Suppose p2 is initialized, make p1 and p2 point to the same memory location if this is legal:

  2.  
  3. Release the memory allocated to p1. What happens to the other pointer p2, which also points to the same location?

  4.  
  5. If A is an array, which of these are legal/illegal provided both A and p1 are defined: A = p1; and p1 = A;

  6.  

8. For the interface of the StringVar class we discussed in lecture write the body definition of the assignment overloading operator (=), void StringVar::operator= ( const StringVar & rhs ). Remember, you need to nullify previous assignments of the left-hand-side, then make room for a new c-string object and assign to it the value of the right-hand-side, rhs.

class StringVar
{
   public:
     StringVar(int size);
     StringVar( );
     StringVar(const char a[ ]);
     StringVar(const StringVar& string_object);
     ~StringVar( );

     int length( ) const;
     void input_line(istream& ins);

     friend ostream& operator <<(ostream& outs, const StringVar& the_string);

   private:
     char *value;
     int max_length;
};
 
 
 
 


9. Write a recursive (on the left side) and an equivalent regular (loop-based) function (on the right side), which print out on the std::out the string PIC10B, N times, where both functions take in an integer argument (N).
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 


10. Fill in the blanks in each of the following sentences.

  1. If double* DP; and DP=1000, (DP+30)= ________.
  2. We allocate dynamic memory for 32 long variables by (declare) _________________________ and (memory allocate) _______________.
  3. ________ members are only accessible inside the scope of the definition of an ADT. And ________ members could be accessed from external functions.

11.State whether each of the following is true or false. If false, explain why.

  1. A recursive function must not return a value.

  2.  
  3. A recursive function can not be implemented any other way.

  4.  
  5. A recursive function can not call any other, external to it, function.

  6.