Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

1. When should a pointer parameter p be a reference parameter? A. When the funct

ID: 644903 • Letter: 1

Question

1. When should a pointer parameter p be a reference parameter?

A. When the function changes p, and you want the change to affect the actual pointer argument.

B. When the function changes p, and you do NOT want the change to affect the actual pointer argument.

C. When the function changes *p, and you want the change to affect the the object that is pointed at.

D. When the function changes *p, and you do NOT want the change to affect the the object that is pointed at.

E. When the pointer points to a large object.

2. Here is a small function that uses the dynamic bag class from Chapter 4:

void quiz( )

{

bag::size_type i; // Line 1

bag b; // Line 2

b.insert(42); // Line 3

i = b.size( ); // Line 4

cout << i; // Line 5

}

When is the bag's dynamic array returned to the heap?

A. During the execution of Line 2.

B. During the execution of Line 3.

C. Just after Line 4 and before line 5.

D. After Line 5.

3. Suppose that a new foo class has this prototype for an overloaded assignment operator:

void operator =(const foo& source);

In an assignment statement a = b, what will be the actual argument for the parameter source?

A. a

B. b

4. What is the usual worst-case performance for resizing a container class that stores its data in a dynamic array?

A. Constant time

B. Logarithmic time

C. Linear time

D. Quadratic time

5. Suppose that you want to develop two different + operators that calculate and return an object of some class. Which statement is correct?

A. One operator must be a friend and the other must not.

B. One operator must be public and the other private.

C. The operators must have a different parameter lists.

D. It is not possible to have two different + operators.

Explanation / Answer

1. When should a pointer parameter p be a reference parameter?

A. When the function changes p, and you want the change to affect the actual pointer argument.

B. When the function changes p, and you do NOT want the change to affect the actual pointer argument.

C. When the function changes *p, and you want the change to affect the the object that is pointed at.

D. When the function changes *p, and you do NOT want the change to affect the the object that is pointed at.

E. When the pointer points to a large object.

2. Here is a small function that uses the dynamic bag class from Chapter 4:

void quiz( )

{

bag::size_type i; // Line 1

bag b; // Line 2

b.insert(42); // Line 3

i = b.size( ); // Line 4

cout << i; // Line 5

}

When is the bag's dynamic array returned to the heap?

A. During the execution of Line 2.

B. During the execution of Line 3.

C. Just after Line 4 and before line 5.

D. After Line 5.

3. Suppose that a new foo class has this prototype for an overloaded assignment operator:

void operator =(const foo& source);

In an assignment statement a = b, what will be the actual argument for the parameter source?

A. a

B. b

4. What is the usual worst-case performance for resizing a container class that stores its data in a dynamic array?

A. Constant time

B. Logarithmic time

C. Linear time

D. Quadratic time

5. Suppose that you want to develop two different + operators that calculate and return an object of some class. Which statement is correct?

A. One operator must be a friend and the other must not.

B. One operator must be public and the other private.

C. The operators must have a different parameter lists.

D. It is not possible to have two different + operators.