Deck 13: Operator Overloading and Templates

Full screen (f)
exit full mode
Question
To include the operator function operator+ as a nonmember function of the class rectangleType, its prototype in the definition of rectangleType is: ____ rectangleType operator+(const rectangleType&, const rectangleType&);

A) bool
B) int
C) double
D) friend
Use Space or
up arrow
down arrow
to flip the card.
Question
The declaration of a friend function cannot be placed within the private part of the class.
Question
A(n) ____ function is a nonmember function that has access to all members of the class.

A) access
B) protected
C) friend
D) void
Question
The return type of the function operator == is ____.

A) int
B) bool
C) char
D) void
Question
Both parameters of the function to overload the operator << are reference parameters.
Question
The function that overloads the ____ operator for a class must be declared as a member of the class.

A) ::
B) *
C) ->
D) +
Question
In C++, >> is used as a stream extraction operator and as a right shift operator.
Question
When writing the definition of a friend function, the name of the class and the scope resolution operator precede the name of the friend function in the function heading.
Question
Most operator functions can either be member functions or nonmember functions of a class.
Question
Which of the following function prototypes overloads the != operator for the class rectangleType?

A) bool operator!=(rectangle&) const;
B) bool operator!=(const rectangleType&) const;
C) int operator!=(const rectangleType) const;
D) int operator!=(rectangle&) const;
Question
Operators can be overloaded either for objects of the user-defined types, or for a combination of objects of the user-defined type and objects of the built-in type.
Question
When an object invokes a member function, the member function references the pointer ____ of the object.

A) object
B) it
C) this
D) address
Question
The general form of the functions to overload the binary operators as member functions of a class is returnType operator#(____ className&) const;.

A) class
B) const
C) *
D) &
Question
The name of the function to overload the operator <= is ____.

A) overload<=
B) <=new
C) operator<=
D) <=operator
Question
A friend function does not have access to the private data members of the class.
Question
The general syntax to overload the stream extraction operator >> for a class is ____.

A) istream& operator>>(istream&, className&);
B) const istream& operator>>(istream&, className&);
C) friend operator>>(istream&, className&);
D) friend istream& operator>>(istream&, className&);
Question
Operator functions typically return void.
Question
Every object of a class maintains a (hidden) pointer to itself, and the name of this pointer is ____.

A) self
B) object
C) it
D) this
Question
The associativity of the operator = is from right to left.
Question
In C++, operator is a reserved word.
Question
With the exception of the ____________________ operator and the member selection operator, operators must be overloaded to be used on class objects.
Question
Which of the following is the general syntax of the function prototype to overload the pre-increment operator ++ as a member function?

A) className operator++();
B) className operator++(int);
C) friend className operator++();
D) friend className operator++(int);
Question
When the post-increment operator is overloaded as a nonmember function of the class, the operator function has ____ parameter(s).

A) no
B) one
C) two
D) three
Question
A(n) ____________________ returns random numbers whose likelihoods correspond to a specific shape such as uniform or normal.
Question
Using a class ____________________ allows you to define an arrayListType that can process any type of list.
Question
Class templates are called ____ types.

A) polymorphic
B) structured
C) member
D) parameterized
Question
Suppose cType is a class template, which can take int as a parameter.The statement: ____ declares x to be an object of type cType, and the type passed to the class cType is int.

A) cType x;
B) cType int x;
C) cType int = x;
D) cType int :: x;
Question
Using a class template, you can write a single code segment for a set of related ____.

A) classes
B) functions
C) operators
D) constructors
Question
Which of the following is a built-in operation on classes?

A) increment
B) assignment
C) decrement
D) relational operators
Question
Suppose cType is a class template, and func is a member function of cType.The heading of the function definition of func is: ____.

A) template
FuncType cType == func(parameters)
B) template
FuncType cType
C) template
FuncType cType::func(parameters)
D) template
FuncType cTypefunc(parameters;
Question
The return type of the function to overload the operator >> must be a reference to a(n) ____ object.

A) iostream
B) ostream
C) stream
D) istream
Question
Which of the following is the general syntax of the function prototype to overload the post-increment operator as a member function?

A) className operator++();
B) friend className operator++();
C) className operator++(int);
D) friend className operator++(int);
Question
To overload the pre-increment (++) operator as a member of a class, requires ____ parameter(s).

A) no
B) one
C) two
D) three
Question
The general syntax for the function prototype to overload the assignment operator = for a class is ____.

A) friend className& operator=(const className&);
B) className& operator=(className&);
C) string className& operator=(className&);
D) const className& operator=(const className&);
Question
Which of the following is the syntax to declare the operator function operator[] as a member function of a class for nonconstant arrays?

A) Type& []operator(int index);
B) Type operator[](int index);
C) Type& operator[](int index);
D) Type [](int index);
Question
Which of the following is the general syntax of the function prototype to overload the pre-increment operator as a nonmember function?

A) className operator++();
B) friend className operator++();
C) className operator++(int);
D) friend className operator++(className&);
Question
Any function that overloads an operator is called a(n) ____________________ function.
Question
If you overload the binary arithmetic operator + as a member function, how many objects must be passed as parameters?

