Deck 9: Understanding Friends and Overloading Operators

Full screen (f)
exit full mode
Question
In addition to overloading, compilers often need to perform coercion or casting when the + symbol is used with mixed arithmetic.
Use Space or
up arrow
down arrow
to flip the card.
Question
Which of the following operators has the highest precedence?

A) new
B) %
C) ::
D) ||
Question
C++ ____ you to use the built-in precedence rules for your class operators.

A) encourages
B) forces
C) forbids
D) enables
Question
To use the applyTransaction() function as a friend to both the Customer and the Transaction class, you must use the following syntax: ____.

A) void applyTransaction(Customer, Transaction):friend;
B) friend void applyTransaction(Customer, Transaction);
C) friend void applyTransaction():Customer, Transaction;
D) friend void applyTransaction();
Question
When you overload the operator[]() function for a class, the parameter is required to be an integer.
Question
The operator++() function overloads the ____ operator.

A) increment
B) pointer-to-member
C) address
D) addition
Question
The ____ operator has left-to-right associativity.

A) !
B) &
C) ~
D) ->
Question
The operator>>() function overloads the ____ operator.

A) less than
B) pointer-to-member
C) insertion
D) extraction
Question
The C++ friend relationship is always one-sided.
Question
Which of the following operators has a different precedence than the others?

A) ++
B) []
C) ::
D) .
Question
To ____ operations is to allow several operators to be used within the same expression.

A) chain
B) link
C) overload
D) stack
Question
The ____ operator is a binary operator.

A) ~
B) %
C) ->*
D) !
Question
Which of the following operators has the lowest precedence?

A) new
B) &&
C) ::
D) .
Question
The name of the function that overloads the + symbol is the ____ function.

A) op+()
B) +()
C) +operator()
D) operator+()
Question
The ____ operator is a unary operator.

A) >>
B) %
C) &
D) /
Question
____ is an example of overloading the prefix increment operator.

A) Inventory& operator++(int);
B) Inventory& operator++();
C) Inventory& ++operator(int);
D) Inventory& ++operator();
Question
The ____ operator has right-to-left associativity.

A) !
B) %
C) ->*
D) ->
Question
You are required to use the word friend within the function name of a friend function.
Question
The = operator() function overloads the assignment operator.
Question
The operator function overloads the ____ operator.

A) greater than
B) pointer-to-member
C) insertion
D) extraction
Question
____ is an example of overloading the postfix increment operator.

A) Inventory& operator++(int);
B) Inventory& operator++();
C) Inventory& ++operator(int);
D) Inventory& ++operator();
Question
Distinguish between the terms overloading and polymorphism.
Question
Consider the following class declaration:
#include
using namespace std;
class Employee
{
private:
int idNum;
double salary;
public:
Employee(int, double);
double operator+(Employee);
};
Write an implementation for the operator+() function.
Question
To use arithmetic symbols with your own objects, you must ____________________ the symbols.
Question
The subscript operator, ____, is declared like any other function.

A) operator
B) operator{}
C) operator[]
D) operator()
Question
In C++, you use the ____ operator to dynamically allocate memory.

A) new
B) ++
C) +=
D) create
Question
Can operators be overloaded for the C++ built-in types? Explain.
Question
C++ ____________________ are the symbols you use to perform operations on objects.
Question
A(n) ____________________ class is a class in which all functions can access the non-public members of another class.
Question
The ____ operator frees previously allocated memory.

A) deallocate
B) delete
C) --
D) -=
Question
Which are the five operators that cannot be overloaded in C++?
Question
When would you want to use friend functions?
Question
To ____ memory for a field is to allot storage for and assign a name to it.

A) assign
B) allocate
C) append
D) increment
Question
When you allocate memory during the execution of a program (as opposed to when the program is compiled) you ____________________ allocate memory.
Question
When do you use encapsulation and data hiding?
Question
The * operator might mean multiplication or be used to ____________________ a pointer.
Question
You can use the ____ as an alternate way to make assignments to an object.

