Deck 9: Understanding Friends and Overloading Operators
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
Match between columns
سؤال
Match between columns
سؤال
سؤال
Match between columns
سؤال
Match between columns
سؤال
سؤال
سؤال
Match between columns
سؤال
Match between columns
سؤال
Match between columns
سؤال
Match between columns
سؤال
Match between columns
فتح الحزمة
قم بالتسجيل لفتح البطاقات في هذه المجموعة!
Unlock Deck
Unlock Deck
1/52
العب
ملء الشاشة (f)
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) ||
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
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();
A) void applyTransaction(Customer, Transaction):friend;
B) friend void applyTransaction(Customer, Transaction);
C) friend void applyTransaction():Customer, Transaction;
D) friend void applyTransaction();
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 52 في هذه المجموعة.
فتح الحزمة
k this deck
5
When you overload the operator[]() function for a class, the parameter is required to be an integer.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 52 في هذه المجموعة.
فتح الحزمة
k this deck
6
The operator++() function overloads the ____ operator.
A) increment
B) pointer-to-member
C) address
D) addition
A) increment
B) pointer-to-member
C) address
D) addition
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 52 في هذه المجموعة.
فتح الحزمة
k this deck
7
The ____ operator has left-to-right associativity.
A) !
B) &
C) ~
D) ->
A) !
B) &
C) ~
D) ->
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 52 في هذه المجموعة.
فتح الحزمة
k this deck
8
The operator>>() function overloads the ____ operator.
A) less than
B) pointer-to-member
C) insertion
D) extraction
A) less than
B) pointer-to-member
C) insertion
D) extraction
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 52 في هذه المجموعة.
فتح الحزمة
k this deck
9
The C++ friend relationship is always one-sided.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 52 في هذه المجموعة.
فتح الحزمة
k this deck
10
Which of the following operators has a different precedence than the others?
A) ++
B) []
C) ::
D) .
A) ++
B) []
C) ::
D) .
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 52 في هذه المجموعة.
فتح الحزمة
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
A) chain
B) link
C) overload
D) stack
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 52 في هذه المجموعة.
فتح الحزمة
k this deck
12
The ____ operator is a binary operator.
A) ~
B) %
C) ->*
D) !
A) ~
B) %
C) ->*
D) !
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 52 في هذه المجموعة.
فتح الحزمة
k this deck
13
Which of the following operators has the lowest precedence?
A) new
B) &&
C) ::
D) .
A) new
B) &&
C) ::
D) .
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 52 في هذه المجموعة.
فتح الحزمة
k this deck
14
The name of the function that overloads the + symbol is the ____ function.
A) op+()
B) +()
C) +operator()
D) operator+()
A) op+()
B) +()
C) +operator()
D) operator+()
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 52 في هذه المجموعة.
فتح الحزمة
k this deck
15
The ____ operator is a unary operator.
A) >>
B) %
C) &
D) /
A) >>
B) %
C) &
D) /
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 52 في هذه المجموعة.
فتح الحزمة
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();
A) Inventory& operator++(int);
B) Inventory& operator++();
C) Inventory& ++operator(int);
D) Inventory& ++operator();
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 52 في هذه المجموعة.
فتح الحزمة
k this deck
17
The ____ operator has right-to-left associativity.
A) !
B) %
C) ->*
D) ->
A) !
B) %
C) ->*
D) ->
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 52 في هذه المجموعة.
فتح الحزمة
k this deck
18
You are required to use the word friend within the function name of a friend function.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 52 في هذه المجموعة.
فتح الحزمة
k this deck
19
The = operator() function overloads the assignment operator.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 52 في هذه المجموعة.
فتح الحزمة
k this deck
20
The operator function overloads the ____ operator.
A) greater than
B) pointer-to-member
C) insertion
D) extraction
A) greater than
B) pointer-to-member
C) insertion
D) extraction
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 52 في هذه المجموعة.
فتح الحزمة
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();
A) Inventory& operator++(int);
B) Inventory& operator++();
C) Inventory& ++operator(int);
D) Inventory& ++operator();
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 52 في هذه المجموعة.
فتح الحزمة
k this deck
22
Distinguish between the terms overloading and polymorphism.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 52 في هذه المجموعة.
فتح الحزمة
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.
#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.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 52 في هذه المجموعة.
فتح الحزمة
k this deck
24
To use arithmetic symbols with your own objects, you must ____________________ the symbols.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 52 في هذه المجموعة.
فتح الحزمة
k this deck
25
The subscript operator, ____, is declared like any other function.
A) operator
B) operator{}
C) operator[]
D) operator()
A) operator
B) operator{}
C) operator[]
D) operator()
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 52 في هذه المجموعة.
فتح الحزمة
k this deck
26
In C++, you use the ____ operator to dynamically allocate memory.
A) new
B) ++
C) +=
D) create
A) new
B) ++
C) +=
D) create
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 52 في هذه المجموعة.
فتح الحزمة
k this deck
27
Can operators be overloaded for the C++ built-in types? Explain.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 52 في هذه المجموعة.
فتح الحزمة
k this deck
28
C++ ____________________ are the symbols you use to perform operations on objects.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 52 في هذه المجموعة.
فتح الحزمة
k this deck
29
A(n) ____________________ class is a class in which all functions can access the non-public members of another class.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 52 في هذه المجموعة.
فتح الحزمة
k this deck
30
The ____ operator frees previously allocated memory.
A) deallocate
B) delete
C) --
D) -=
A) deallocate
B) delete
C) --
D) -=
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 52 في هذه المجموعة.
فتح الحزمة
k this deck
31
Which are the five operators that cannot be overloaded in C++?
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 52 في هذه المجموعة.
فتح الحزمة
k this deck
32
When would you want to use friend functions?
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 52 في هذه المجموعة.
فتح الحزمة
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
A) assign
B) allocate
C) append
D) increment
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 52 في هذه المجموعة.
فتح الحزمة
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.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 52 في هذه المجموعة.
فتح الحزمة
k this deck
35
When do you use encapsulation and data hiding?
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 52 في هذه المجموعة.
فتح الحزمة
k this deck
36
The * operator might mean multiplication or be used to ____________________ a pointer.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 52 في هذه المجموعة.
فتح الحزمة
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()
A) operator
B) operator{}
C) operator
D) operator()
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 52 في هذه المجموعة.
فتح الحزمة
k this deck
38
The ____________________ function overloads the decrement operator.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 52 في هذه المجموعة.
فتح الحزمة
k this deck
39
Can overloaded functions be friends? If so, how?
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 52 في هذه المجموعة.
فتح الحزمة
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.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 52 في هذه المجموعة.
فتح الحزمة
k this deck
41
Match between columns
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 52 في هذه المجموعة.
فتح الحزمة
k this deck
42
Match between columns
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 52 في هذه المجموعة.
فتح الحزمة
k this deck
43
Provide an example of chained operations and explain how you can overload operators to allow this type of operation.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 52 في هذه المجموعة.
فتح الحزمة
k this deck
44
Match between columns
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 52 في هذه المجموعة.
فتح الحزمة
k this deck
45
Match between columns
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 52 في هذه المجموعة.
فتح الحزمة
k this deck
46
When you use the new operator, is the memory allocation always successful? Explain.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 52 في هذه المجموعة.
فتح الحزمة
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];
}
}
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];
}
}
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 52 في هذه المجموعة.
فتح الحزمة
k this deck
48
Match between columns
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 52 في هذه المجموعة.
فتح الحزمة
k this deck
49
Match between columns
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 52 في هذه المجموعة.
فتح الحزمة
k this deck
50
Match between columns
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 52 في هذه المجموعة.
فتح الحزمة
k this deck
51
Match between columns
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 52 في هذه المجموعة.
فتح الحزمة
k this deck
52
Match between columns
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 52 في هذه المجموعة.
فتح الحزمة
k this deck