A) none
B) one
C) two
D) three
Question
The operators that cannot be overloaded are ., .*, ::, ?:, and ____________________.
Question
Which of the following is the syntax to declare the operator function operator[] as a member function of a class for constant arrays?

A) const Type& []operator(int index) const;
B) const Type& operator[](int index) const;
C) const Type& operator[](int index);
D) const Type [](int index) const;
Question
A(n) ____________________ constructor converts its argument to an object of the constructor's class.
Unlock Deck
Sign up to unlock the cards in this deck!
Unlock Deck
Unlock Deck
1/41
auto play flashcards
Play
simple tutorial
Full screen (f)
exit full mode
Deck 13: Operator Overloading and Templates
1
To include the operator function operator+ as a nonmember function of the class rectangleType, its prototype in the definition of rectangleType is: ____ rectangleType operator+(const rectangleType&, const rectangleType&);

A) bool
B) int
C) double
D) friend
D
2
The declaration of a friend function cannot be placed within the private part of the class.
False
3
A(n) ____ function is a nonmember function that has access to all members of the class.

A) access
B) protected
C) friend
D) void
C
4
The return type of the function operator == is ____.

A) int
B) bool
C) char
D) void
Unlock Deck
Unlock for access to all 41 flashcards in this deck.
Unlock Deck
k this deck
5
Both parameters of the function to overload the operator << are reference parameters.
Unlock Deck
Unlock for access to all 41 flashcards in this deck.
Unlock Deck
k this deck
6
The function that overloads the ____ operator for a class must be declared as a member of the class.

A) ::
B) *
C) ->
D) +
Unlock Deck
Unlock for access to all 41 flashcards in this deck.
Unlock Deck
k this deck
7
In C++, >> is used as a stream extraction operator and as a right shift operator.
Unlock Deck
Unlock for access to all 41 flashcards in this deck.
Unlock Deck
k this deck
8
When writing the definition of a friend function, the name of the class and the scope resolution operator precede the name of the friend function in the function heading.
Unlock Deck
Unlock for access to all 41 flashcards in this deck.
Unlock Deck
k this deck
9
Most operator functions can either be member functions or nonmember functions of a class.
Unlock Deck
Unlock for access to all 41 flashcards in this deck.
Unlock Deck
k this deck
10
Which of the following function prototypes overloads the != operator for the class rectangleType?

A) bool operator!=(rectangle&) const;
B) bool operator!=(const rectangleType&) const;
C) int operator!=(const rectangleType) const;
D) int operator!=(rectangle&) const;
Unlock Deck
Unlock for access to all 41 flashcards in this deck.
Unlock Deck
k this deck
11
Operators can be overloaded either for objects of the user-defined types, or for a combination of objects of the user-defined type and objects of the built-in type.
Unlock Deck
Unlock for access to all 41 flashcards in this deck.
Unlock Deck
k this deck
12
When an object invokes a member function, the member function references the pointer ____ of the object.

A) object
B) it
C) this
D) address
Unlock Deck
Unlock for access to all 41 flashcards in this deck.
Unlock Deck
k this deck
13
The general form of the functions to overload the binary operators as member functions of a class is returnType operator#(____ className&) const;.

A) class
B) const
C) *
D) &
Unlock Deck
Unlock for access to all 41 flashcards in this deck.
Unlock Deck
k this deck
14
The name of the function to overload the operator <= is ____.

A) overload<=
B) <=new
C) operator<=
D) <=operator
Unlock Deck
Unlock for access to all 41 flashcards in this deck.
Unlock Deck
k this deck
15
A friend function does not have access to the private data members of the class.
Unlock Deck
Unlock for access to all 41 flashcards in this deck.
Unlock Deck
k this deck
16
The general syntax to overload the stream extraction operator >> for a class is ____.

A) istream& operator>>(istream&, className&);
B) const istream& operator>>(istream&, className&);
C) friend operator>>(istream&, className&);
D) friend istream& operator>>(istream&, className&);
Unlock Deck
Unlock for access to all 41 flashcards in this deck.
Unlock Deck
k this deck
17
Operator functions typically return void.
Unlock Deck
Unlock for access to all 41 flashcards in this deck.
Unlock Deck
k this deck
18
Every object of a class maintains a (hidden) pointer to itself, and the name of this pointer is ____.

A) self
B) object
C) it
D) this
Unlock Deck
Unlock for access to all 41 flashcards in this deck.
Unlock Deck
k this deck
19
The associativity of the operator = is from right to left.
Unlock Deck
Unlock for access to all 41 flashcards in this deck.
Unlock Deck
k this deck
20
In C++, operator is a reserved word.
Unlock Deck
Unlock for access to all 41 flashcards in this deck.
Unlock Deck
k this deck
21
With the exception of the ____________________ operator and the member selection operator, operators must be overloaded to be used on class objects.
Unlock Deck
Unlock for access to all 41 flashcards in this deck.
Unlock Deck
k this deck
22
Which of the following is the general syntax of the function prototype to overload the pre-increment operator ++ as a member function?