A) operator
B) operator{}
C) operator
D) operator()
Question
The ____________________ function overloads the decrement operator.
Question
Can overloaded functions be friends? If so, how?
Question
A(n) ____________________ function can access the non-public members of a class, even though the function itself is not a member of the class.
Question
Match between columns
memory that is no longer assigned to anything in an application
pure polymorphism
memory that is no longer assigned to anything in an application
deallocated memory
memory that is no longer assigned to anything in an application
parametric overloading
memory that is no longer assigned to anything in an application
signature
memory that is no longer assigned to anything in an application
operator overloading
memory that is no longer assigned to anything in an application
stacking
memory that is no longer assigned to anything in an application
associativity
memory that is no longer assigned to anything in an application
dummy parameter
memory that is no longer assigned to anything in an application
forward declaration
Question
Match between columns
a function's prototype
pure polymorphism
a function's prototype
deallocated memory
a function's prototype
parametric overloading
a function's prototype
signature
a function's prototype
operator overloading
a function's prototype
stacking
a function's prototype
associativity
a function's prototype
dummy parameter
a function's prototype
forward declaration
Question
Provide an example of chained operations and explain how you can overload operators to allow this type of operation.
Question
Match between columns
it is not used within the function but exists only to provide a different function prototype
pure polymorphism
it is not used within the function but exists only to provide a different function prototype
deallocated memory
it is not used within the function but exists only to provide a different function prototype
parametric overloading
it is not used within the function but exists only to provide a different function prototype
signature
it is not used within the function but exists only to provide a different function prototype
operator overloading
it is not used within the function but exists only to provide a different function prototype
stacking
it is not used within the function but exists only to provide a different function prototype
associativity
it is not used within the function but exists only to provide a different function prototype
dummy parameter
it is not used within the function but exists only to provide a different function prototype
forward declaration
Question
Match between columns
multiple calls to the same operator function
pure polymorphism
multiple calls to the same operator function
deallocated memory
multiple calls to the same operator function
parametric overloading
multiple calls to the same operator function
signature
multiple calls to the same operator function
operator overloading
multiple calls to the same operator function
stacking
multiple calls to the same operator function
associativity
multiple calls to the same operator function
dummy parameter
multiple calls to the same operator function
forward declaration
Question
When you use the new operator, is the memory allocation always successful? Explain.
Question
Write a destructor for the following class:
class Classroom
{
private:
string *student;
int numStudents;
int gradeLevel;
public:
Classroom();
~Classroom();
void display();
};
Classroom::Classroom()
{
int x;
cout > gradeLevel;
cout > numStudents;
student = new string[numStudents];
for(x = 0; x > student[x];
}
}
Question
Match between columns
refers to the order in which actions within an expression are carried out
pure polymorphism
refers to the order in which actions within an expression are carried out
deallocated memory
refers to the order in which actions within an expression are carried out
parametric overloading
refers to the order in which actions within an expression are carried out
signature
refers to the order in which actions within an expression are carried out
operator overloading
refers to the order in which actions within an expression are carried out
stacking
refers to the order in which actions within an expression are carried out
associativity
refers to the order in which actions within an expression are carried out
dummy parameter
refers to the order in which actions within an expression are carried out
forward declaration
Question
Match between columns
process by which you apply operators to your own abstract data types
pure polymorphism
process by which you apply operators to your own abstract data types
deallocated memory
process by which you apply operators to your own abstract data types
parametric overloading
process by which you apply operators to your own abstract data types
signature
process by which you apply operators to your own abstract data types
operator overloading
process by which you apply operators to your own abstract data types
stacking
process by which you apply operators to your own abstract data types
associativity
process by which you apply operators to your own abstract data types
dummy parameter
process by which you apply operators to your own abstract data types
forward declaration
Question
Match between columns
statement that lets the compiler know that the class exists, and that the details will come later
pure polymorphism
statement that lets the compiler know that the class exists, and that the details will come later
deallocated memory
statement that lets the compiler know that the class exists, and that the details will come later
parametric overloading
statement that lets the compiler know that the class exists, and that the details will come later
signature
statement that lets the compiler know that the class exists, and that the details will come later
operator overloading
statement that lets the compiler know that the class exists, and that the details will come later
stacking
statement that lets the compiler know that the class exists, and that the details will come later
associativity
statement that lets the compiler know that the class exists, and that the details will come later
dummy parameter
statement that lets the compiler know that the class exists, and that the details will come later
forward declaration
Question
Match between columns
use of functions that are distinguished by their number or types of arguments
pure polymorphism
use of functions that are distinguished by their number or types of arguments
deallocated memory
use of functions that are distinguished by their number or types of arguments
parametric overloading
use of functions that are distinguished by their number or types of arguments
signature
use of functions that are distinguished by their number or types of arguments
operator overloading
use of functions that are distinguished by their number or types of arguments
stacking
use of functions that are distinguished by their number or types of arguments
associativity
use of functions that are distinguished by their number or types of arguments
dummy parameter
use of functions that are distinguished by their number or types of arguments
forward declaration
Question
Match between columns
one function body is used with a variety of arguments
pure polymorphism
one function body is used with a variety of arguments
deallocated memory
one function body is used with a variety of arguments
parametric overloading
one function body is used with a variety of arguments
signature
one function body is used with a variety of arguments
operator overloading
one function body is used with a variety of arguments
stacking
one function body is used with a variety of arguments
associativity
one function body is used with a variety of arguments
dummy parameter
one function body is used with a variety of arguments
forward declaration
Unlock Deck
Sign up to unlock the cards in this deck!
Unlock Deck
Unlock Deck
1/52
auto play flashcards
Play
simple tutorial
Full screen (f)
exit full mode
Deck 9: Understanding Friends and Overloading Operators
1
In addition to overloading, compilers often need to perform coercion or casting when the + symbol is used with mixed arithmetic.
True
2
Which of the following operators has the highest precedence?

