Question
12. Here is a small function that uses the dynamic bag class from Chapter 4: void quiz( ) { bag::size_type i; // Line 1 bag
12. 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 allocated?
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.
13. 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.
14 The + operator which combines two bags was not declared as a member function of the bag class. How can this function access the private data members of the two bags passed as arguments?
A. It cannot.
B. The operator is declared to be a friend to the class.
C. The operator is implemented in the header file containing the bag class definition.
D. The operator is implemented in the same implementation file as the bag class.
15. 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
16. Suppose you are implementing an assignment operator, a copy constructor, and an operator +=. For which of these functions do you need to worry about possible "self-application" (where the argument is the same as the object that activates the function):
A. Only one of the three functions has possible self-application
B. The assignment operator and the copy construtor have possible self-application
C. The assignment operator and the operator += have possible self-application
D. The copy construtor and the operator += have possible self-application
E. All three functions have possible self-application
17. 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
18. When a class uses dynamic memory, what member functions should be provided by the class?
A. The assignment operator.
B. The copy constructor.
C. A destructor.
D. All of the above.
19.. Which situation does not use the copy constructor?
A. Calling a function with a reference parameter
B. Calling a function with a value parameter
C. Declaring a variable to be a copy of another existing object
D. Returning a value from a function
E. All of the above situations use the copy constructor
20. . Suppose that you want to declare an array of characters to hold a C++ string with exactly 9 letters. Which declaration is best?
A. char s[8];
B. char s[9];
C. char s[10];
D. char s[11];
E. char s[12];
21. Suppose that x and y are two C++ strings. Which expression will return true whenever x and y contain the same sequence of characters?
A. (x = y)
B. (x == y)
C. (x != y)
D. (strcmp(x, y))
22. 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.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started