Deck 11: Operator Overloading; String and Array Objects

ملء الشاشة (f)
exit full mode
سؤال
Which of the following is false?

A) An entire non-char array cannot be input or output at once.
B) Two arrays cannot be meaningfully compared with equality or relational operators.
C) Arrays cannot be assigned to one another i.e., array1 = array2;).
D) C++ ensures that you cannot "walk off" either end of an array.
استخدم زر المسافة أو
up arrow
down arrow
لقلب البطاقة.
سؤال
Which statement about operator overloading is false?

A) New operators can never be created.
B) Certain overloaded operators can change the number of arguments they take.
C) The precedence of an operator cannot be changed by overloading.
D) Overloading cannot change how an operator works on built-in types.
سؤال
To use an operator on user-defined class objects, operator overloading:

A) Must always be used.
B) Must always be used, with three exceptions.
C) Must never be used, with three exceptions.
D) Must never be used.
سؤال
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?

A) y = y operator+= z
B) y.operator+= z )
C) y = y + z
D) y operator+= y + z )
سؤال
Which of the following operators can be overloaded as a global function?

A) )
B) []
C) +=
D) ==
سؤال
For operators overloaded as non-static member functions:

A) Binary operators can have two arguments and unary operators can have one.
B) Both binary and unary operators take one argument.
C) Binary operators can have one argument, and unary operators cannot have any.
D) Neither binary nor unary operators can have arguments.
سؤال
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?

A) Time::operator double) const;
B) Time::static_cast double) const;
C) Time::operator_castdouble) const;
D) Time::double) const;
سؤال
The prototypes of overloaded cast operator functions do not:

A) Specify the type they convert to.
B) Specify the type that is being converted.
C) Specify a return type.
D) Need to be defined inside the class whose objects are being converted.
سؤال
A copy constructor:

A) Is a constructor with only default arguments.
B) Is a constructor that initializes a newly declared object to the value of an existing object of the same class.
C) Is a constructor that takes no arguments.
D) None of the above.
سؤال
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:

A) ostream &operator<< ostream &output, const Data &dataToPrint )
B) ostream operator<< ostream &output, const Data &dataToPrint )
C) ostream &operator<< const Data &dataToPrint, ostream &output )
D) ostream operator<< const Data &dataToPrint, ostream &output )
سؤال
A copy constructor must receive its argument by reference because:

A) Otherwise the constructor will only make a copy of a pointer to an object.
B) Otherwise infinite recursion occurs.
C) The copy of the argument passed by value has function scope.
D) The pointer needs to know the address of the original data, not a temporary copy of it.
سؤال
The correct function name for overloading the addition +) operator is:

A) operator+
B) operator+)
C) operator:+
D) operator_+
سؤال
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) s.operator!)
B) s.operator! default_value1, default_value2,…)
C) operator! s )
D) A compiler error results because no arguments are given.
سؤال
To prevent class objects from being copied:

A) Make the overloaded assignment operator private.
B) Make the copy constructor private.
C) Both a) and b).
D) None of the above.
سؤال
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):

A) operator+ must be a member function of the class from which the objects are instantiated.
B) operator+ must be a non-member function.
C) 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.
D) The + operator cannot be overloaded to be commutative.
سؤال
Which situation would require the operator to be overloaded as a global function?

A) The overloaded operator is =.
B) The left most operand must be a class object or a reference to a class object).
C) The left operand is an int.
D) The operator returns a reference.
سؤال
Which of the following operators cannot be overloaded?

A) The . operator.
B) The -> operator.
C) The & operator.
D) The [ ] operator.
سؤال
To implicitly overload the += operator:

A) Only the + operator needs to be overloaded.
B) Only the = operator needs to be overloaded.
C) Both the + and = operators need to be overloaded.
D) The += operator cannot be overloaded implicitly.
سؤال
Conversion constructors:

A) Can have multiple arguments.
B) Can convert between user-defined types.
C) Are implicitly defined by the compiler if not explicitly written by the programmer.
D) Cannot convert built-in types to user defined types.
سؤال
The array subscript operator [], when overloaded, cannot:

A) Be used with linked list classes.
B) Take a float as an operand.
C) Take multiple values inside
D) Take user-defined objects as operands.
E)g., [4,8]).
سؤال
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?