A) new
B) %
C) ::
D) ||
C
3
C++ ____ you to use the built-in precedence rules for your class operators.

A) encourages
B) forces
C) forbids
D) enables
B
4
To use the applyTransaction() function as a friend to both the Customer and the Transaction class, you must use the following syntax: ____.

A) void applyTransaction(Customer, Transaction):friend;
B) friend void applyTransaction(Customer, Transaction);
C) friend void applyTransaction():Customer, Transaction;
D) friend void applyTransaction();
Unlock Deck
Unlock for access to all 52 flashcards in this deck.
Unlock Deck
k this deck
5
When you overload the operator[]() function for a class, the parameter is required to be an integer.
Unlock Deck
Unlock for access to all 52 flashcards in this deck.
Unlock Deck
k this deck
6
The operator++() function overloads the ____ operator.

A) increment
B) pointer-to-member
C) address
D) addition
Unlock Deck
Unlock for access to all 52 flashcards in this deck.
Unlock Deck
k this deck
7
The ____ operator has left-to-right associativity.

A) !
B) &
C) ~
D) ->
Unlock Deck
Unlock for access to all 52 flashcards in this deck.
Unlock Deck
k this deck
8
The operator>>() function overloads the ____ operator.

A) less than
B) pointer-to-member
C) insertion
D) extraction
Unlock Deck
Unlock for access to all 52 flashcards in this deck.
Unlock Deck
k this deck
9
The C++ friend relationship is always one-sided.
Unlock Deck
Unlock for access to all 52 flashcards in this deck.
Unlock Deck
k this deck
10
Which of the following operators has a different precedence than the others?

A) ++
B) []
C) ::
D) .
Unlock Deck
Unlock for access to all 52 flashcards in this deck.
Unlock Deck
k this deck
11
To ____ operations is to allow several operators to be used within the same expression.

A) chain
B) link
C) overload
D) stack
Unlock Deck
Unlock for access to all 52 flashcards in this deck.
Unlock Deck
k this deck
12
The ____ operator is a binary operator.

A) ~
B) %
C) ->*
D) !
Unlock Deck
Unlock for access to all 52 flashcards in this deck.
Unlock Deck
k this deck
13
Which of the following operators has the lowest precedence?

