< previous page page_1041 next page >

Page 1041
3e26ecb1b6ac508ae10a0e39d2fb98b2.gif
PtrType p1;
PtrType p2;
PtrType p3;
PtrType p4;
  .
  .
  .
p4 = PtrToMax(p1, p2, p3);
3e26ecb1b6ac508ae10a0e39d2fb98b2.gif
the PtrToMax function returns a pointer: the value of p1, p2, or p3, whichever points to the struct with the highest value of score. Implement the PtrToMax function.
6. Write an If statement that compares the two dynamic int variables pointed to by variables p and q, puts the smaller into an int variable named smaller, and destroys the original two dynamic variables.
7. Declare all variables used in Exercise 6.
8. Given the declarations
3e26ecb1b6ac508ae10a0e39d2fb98b2.gif
int   numLetters;  // No. of letters in user's last name
int   i;           // Index variable
char* list;        // Pointer to array of letters in
                   //   user's last name
3e26ecb1b6ac508ae10a0e39d2fb98b2.gif
write a section of code that prompts the user for the number of letters in his or her last name, dynamically creates a char array of exactly the right size to hold the letters, inputs the letters, prints out the letters in reverse order (last through first), and deallocates the array.
9. Pretend that C++ provides pointer types but not reference types. Rewrite the following function using pointer variables instead of reference variables.
3e26ecb1b6ac508ae10a0e39d2fb98b2.gif
void AddAndIncr( /* in */    int int1,
                 /* inout */ int& int2,
                 /* out */   int& sum )
{
    sum = int1 + int2;
    int2++;
}
10. For the function of Exercise 9, change the function call
3e26ecb1b6ac508ae10a0e39d2fb98b2.gif
AddAndIncr(m, n, theirSum);
3e26ecb1b6ac508ae10a0e39d2fb98b2.gif
so that it corresponds to the new version of the function.
11. a. Design the data sets necessary to thoroughly test the ValueAt function of the DynArray class (pages 10201030).
3e26ecb1b6ac508ae10a0e39d2fb98b2.gif
b. Write a driver and test the ValueAt function using your test data.
12. a. Design the data sets necessary to thoroughly test the Store function of the DynArray class (pages 10201030).
3e26ecb1b6ac508ae10a0e39d2fb98b2.gif
b. Write a driver and test the Store function using your test data.

 
< previous page page_1041 next page >