Section 11.1 Introduction
11.1 Q1: Which of the following is not an operator overloaded by the C++ language?

pow.
>>.
+.
<<.
Which of the following is true about streams?

A.    It is a sequence of bytes
B.    It is an ordered sequence
C.        All bytes can go through the stream simultaneously
D.    Bytes that enters first into the stream will go out at last
A only
C only

A and B
A and D
Stream is a sequence of bytes. It is an ordered sequence. Let’s compare it with the door example. The person who enters first will go out of the door first. The person who enters behind someone will go out behind that person. Similarly streams are also ordered sequence. The thing that enters first into the stream will go out first. You should think streams as ordered sequence of bytes. Byte is a unit of measure. A byte can store one character, so you can think of an ordered sequence of characters.

11.2 Q1: To use an operator on user-defined class objects, operator overloading:

Must never be used, with three exceptions.
Must never be used.
Must always be used.
Must always be used, with three exceptions.

operator_+.
operator:+.
operator+.
operator(+).

11.3 Q1: Which of the following operators cannot be overloaded?

The . operator.
The -> operator.
The [ ] operator.
The & operator.

New operators can never be created.
Certain overloaded operators can change the number of arguments they take.

11.3 Q3: To implicitly overload the += operator:

Only the = operator needs to be overloaded.
Only the + operator needs to be overloaded.
The += operator cannot be overloaded implicitly.
Both the + and = operators need to be overloaded.

Section 11.4 Operator Functions as Class Members vs. Global Functions
11.4 Q1: Which of the following operators can be overloaded as a global function?

().
==.
+=.
[].

11.4 Q2: Which situation would require the operator to be overloaded as a global function?

The left most operand must be a class object (or a reference to a class object).
The left operand is an int.
The operator returns a reference.

11.4 Q3: An overloaded + operator takes a class object and a double as operands. For it to be commutative (i.e., a + b and b + a both work):

The + operator cannot be overloaded to be commutative.
operator+ must be a non-member function.
operator+ must be a member function of the class from which the objects are instantiated.
It must be overloaded twice; the operator+ function that takes the object as the left operand must be a member function, and the other operator+ function must be a global function.

11.5 Q1: Suppose you have a programmer-defined data type Data and want to overload the << operator to output your data type to the screen in the form cout << dataToPrint; and allow cascaded function calls. The first line of the function definition would be:

ostream &operator<<( const Data &dataToPrint, ostream &output ).
ostream &operator<<( ostream &output, const Data &dataToPrint ).
ostream operator<<( ostream &output, const Data &dataToPrint ).
ostream operator<<( const Data &dataToPrint, ostream &output ).

11.6 Q1: Suppose the unary ! operator is an overloaded member function of class String. For a String object s, which function call is generated by the compiler when it finds the expression !s?

A compiler error results because no arguments are given.
operator!( s ).
s.operator!( default_value1, default_value2,…).
s.operator!().

11.7 Q1: y and z are user-defined objects and the += operator is an overloaded member function. The operator is overloaded such that y += z adds z and y, then stores the result in y. Which of the following expressions is always equivalent to y += z?

y.operator+=( z ).
y = y + z.
y = y operator+= z.
y operator+=( y + z ).

11.7 Q2: For operators overloaded as non-static member functions:

Both binary and unary operators take one argument.
Neither binary nor unary operators can have arguments.
Binary operators can have two arguments and unary operators can have one.
Binary operators can have one argument, and unary operators cannot have any.

Section 11.8 Case Study: Array Class
11.8 Q1: Which of the following is        False?

Two arrays cannot be meaningfully compared with equality or relational operators.
C++ ensures that you cannot “walk off” either end of an array.
An entire non-char array cannot be input or output at once.
Arrays cannot be assigned to one another (i.e., array1 = array2;).

11.8 Q2: The array subscript operator [], when overloaded, cannot:

Take multiple values inside (e.g., [4 8]).
Take a float as an operand.
Take user-defined objects as operands.
Be used with linked list classes.

11.8 Q3: A copy constructor:

None of the above.
Is a constructor that takes no arguments.
Is a constructor with only default arguments.
Is a constructor that initializes a newly declared object to the value of an existing object of the same class.

11.8 Q4: Copy constructors must receive its argument by reference because:

The pointer needs to know the address of the original data, not a temporary copy of it.
The copy of the argument passed by value has function scope.
Otherwise the constructor will only make a copy of a pointer to an object.
Otherwise infinite recursion occurs.

11.8 Q5: To prevent class objects from being copied:

Make the copy constructor private.
None of the above.
Make the overloaded assignment operator private.
Both (a) and (b).

Section 11.9 Converting between Types
11.9 Q1: Conversion constructors:

Can convert between user-defined types.
Are implicitly defined by the compiler if not explicitly written by the programmer.
Cannot convert built-in types to user defined types.
Can have multiple arguments.

11.9 Q2: The prototypes of overloaded cast operator functions do not:

Specify the type they convert to.
Need to be defined inside the class whose objects are being converted.
Specify the type that is being converted.
Specify a return type.

11.9 Q3: Which of the following lines would be the prototype for an overloaded cast operator function that converts an object of user-defined type Time into a double?

Time::operator_cast(double) const;.
Time::static_cast double() const;.
Time::operator double() const;.
d. Time::double() const;.

Section 11.10 Case Study: String Class
11.10 Q1: Conversion constructors cannot:

Be used to convert the arguments for overloaded operators to the types needed by those overloaded operators.
Take exactly one argument.
Be used implicitly in series to match the needs of an overloaded operator.
Be applied implicitly.

11.10 Q2: Which of the following is not a disadvantage of default memberwise copy with objects containing pointers?

Having the possibility of leaving a dangling pointer.
Allowing both objects to point to the same dynamically allocated storage.
Allowing the destructor of one object to be called while leaving the second pointer, to the same memory location, intact.

11.10 Q3: Assume that the function call operator() is overloaded for data type String in the usual sense of selecting a substring from a larger string. For a String object string1 with the character string "ABCDEFGHI", what string does string1( 4 , 2 ) return?

"CDEF".
"EF".
"CD".
"EFGHI".

11.11 Q1: The conventional way to distinguish between the overloaded preincrement and postincrement operators (++) is:

To assign a dummy value to preincrement.
To make the argument list of postincrement include an int.
To have the postincrement operator call the preincrement operator.
Implicitly done by the compiler.

11.11 Q2: Because the postfix increment operator returns objects by value and the prefix increment operator returns objects by reference:

The postfix increment operator returns the actual incremented object with its new value.
The postfix increment operator typically returns a temporary object that contains the original value of the object before the increment occurred.
Prefix increment has slightly more overhead than postfix increment.
Objects returned by postfix increment cannot be used in larger expressions.

Section 11.12 Case Study: A Date Class
11.12 Q1: There exists a data type Date with member function Increment that increments the current Date object by one. The ++ operator is being overloaded to postincrement an object of type Date. Select the correct implementation:

Date Date::operator++( int )
{
Date temp = *this;
Increment();
return *temp;
}.

Date Date::operator++( int )
{
Increment();
Date temp = *this;
return temp;
}.

Date Date::operator++( int )
{
Date temp = *this;
return this;
temp.Increment();
}.

Date Date::operator++( int )
{
Date temp = *this;
Increment();
return temp;
}.

Section 11.13 Standard Library Class string
11.13 Q1: Which of the following is      False?

b. Class string provides bounds checking in its member function at.
d. An exception is thrown. if the argument to string’s at member function is an invalid subscript.
Class string’s overloaded [] operator returns a vector element as an rvalue or an lvalue, depending on the context.
A string can be defined to store any data type.
Section 11.14 explicit Constructors
11.14 Q1: An explicit constructor:

Cannot be called outside of the class it is declared in.
Does not initialize its class’s data members.
Can be implicitly called by the compiler to perform a data type conversion.
Must take exactly one argument.
Section 10.2 const (Constant) Objects and const Member Functions
10.2 Q1: Which of the following statements will not produce a syntax error?
Defining a const member function that modifies a data member of the object.
Declaring an object to be const.
Declaring a constructor to be const.
Invoking a non-const member function on a const object.

10.2 Q2: The code fragment:
Increment::Increment( int c, int i )
: increment ( i )
{
count = c;
}
does not cause any compilation errors. This tells you that:
increment must be a const variable.
count must be a const variable.
increment must be a non-const variable.
count must be a non-const variable.

Section 10.3 Composition: Objects as Members of Classes
10.3 Q1: When composition (one object having another object as a member) is used:
Member objects are destructed last, in the order they are declared in the host’s class.
The host object is constructed first and then the member objects are placed into it.
Member objects are constructed first, in the order they are declared in the host’s class.
Member objects are constructed first, in the order they appear in the host constructor’s initializer list.