A) new
B) &&
C) ::
D) .
Unlock Deck
Unlock for access to all 52 flashcards in this deck.
Unlock Deck
k this deck
14
The name of the function that overloads the + symbol is the ____ function.

A) op+()
B) +()
C) +operator()
D) operator+()
Unlock Deck
Unlock for access to all 52 flashcards in this deck.
Unlock Deck
k this deck
15
The ____ operator is a unary operator.

A) >>
B) %
C) &
D) /
Unlock Deck
Unlock for access to all 52 flashcards in this deck.
Unlock Deck
k this deck
16
____ is an example of overloading the prefix increment operator.

A) Inventory& operator++(int);
B) Inventory& operator++();
C) Inventory& ++operator(int);
D) Inventory& ++operator();
Unlock Deck
Unlock for access to all 52 flashcards in this deck.
Unlock Deck
k this deck
17
The ____ operator has right-to-left associativity.

A) !
B) %
C) ->*
D) ->
Unlock Deck
Unlock for access to all 52 flashcards in this deck.
Unlock Deck
k this deck
18
You are required to use the word friend within the function name of a friend function.
Unlock Deck
Unlock for access to all 52 flashcards in this deck.
Unlock Deck
k this deck
19
The = operator() function overloads the assignment operator.
Unlock Deck
Unlock for access to all 52 flashcards in this deck.
Unlock Deck
k this deck
20
The operator function overloads the ____ operator.

A) greater than
B) pointer-to-member
C) insertion
D) extraction
Unlock Deck
Unlock for access to all 52 flashcards in this deck.
Unlock Deck
k this deck
21
____ is an example of overloading the postfix increment operator.

A) Inventory& operator++(int);
B) Inventory& operator++();
C) Inventory& ++operator(int);
D) Inventory& ++operator();
Unlock Deck
Unlock for access to all 52 flashcards in this deck.
Unlock Deck
k this deck
22
Distinguish between the terms overloading and polymorphism.
Unlock Deck
Unlock for access to all 52 flashcards in this deck.
Unlock Deck
k this deck
23
Consider the following class declaration:
#include
using namespace std;
class Employee
{
private:
int idNum;
double salary;
public:
Employee(int, double);
double operator+(Employee);
};
Write an implementation for the operator+() function.
Unlock Deck
Unlock for access to all 52 flashcards in this deck.
Unlock Deck
k this deck
24
To use arithmetic symbols with your own objects, you must ____________________ the symbols.
Unlock Deck
Unlock for access to all 52 flashcards in this deck.
Unlock Deck
k this deck
25
The subscript operator, ____, is declared like any other function.

A) operator
B) operator{}
C) operator[]
D) operator()
Unlock Deck
Unlock for access to all 52 flashcards in this deck.
Unlock Deck
k this deck
26
In C++, you use the ____ operator to dynamically allocate memory.

A) new
B) ++
C) +=
D) create
Unlock Deck
Unlock for access to all 52 flashcards in this deck.
Unlock Deck
k this deck
27
Can operators be overloaded for the C++ built-in types? Explain.
Unlock Deck
Unlock for access to all 52 flashcards in this deck.
Unlock Deck
k this deck
28
C++ ____________________ are the symbols you use to perform operations on objects.
Unlock Deck
Unlock for access to all 52 flashcards in this deck.
Unlock Deck
k this deck
29
A(n) ____________________ class is a class in which all functions can access the non-public members of another class.
Unlock Deck
Unlock for access to all 52 flashcards in this deck.
Unlock Deck
k this deck
30
The ____ operator frees previously allocated memory.

A) deallocate
B) delete
C) --
D) -=
Unlock Deck
Unlock for access to all 52 flashcards in this deck.
Unlock Deck
k this deck
31
Which are the five operators that cannot be overloaded in C++?
Unlock Deck
Unlock for access to all 52 flashcards in this deck.
Unlock Deck
k this deck
32
When would you want to use friend functions?
Unlock Deck
Unlock for access to all 52 flashcards in this deck.
Unlock Deck
k this deck
33
To ____ memory for a field is to allot storage for and assign a name to it.