A) "EF"
B) "EFGHI"
C) "CDEF"
D) "CD"
سؤال
Which of the following is false about the new operator and the object for which it allocates memory?

A) It calls the object's constructor.
B) It returns a pointer.
C) It does not require the size of the object to be explicitly specified in the new expression.
D) It automatically destroys the object after main is exited.
سؤال
The delete operator:

A) Can terminate the program.
B) Must be told which destructor to call when destroying an object.
C) Can delete an entire array of objects declared using new.
D) Is called implicitly at the end of a program.
سؤال
Proxy classes are best described as an example of:

A) Object-oriented programming as used in the text).
B) Structured programming.
C) Information hiding.
D) Utility functions.
سؤال
Because the postfix increment operator returns objects by value and the prefix increment operator returns objects by reference:

A) Prefix increment has slightly more overhead than postfix increment.
B) The postfix increment operator returns the actual incremented object with its new value.
C) Objects returned by postfix increment cannot be used in larger expressions.
D) The postfix increment operator typically returns a temporary object that contains the original value of the object before the increment occurred.
سؤال
In addition to hiding the implementation details that the ordinary method of "separating implementation from interface" would hide, using a proxy class also hides:

A) The definition of inline functions.
B) The definition of access functions.
C) The definition of constructors and the destructor.
D) The names of private data members.
سؤال
An explicit constructor:

A) Cannot be called outside of the class it is declared in.
B) Can be implicitly called by the compiler to perform a data type conversion.
C) Does not initialize its class's data members.
D) Must take exactly one argument.
سؤال
Which of the following is not a disadvantage of default memberwise copy with objects containing pointers?

A) Having the possibility of leaving a dangling pointer.
B) Allowing both objects to point to the same dynamically allocated storage.
C) Allowing the destructor of one object to be called while leaving the second pointer, to the same memory location, intact.
D) Requiring the explicit overloading of the assignment operator.
سؤال
Conversion constructors cannot:

A) Be applied implicitly.
B) Be used to convert the arguments for overloaded operators to the types needed by those overloaded operators.
C) Take exactly one argument.
D) Be used implicitly in series to match the needs of an overloaded operator.
سؤال
Which of the following is false?

A) A string can be defined to store any data type.
B) Class string provides bounds checking in its member function at.
C) Class string's overloaded [] operator returns a vector element as an rvalue or an lvalue, depending on the context.
D) An exception is thrown if the argument to string's at member function is an invalid subscript.
سؤال
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:

A) Date Date::operator++ int ) {
Date temp = *this;
Increment);
Return *temp;
}
B) Date Date::operator++ int ) {
Increment);
Date temp = *this;
Return temp;
}
C) Date Date::operator++ int ) {
Date temp = *this;
Return this;
Temp.Increment);
}
D) Date Date::operator++ int ) {
Date temp = *this;
Increment);
Return temp;
}
سؤال
The conventional way to distinguish between the overloaded preincrement and postincrement operators ++) is:

A) To assign a dummy value to preincrement.
B) To make the argument list of postincrement include an int.
C) To have the postincrement operator call the preincrement operator.
D) Implicitly done by the compiler.
فتح الحزمة
قم بالتسجيل لفتح البطاقات في هذه المجموعة!
Unlock Deck
Unlock Deck
1/32
auto play flashcards
العب
simple tutorial
ملء الشاشة (f)
exit full mode
Deck 11: Operator Overloading; String and Array Objects
1
Which of the following is false?

A) An entire non-char array cannot be input or output at once.
B) Two arrays cannot be meaningfully compared with equality or relational operators.
C) Arrays cannot be assigned to one another i.e., array1 = array2;).
D) C++ ensures that you cannot "walk off" either end of an array.
D
2
Which statement about operator overloading is false?

A) New operators can never be created.
B) Certain overloaded operators can change the number of arguments they take.
C) The precedence of an operator cannot be changed by overloading.
D) Overloading cannot change how an operator works on built-in types.
B
3
To use an operator on user-defined class objects, operator overloading:

A) Must always be used.
B) Must always be used, with three exceptions.
C) Must never be used, with three exceptions.
D) Must never be used.
B
4
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?

