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:
| Decimal | Binary | Hex |
| 1023 | 1111111111 | 3FF |
| 165 | 10100101 | A5 |
| 197 | 11000101 | C5 |
| 42 | 101010 | 2A |
| 273 | 100010001 | 111 |
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