A) assign
B) allocate
C) append
D) increment
Unlock Deck
Unlock for access to all 52 flashcards in this deck.
Unlock Deck
k this deck
34
When you allocate memory during the execution of a program (as opposed to when the program is compiled) you ____________________ allocate memory.
Unlock Deck
Unlock for access to all 52 flashcards in this deck.
Unlock Deck
k this deck
35
When do you use encapsulation and data hiding?
Unlock Deck
Unlock for access to all 52 flashcards in this deck.
Unlock Deck
k this deck
36
The * operator might mean multiplication or be used to ____________________ a pointer.
Unlock Deck
Unlock for access to all 52 flashcards in this deck.
Unlock Deck
k this deck
37
You can use the ____ as an alternate way to make assignments to an object.

A) operator
B) operator{}
C) operator
D) operator()
Unlock Deck
Unlock for access to all 52 flashcards in this deck.
Unlock Deck
k this deck
38
The ____________________ function overloads the decrement operator.
Unlock Deck
Unlock for access to all 52 flashcards in this deck.
Unlock Deck
k this deck
39
Can overloaded functions be friends? If so, how?
Unlock Deck
Unlock for access to all 52 flashcards in this deck.
Unlock Deck
k this deck
40
A(n) ____________________ function can access the non-public members of a class, even though the function itself is not a member of the class.
Unlock Deck
Unlock for access to all 52 flashcards in this deck.
Unlock Deck
k this deck
41
Match between columns
memory that is no longer assigned to anything in an application
pure polymorphism
memory that is no longer assigned to anything in an application
deallocated memory
memory that is no longer assigned to anything in an application
parametric overloading
memory that is no longer assigned to anything in an application
signature
memory that is no longer assigned to anything in an application
operator overloading
memory that is no longer assigned to anything in an application
stacking
memory that is no longer assigned to anything in an application
associativity
memory that is no longer assigned to anything in an application
dummy parameter
memory that is no longer assigned to anything in an application
forward declaration
Unlock Deck
Unlock for access to all 52 flashcards in this deck.
Unlock Deck
k this deck
42
Match between columns
a function's prototype
pure polymorphism
a function's prototype
deallocated memory
a function's prototype
parametric overloading
a function's prototype
signature
a function's prototype
operator overloading
a function's prototype
stacking
a function's prototype
associativity
a function's prototype
dummy parameter
a function's prototype
forward declaration
Unlock Deck
Unlock for access to all 52 flashcards in this deck.
Unlock Deck
k this deck
43
Provide an example of chained operations and explain how you can overload operators to allow this type of operation.
Unlock Deck
Unlock for access to all 52 flashcards in this deck.
Unlock Deck
k this deck
44
Match between columns
it is not used within the function but exists only to provide a different function prototype
pure polymorphism
it is not used within the function but exists only to provide a different function prototype
deallocated memory
it is not used within the function but exists only to provide a different function prototype
parametric overloading
it is not used within the function but exists only to provide a different function prototype
signature
it is not used within the function but exists only to provide a different function prototype
operator overloading
it is not used within the function but exists only to provide a different function prototype
stacking
it is not used within the function but exists only to provide a different function prototype
associativity
it is not used within the function but exists only to provide a different function prototype
dummy parameter
it is not used within the function but exists only to provide a different function prototype
forward declaration
Unlock Deck
Unlock for access to all 52 flashcards in this deck.
Unlock Deck
k this deck
45
Match between columns
multiple calls to the same operator function
pure polymorphism
multiple calls to the same operator function
deallocated memory
multiple calls to the same operator function
parametric overloading
multiple calls to the same operator function
signature
multiple calls to the same operator function
operator overloading
multiple calls to the same operator function
stacking
multiple calls to the same operator function
associativity
multiple calls to the same operator function
dummy parameter
multiple calls to the same operator function
forward declaration
Unlock Deck
Unlock for access to all 52 flashcards in this deck.
Unlock Deck
k this deck
46
When you use the new operator, is the memory allocation always successful? Explain.
Unlock Deck
Unlock for access to all 52 flashcards in this deck.
Unlock Deck
k this deck
47
Write a destructor for the following class:
class Classroom
{
private:
string *student;
int numStudents;
int gradeLevel;
public:
Classroom();
~Classroom();
void display();
};
Classroom::Classroom()
{
int x;
cout > gradeLevel;
cout > numStudents;
student = new string[numStudents];
for(x = 0; x > student[x];
}
}
Unlock Deck
Unlock for access to all 52 flashcards in this deck.
Unlock Deck
k this deck
48
Match between columns
refers to the order in which actions within an expression are carried out
pure polymorphism
refers to the order in which actions within an expression are carried out
deallocated memory
refers to the order in which actions within an expression are carried out
parametric overloading
refers to the order in which actions within an expression are carried out
signature
refers to the order in which actions within an expression are carried out
operator overloading
refers to the order in which actions within an expression are carried out
stacking
refers to the order in which actions within an expression are carried out
associativity
refers to the order in which actions within an expression are carried out
dummy parameter
refers to the order in which actions within an expression are carried out
forward declaration
Unlock Deck
Unlock for access to all 52 flashcards in this deck.
Unlock Deck
k this deck
49
Match between columns
process by which you apply operators to your own abstract data types
pure polymorphism
process by which you apply operators to your own abstract data types
deallocated memory
process by which you apply operators to your own abstract data types
parametric overloading
process by which you apply operators to your own abstract data types
signature
process by which you apply operators to your own abstract data types
operator overloading
process by which you apply operators to your own abstract data types
stacking
process by which you apply operators to your own abstract data types
associativity
process by which you apply operators to your own abstract data types
dummy parameter
process by which you apply operators to your own abstract data types
forward declaration
Unlock Deck
Unlock for access to all 52 flashcards in this deck.
Unlock Deck
k this deck
50
Match between columns
statement that lets the compiler know that the class exists, and that the details will come later
pure polymorphism
statement that lets the compiler know that the class exists, and that the details will come later
deallocated memory
statement that lets the compiler know that the class exists, and that the details will come later
parametric overloading
statement that lets the compiler know that the class exists, and that the details will come later
signature
statement that lets the compiler know that the class exists, and that the details will come later
operator overloading
statement that lets the compiler know that the class exists, and that the details will come later
stacking
statement that lets the compiler know that the class exists, and that the details will come later
associativity
statement that lets the compiler know that the class exists, and that the details will come later
dummy parameter
statement that lets the compiler know that the class exists, and that the details will come later
forward declaration
Unlock Deck
Unlock for access to all 52 flashcards in this deck.
Unlock Deck
k this deck
51
Match between columns
use of functions that are distinguished by their number or types of arguments
pure polymorphism
use of functions that are distinguished by their number or types of arguments
deallocated memory
use of functions that are distinguished by their number or types of arguments
parametric overloading
use of functions that are distinguished by their number or types of arguments
signature
use of functions that are distinguished by their number or types of arguments
operator overloading
use of functions that are distinguished by their number or types of arguments
stacking
use of functions that are distinguished by their number or types of arguments
associativity
use of functions that are distinguished by their number or types of arguments
dummy parameter
use of functions that are distinguished by their number or types of arguments
forward declaration
Unlock Deck
Unlock for access to all 52 flashcards in this deck.
Unlock Deck
k this deck
52
Match between columns
one function body is used with a variety of arguments
pure polymorphism
one function body is used with a variety of arguments
deallocated memory
one function body is used with a variety of arguments
parametric overloading
one function body is used with a variety of arguments
signature
one function body is used with a variety of arguments
operator overloading
one function body is used with a variety of arguments
stacking
one function body is used with a variety of arguments
associativity
one function body is used with a variety of arguments
dummy parameter
one function body is used with a variety of arguments
forward declaration
Unlock Deck
Unlock for access to all 52 flashcards in this deck.
Unlock Deck
k this deck
locked card icon
Unlock Deck
Unlock for access to all 52 flashcards in this deck.