COM1201 Spring 1997 Professor Fell QUIZ 2 Solution
Problem 1: (7.5 points) Write the body of the function:

template <class T>
int Max (T Arr[], int n){
// precondition: n is the number of valid elements in Arr[]
// postcondition: returns the index of the maximum value in Arr[]
   T M = Arr[0];
   int index = 0;
   int i;
   for (i = 1; i < n; i++)
      if (Arr[i] > M){
      M = Arr[i];
      index = i;
   }
   return index;
};

Problem 2: (7.5 points) Fill in the following table:
DecimalBinaryHex
102311111111113FF
165 10100101 A5
19711000101 C5
42 1010102A
273100010001111

Problem 3: (5 points) For the following code segment, show the values of x, y, *p, *q at the five places indicated.

int x = 3; 
int  y = 5;
int *p = &x; int *q = &y; // 1a. x, y, *p, *q 3 5 3 5

*p += y;             // 1b.    x,     y,     *p,     *q
                               8      5       8       5

y = x + *p;          // 1c.    x,     y,     *p,     *q
                               8      16      8      16

q = p;               // 1d.    x,     y,     *p,     *q 
                               8      16      8       8 

p = &y;              // 1e.    x,     y,     *p,     *q
                               8      16     16       8

Last Updated: April 11, 1997 12:18 pm by

Harriet Fell
College of Computer Science, Northeastern University
360 Huntington Avenue #161CN,
Boston, MA 02115
Internet: fell@ccs.neu.edu
Phone: (617) 373-2198 / Fax: (617) 373-5121
The URL for this document is: http://www.ccs.neu.edu/home/fell/COM1101/QUIZ/Q2/quiz2Solution.html