A) className operator++();
B) className operator++(int);
C) friend className operator++();
D) friend className operator++(int);
Unlock Deck
Unlock for access to all 41 flashcards in this deck.
Unlock Deck
k this deck
23
When the post-increment operator is overloaded as a nonmember function of the class, the operator function has ____ parameter(s).

A) no
B) one
C) two
D) three
Unlock Deck
Unlock for access to all 41 flashcards in this deck.
Unlock Deck
k this deck
24
A(n) ____________________ returns random numbers whose likelihoods correspond to a specific shape such as uniform or normal.
Unlock Deck
Unlock for access to all 41 flashcards in this deck.
Unlock Deck
k this deck
25
Using a class ____________________ allows you to define an arrayListType that can process any type of list.
Unlock Deck
Unlock for access to all 41 flashcards in this deck.
Unlock Deck
k this deck
26
Class templates are called ____ types.

A) polymorphic
B) structured
C) member
D) parameterized
Unlock Deck
Unlock for access to all 41 flashcards in this deck.
Unlock Deck
k this deck
27
Suppose cType is a class template, which can take int as a parameter.The statement: ____ declares x to be an object of type cType, and the type passed to the class cType is int.

A) cType x;
B) cType int x;
C) cType int = x;
D) cType int :: x;
Unlock Deck
Unlock for access to all 41 flashcards in this deck.
Unlock Deck
k this deck
28
Using a class template, you can write a single code segment for a set of related ____.

A) classes
B) functions
C) operators
D) constructors
Unlock Deck
Unlock for access to all 41 flashcards in this deck.
Unlock Deck
k this deck
29
Which of the following is a built-in operation on classes?

A) increment
B) assignment
C) decrement
D) relational operators
Unlock Deck
Unlock for access to all 41 flashcards in this deck.
Unlock Deck
k this deck
30
Suppose cType is a class template, and func is a member function of cType.The heading of the function definition of func is: ____.

A) template
FuncType cType == func(parameters)
B) template
FuncType cType
C) template
FuncType cType::func(parameters)
D) template
FuncType cTypefunc(parameters;
Unlock Deck
Unlock for access to all 41 flashcards in this deck.
Unlock Deck
k this deck
31
The return type of the function to overload the operator >> must be a reference to a(n) ____ object.

A) iostream
B) ostream
C) stream
D) istream
Unlock Deck
Unlock for access to all 41 flashcards in this deck.
Unlock Deck
k this deck
32
Which of the following is the general syntax of the function prototype to overload the post-increment operator as a member function?

A) className operator++();
B) friend className operator++();
C) className operator++(int);
D) friend className operator++(int);
Unlock Deck
Unlock for access to all 41 flashcards in this deck.
Unlock Deck
k this deck
33
To overload the pre-increment (++) operator as a member of a class, requires ____ parameter(s).

A) no
B) one
C) two
D) three
Unlock Deck
Unlock for access to all 41 flashcards in this deck.
Unlock Deck
k this deck
34
The general syntax for the function prototype to overload the assignment operator = for a class is ____.

A) friend className& operator=(const className&);
B) className& operator=(className&);
C) string className& operator=(className&);
D) const className& operator=(const className&);
Unlock Deck
Unlock for access to all 41 flashcards in this deck.
Unlock Deck
k this deck
35
Which of the following is the syntax to declare the operator function operator[] as a member function of a class for nonconstant arrays?

A) Type& []operator(int index);
B) Type operator[](int index);
C) Type& operator[](int index);
D) Type [](int index);
Unlock Deck
Unlock for access to all 41 flashcards in this deck.
Unlock Deck
k this deck
36
Which of the following is the general syntax of the function prototype to overload the pre-increment operator as a nonmember function?

A) className operator++();
B) friend className operator++();
C) className operator++(int);
D) friend className operator++(className&);
Unlock Deck
Unlock for access to all 41 flashcards in this deck.
Unlock Deck
k this deck
37
Any function that overloads an operator is called a(n) ____________________ function.
Unlock Deck
Unlock for access to all 41 flashcards in this deck.
Unlock Deck
k this deck
38
If you overload the binary arithmetic operator + as a member function, how many objects must be passed as parameters?

A) none
B) one
C) two
D) three
Unlock Deck
Unlock for access to all 41 flashcards in this deck.
Unlock Deck
k this deck
39
The operators that cannot be overloaded are ., .*, ::, ?:, and ____________________.
Unlock Deck
Unlock for access to all 41 flashcards in this deck.
Unlock Deck
k this deck
40
Which of the following is the syntax to declare the operator function operator[] as a member function of a class for constant arrays?

A) const Type& []operator(int index) const;
B) const Type& operator[](int index) const;
C) const Type& operator[](int index);
D) const Type [](int index) const;
Unlock Deck
Unlock for access to all 41 flashcards in this deck.
Unlock Deck
k this deck
41
A(n) ____________________ constructor converts its argument to an object of the constructor's class.
Unlock Deck
Unlock for access to all 41 flashcards in this deck.
Unlock Deck
k this deck
locked card icon
Unlock Deck
Unlock for access to all 41 flashcards in this deck.