10.3 Q2: An error occurs if:
A non-reference, non-const, primitive data member is initialized in the member initialization list.
An object data member is not initialized in the member initialization list and does not have a default constructor.
An object data member is not initialized in the member initialization list.
An object data member does not have a default constructor.

Section 10.4 friend Functions and friend Classes
10.4 Q1:
If the line:
friend class A;
appears in class B,and the line:
friend class B;
appears in class C,then:
Class A can access private variables of class B.
Class A is a friend of class C.
Class B can access class A’s private variables.
Class C can call class A’s private member functions.

10.4 Q2: Which of the following is not true about friend functions and friend classes?
A class can either grant friendship to or take friendship from another class using the friend keyword.
The friendship relationship is neither symmetric nor transitive.
A friend of a class can access all of its private data member and member functions.
A friend declaration can appear anywhere in a class definition.

Section 10.5 Using the this Pointer
10.5 Q1: For a non-constant member function of class Test, the this pointer has type:
const Test *.
Test * const.
const Test * const.
Test const *.

10.5 Q2: Inside a function definition for a member function of an object with data element x, which of the following is not equivalent to this->x:
(* (& (*this) ) ).x.
(*this).x.
*this.x.
x.

10.5 Q3: Assume that t is an object of class Test, which has member functions a(), b(), c() and d(). If the functions a(), b() and c() all return references to an object of class Test (using the dereferenced this pointer) and function d() is declared void, which of the following statements will not produce a syntax error:
t.a().b().d();.
t.d().c();.
t.a().t.d();.
a().b().t;.

Section 10.6 Dynamic Memory Management with Operators new and delete
10.6 Q1: Which of the following isFalse about the new operator and the object for which it allocates memory?
It automatically destroys the object after main is exited.
It returns a pointer.
It calls the object’s constructor.
It does not require the size of the object to be explicitly specified in the new expression.

10.6 Q2: The delete operator:
Is called implicitly at the end of a program.
Must be told which destructor to call when destroying an object.
Can delete an entire array of objects declared using new.
Can terminate the program.

Section 10.7 static Class Members
10.7 Q1: If Americans are objects of the same class, which of the following attributes would most likely be represented by a static variable of that class?
Age.
Favorite food.
Place of birth.
The President.

10.7 Q2: static data members of a certain class:
Cannot be changed, even by objects of the same that class.
Can be accessed only if an object of that class exists.
Have class scope.
Can only be changed by static member functions.

10.7 Q3: static member functions:
Can be declared const as well.
Can use the this pointer.
Cannot be called until an object of their class is instantiated.
Can only access other static member functions and static data members.

Section 10.8 Data Abstraction and Information Hiding
10.8 Q1: Which of the following is not an abstract data type?
An ASCII character.
A for loop.
An int.
A used-defined class.

10.8 Q2: Which of the following are true about an abstract data type?
I.Captures a data representation.
II.Defines the operations that are allowed on its data.
III.Replaces structured programming.
I and II.
I and III.
I, II and III.
II and III.

Section 10.8.1 Example: Array Abstract Data Type
10.8.1 Q1: Which of the following capabilities do “raw” C++ arrays not provide?
Dynamic size expansion to accommodate more elements.
Array comparison.
Subscript range checking.
“Raw” arrays do not provide any of the above capabilities.

Section 10.8.2 Example: String Abstract Data Type

10.8.2 Q1: Instead of including a string data type among C++’s built-in data types, C++: Was designed to include mechanisms for creating and implementing string abstract data types through classes.
Was designed to include mechanisms for creating and implementing string abstract data types through classes.
Forces the programmer to make do with char array strings.
Chose to ignore the need for a string data type.
None of the above.

Section 10.8.3 Example: Queue Abstract Data Type
10.8.3 Q1: The numbers 3, 2, 5, 7 are enqueued in a queue in that order, then three numbers are dequeued, and finally 3, 7, 9, 4 are enqueued in that order. What is the first number in the queue (the next number to be dequeued)?
3.
7.
9.
4.

Section 10.9 Container Classes and Iterators
10.9 Q1: Which of the following is not a type of container (collection) class?
floats.
Stacks.
Arrays.

Section 10.10 Proxy Classes
10.10 Q1: Proxy classes are best described as an example of:
Structured programming.
Object-oriented programming (as used in the text).
Information hiding.
Utility functions.

10.10 Q2: In addition to hiding the implementation details that the ordinary method of “separating implementation from interface” would hide, using a proxy class also hides:
The definition of access functions.
The definition of inline functions.
The definition of constructors and the destructor.
The names of private data members.