|
|
 |
|
|
|
|
PtrType p1;
PtrType p2;
PtrType p3;
PtrType p4;
.
.
.
p4 = PtrToMax(p1, p2, p3); |
|
|
|
 |
|
|
|
|
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 |
|
|
|
 |
|
|
|
|
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 |
|
|
|
 |
|
|
|
|
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. |
|
|
|
 |
|
|
|
|
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 |
|
|
|
 |
|
|
|
|
AddAndIncr(m, n, theirSum); |
|
|
|
 |
|
|
|
|
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). |
|
|
|
 |
|
|
|
|
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). |
|
|
|
 |
|
|
|
|
b. Write a driver and test the Store function using your test data. |
|
|
|
|
|