A) y = y operator+= z
B) y.operator+= z )
C) y = y + z
D) y operator+= y + z )
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 32 في هذه المجموعة.
فتح الحزمة
k this deck
5
Which of the following operators can be overloaded as a global function?

A) )
B) []
C) +=
D) ==
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 32 في هذه المجموعة.
فتح الحزمة
k this deck
6
For operators overloaded as non-static member functions:

A) Binary operators can have two arguments and unary operators can have one.
B) Both binary and unary operators take one argument.
C) Binary operators can have one argument, and unary operators cannot have any.
D) Neither binary nor unary operators can have arguments.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 32 في هذه المجموعة.
فتح الحزمة
k this deck
7
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?

A) Time::operator double) const;
B) Time::static_cast double) const;
C) Time::operator_castdouble) const;
D) Time::double) const;
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 32 في هذه المجموعة.
فتح الحزمة
k this deck
8
The prototypes of overloaded cast operator functions do not:

A) Specify the type they convert to.
B) Specify the type that is being converted.
C) Specify a return type.
D) Need to be defined inside the class whose objects are being converted.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 32 في هذه المجموعة.
فتح الحزمة
k this deck
9
A copy constructor:

A) Is a constructor with only default arguments.
B) Is a constructor that initializes a newly declared object to the value of an existing object of the same class.
C) Is a constructor that takes no arguments.
D) None of the above.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 32 في هذه المجموعة.
فتح الحزمة
k this deck
10
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:

A) ostream &operator<< ostream &output, const Data &dataToPrint )
B) ostream operator<< ostream &output, const Data &dataToPrint )
C) ostream &operator<< const Data &dataToPrint, ostream &output )
D) ostream operator<< const Data &dataToPrint, ostream &output )
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 32 في هذه المجموعة.
فتح الحزمة
k this deck
11
A copy constructor must receive its argument by reference because:

A) Otherwise the constructor will only make a copy of a pointer to an object.
B) Otherwise infinite recursion occurs.
C) The copy of the argument passed by value has function scope.
D) The pointer needs to know the address of the original data, not a temporary copy of it.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 32 في هذه المجموعة.
فتح الحزمة
k this deck
12
The correct function name for overloading the addition +) operator is:

A) operator+
B) operator+)
C) operator:+
D) operator_+
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 32 في هذه المجموعة.
فتح الحزمة
k this deck
13
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) s.operator!)
B) s.operator! default_value1, default_value2,…)
C) operator! s )
D) A compiler error results because no arguments are given.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 32 في هذه المجموعة.
فتح الحزمة
k this deck
14
To prevent class objects from being copied:

A) Make the overloaded assignment operator private.
B) Make the copy constructor private.
C) Both a) and b).
D) None of the above.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 32 في هذه المجموعة.
فتح الحزمة
k this deck
15
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):

A) operator+ must be a member function of the class from which the objects are instantiated.
B) operator+ must be a non-member function.
C) 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.
D) The + operator cannot be overloaded to be commutative.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 32 في هذه المجموعة.
فتح الحزمة
k this deck
16
Which situation would require the operator to be overloaded as a global function?

A) The overloaded operator is =.
B) The left most operand must be a class object or a reference to a class object).
C) The left operand is an int.
D) The operator returns a reference.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 32 في هذه المجموعة.
فتح الحزمة
k this deck
17
Which of the following operators cannot be overloaded?

A) The . operator.
B) The -> operator.
C) The & operator.
D) The [ ] operator.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 32 في هذه المجموعة.
فتح الحزمة
k this deck
18
To implicitly overload the += operator:

A) Only the + operator needs to be overloaded.
B) Only the = operator needs to be overloaded.
C) Both the + and = operators need to be overloaded.
D) The += operator cannot be overloaded implicitly.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 32 في هذه المجموعة.
فتح الحزمة
k this deck
19
Conversion constructors:

A) Can have multiple arguments.
B) Can convert between user-defined types.
C) Are implicitly defined by the compiler if not explicitly written by the programmer.
D) Cannot convert built-in types to user defined types.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 32 في هذه المجموعة.
فتح الحزمة
k this deck
20
The array subscript operator [], when overloaded, cannot:

A) Be used with linked list classes.
B) Take a float as an operand.
C) Take multiple values inside
D) Take user-defined objects as operands.
E)g., [4,8]).
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 32 في هذه المجموعة.
فتح الحزمة
k this deck
21
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?

A) "EF"
B) "EFGHI"
C) "CDEF"
D) "CD"
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 32 في هذه المجموعة.
فتح الحزمة
k this deck
22
Which of the following is false about the new operator and the object for which it allocates memory?

A) It calls the object's constructor.
B) It returns a pointer.
C) It does not require the size of the object to be explicitly specified in the new expression.
D) It automatically destroys the object after main is exited.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 32 في هذه المجموعة.
فتح الحزمة
k this deck
23
The delete operator:

A) Can terminate the program.
B) Must be told which destructor to call when destroying an object.
C) Can delete an entire array of objects declared using new.
D) Is called implicitly at the end of a program.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 32 في هذه المجموعة.
فتح الحزمة
k this deck
24
Proxy classes are best described as an example of:

A) Object-oriented programming as used in the text).
B) Structured programming.
C) Information hiding.
D) Utility functions.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 32 في هذه المجموعة.
فتح الحزمة
k this deck
25
Because the postfix increment operator returns objects by value and the prefix increment operator returns objects by reference:

A) Prefix increment has slightly more overhead than postfix increment.
B) The postfix increment operator returns the actual incremented object with its new value.
C) Objects returned by postfix increment cannot be used in larger expressions.
D) The postfix increment operator typically returns a temporary object that contains the original value of the object before the increment occurred.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 32 في هذه المجموعة.
فتح الحزمة
k this deck
26
In addition to hiding the implementation details that the ordinary method of "separating implementation from interface" would hide, using a proxy class also hides:

A) The definition of inline functions.
B) The definition of access functions.
C) The definition of constructors and the destructor.
D) The names of private data members.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 32 في هذه المجموعة.
فتح الحزمة
k this deck
27
An explicit constructor:

A) Cannot be called outside of the class it is declared in.
B) Can be implicitly called by the compiler to perform a data type conversion.
C) Does not initialize its class's data members.
D) Must take exactly one argument.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 32 في هذه المجموعة.
فتح الحزمة
k this deck
28
Which of the following is not a disadvantage of default memberwise copy with objects containing pointers?

A) Having the possibility of leaving a dangling pointer.
B) Allowing both objects to point to the same dynamically allocated storage.
C) Allowing the destructor of one object to be called while leaving the second pointer, to the same memory location, intact.
D) Requiring the explicit overloading of the assignment operator.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 32 في هذه المجموعة.
فتح الحزمة
k this deck
29
Conversion constructors cannot:

A) Be applied implicitly.
B) Be used to convert the arguments for overloaded operators to the types needed by those overloaded operators.
C) Take exactly one argument.
D) Be used implicitly in series to match the needs of an overloaded operator.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 32 في هذه المجموعة.
فتح الحزمة
k this deck
30
Which of the following is false?

A) A string can be defined to store any data type.
B) Class string provides bounds checking in its member function at.
C) Class string's overloaded [] operator returns a vector element as an rvalue or an lvalue, depending on the context.
D) An exception is thrown if the argument to string's at member function is an invalid subscript.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 32 في هذه المجموعة.
فتح الحزمة
k this deck
31
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:

A) Date Date::operator++ int ) {
Date temp = *this;
Increment);
Return *temp;
}
B) Date Date::operator++ int ) {
Increment);
Date temp = *this;
Return temp;
}
C) Date Date::operator++ int ) {
Date temp = *this;
Return this;
Temp.Increment);
}
D) Date Date::operator++ int ) {
Date temp = *this;
Increment);
Return temp;
}
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 32 في هذه المجموعة.
فتح الحزمة
k this deck
32
The conventional way to distinguish between the overloaded preincrement and postincrement operators ++) is:

A) To assign a dummy value to preincrement.
B) To make the argument list of postincrement include an int.
C) To have the postincrement operator call the preincrement operator.
D) Implicitly done by the compiler.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 32 في هذه المجموعة.
فتح الحزمة
k this deck
locked card icon
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 32 في هذه المجموعة.