Deck 7: Using Classes
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Match between columns
Question
Match between columns
Question
Match between columns
Question
Match between columns
Question
Match between columns
Question
Question
Match between columns
Question
Match between columns
Question
Question
Match between columns
Question
Question
Match between columns
Unlock Deck
Sign up to unlock the cards in this deck!
Unlock Deck
Unlock Deck
1/56
Play
Full screen (f)
Deck 7: Using Classes
1
When a class field is ____, only one memory location is allocated, no matter how many objects of the class you instantiate.
A) const
B) static
C) void
D) private
A) const
B) static
C) void
D) private
B
2
Programmers sometimes refer to ____ as an example of using a "black box."
A) polymorphism
B) encapsulation
C) instantiation
D) abstraction
A) polymorphism
B) encapsulation
C) instantiation
D) abstraction
B
3
You ____ assign a value to a field in a class definition.
A) can
B) cannot
C) should
D) should not
A) can
B) cannot
C) should
D) should not
B
4
To ____ an object is to declare or create it.
A) instantiate
B) encapsulate
C) abstract
D) overload
A) instantiate
B) encapsulate
C) abstract
D) overload
Unlock Deck
Unlock for access to all 56 flashcards in this deck.
Unlock Deck
k this deck
5
The access modifier ____ means a class member cannot be accessed using any statements in any functions that are not also part of the class.
A) public
B) private
C) protected
D) static
A) public
B) private
C) protected
D) static
Unlock Deck
Unlock for access to all 56 flashcards in this deck.
Unlock Deck
k this deck
6
You must use both the class name and the ____ operator when you implement a member function, because they tie the function to the class and allow every instantiated object to use the function name.
A) address
B) dot
C) scope resolution
D) pointer-to-member
A) address
B) dot
C) scope resolution
D) pointer-to-member
Unlock Deck
Unlock for access to all 56 flashcards in this deck.
Unlock Deck
k this deck
7
The scope resolution operator is ____.
A) &
B) ::
C) *
D) ->
A) &
B) ::
C) *
D) ->
Unlock Deck
Unlock for access to all 56 flashcards in this deck.
Unlock Deck
k this deck
8
To use the function displayStudentData() of the object aSophmore that belongs to the class Student , the correct syntax is ____.
A) aSophmore.displayStudentData();
B) Student.displayStudentData();
C) aSophmore::displayStudentData();
D) *aSophmore.displayStudentData();
A) aSophmore.displayStudentData();
B) Student.displayStudentData();
C) aSophmore::displayStudentData();
D) *aSophmore.displayStudentData();
Unlock Deck
Unlock for access to all 56 flashcards in this deck.
Unlock Deck
k this deck
9
C++ is an extensible language.
Unlock Deck
Unlock for access to all 56 flashcards in this deck.
Unlock Deck
k this deck
10
The ____ section of a class contains the class name, variables (attributes), and function prototypes.
A) header
B) definition
C) declaration
D) implementation
A) header
B) definition
C) declaration
D) implementation
Unlock Deck
Unlock for access to all 56 flashcards in this deck.
Unlock Deck
k this deck
11
A C++ ____ is an instantiation of a class that can contain both data members and methods.
A) variable
B) field
C) structure
D) object
A) variable
B) field
C) structure
D) object
Unlock Deck
Unlock for access to all 56 flashcards in this deck.
Unlock Deck
k this deck
12
A(n) ____ language is one to which you can add your own data types.
A) low-level
B) high-level
C) extensible
D) object-oriented
A) low-level
B) high-level
C) extensible
D) object-oriented
Unlock Deck
Unlock for access to all 56 flashcards in this deck.
Unlock Deck
k this deck
13
You may use the this pointer instead of the class name and scope resolution operator when a local variable and a field name conflict.
Unlock Deck
Unlock for access to all 56 flashcards in this deck.
Unlock Deck
k this deck
14
All members of a class share a single storage location for a static data member of that same class.
Unlock Deck
Unlock for access to all 56 flashcards in this deck.
Unlock Deck
k this deck
15
When you create a class, you usually make data items public.
Unlock Deck
Unlock for access to all 56 flashcards in this deck.
Unlock Deck
k this deck
16
The value of a static field cannot be changed.
Unlock Deck
Unlock for access to all 56 flashcards in this deck.
Unlock Deck
k this deck
17
When you create a class, you usually make the functions private.
Unlock Deck
Unlock for access to all 56 flashcards in this deck.
Unlock Deck
k this deck
18
To ____ components is to contain them.
A) instantiate
B) abstract
C) declare
D) encapsulate
A) instantiate
B) abstract
C) declare
D) encapsulate
Unlock Deck
Unlock for access to all 56 flashcards in this deck.
Unlock Deck
k this deck
19
An abstract data type is a type defined by C++.
Unlock Deck
Unlock for access to all 56 flashcards in this deck.
Unlock Deck
k this deck
20
A class is a new data type you create that is more complex than the basic data types.
Unlock Deck
Unlock for access to all 56 flashcards in this deck.
Unlock Deck
k this deck
21
Consider the following class:
class Student
{
private:
int idNum;
string lastName;
double gradePointAverage;
};
Add a public function void displayStudentData() to the class definition and then write an implementation for the function.
class Student
{
private:
int idNum;
string lastName;
double gradePointAverage;
};
Add a public function void displayStudentData() to the class definition and then write an implementation for the function.
Unlock Deck
Unlock for access to all 56 flashcards in this deck.
Unlock Deck
k this deck
22
Why should you make class data fields private and not public?
Unlock Deck
Unlock for access to all 56 flashcards in this deck.
Unlock Deck
k this deck
23
A function that is a user of your class is a class ____________________.
Unlock Deck
Unlock for access to all 56 flashcards in this deck.
Unlock Deck
k this deck
24
The ______________________________ is constructed by using a dash followed by a right-angle bracket (or greater-than sign).
Unlock Deck
Unlock for access to all 56 flashcards in this deck.
Unlock Deck
k this deck
25
When may it be a good idea to make data public in a class?
Unlock Deck
Unlock for access to all 56 flashcards in this deck.
Unlock Deck
k this deck
26
____ variables are sometimes called class variables, class fields, or class-wide fields.
A) Public
B) Private
C) Constant
D) Static
A) Public
B) Private
C) Constant
D) Static
Unlock Deck
Unlock for access to all 56 flashcards in this deck.
Unlock Deck
k this deck
27
The only type of class member function that does not have a this pointer is a ____ member function.
A) const
B) static
C) public
D) private
A) const
B) static
C) public
D) private
Unlock Deck
Unlock for access to all 56 flashcards in this deck.
Unlock Deck
k this deck
28
Static functions ____ access non-static variables.
A) can
B) cannot
C) should
D) should not
A) can
B) cannot
C) should
D) should not
Unlock Deck
Unlock for access to all 56 flashcards in this deck.
Unlock Deck
k this deck
29
Write a class with three private fields and then modify it so that the fields are public. Show both versions.
Unlock Deck
Unlock for access to all 56 flashcards in this deck.
Unlock Deck
k this deck
30
The variable ____ is an example of a correct use of the this pointer.
A) *this.employeeIdNum
B) (*this).employeeIdNum
C) *(this.employeeIdNum)
D) *(this).employeeIdNum
A) *this.employeeIdNum
B) (*this).employeeIdNum
C) *(this.employeeIdNum)
D) *(this).employeeIdNum
Unlock Deck
Unlock for access to all 56 flashcards in this deck.
Unlock Deck
k this deck
31
Conventionally, object names begin with a(n) ____________________ letter.
Unlock Deck
Unlock for access to all 56 flashcards in this deck.
Unlock Deck
k this deck
32
When you use an object, the ____ operator, and a non-static function of the object's class, you actually pass the specific object's address to the function as an unseen argument.
A) scope resolution
B) conditional
C) dot
D) address
A) scope resolution
B) conditional
C) dot
D) address
Unlock Deck
Unlock for access to all 56 flashcards in this deck.
Unlock Deck
k this deck
33
When you do not want to declare an object, you can still access a static , class-wide field by using a function that is ____.
A) static
B) const
C) public
D) private
A) static
B) const
C) public
D) private
Unlock Deck
Unlock for access to all 56 flashcards in this deck.
Unlock Deck
k this deck
34
The ____ pointer is automatically supplied every time you call a non-static member function of a class.
A) this
B) super
C) const
D) void
A) this
B) super
C) const
D) void
Unlock Deck
Unlock for access to all 56 flashcards in this deck.
Unlock Deck
k this deck
35
Conventionally, class names begin with a(n) ____________________ letter.
Unlock Deck
Unlock for access to all 56 flashcards in this deck.
Unlock Deck
k this deck
36
ADT stands for ____________________.
Unlock Deck
Unlock for access to all 56 flashcards in this deck.
Unlock Deck
k this deck
37
____________________ variables belong to the class, and you can use them even if you never instantiate an object.
Unlock Deck
Unlock for access to all 56 flashcards in this deck.
Unlock Deck
k this deck
38
When you create an object, a block of ____________________ is set aside for the data members.
Unlock Deck
Unlock for access to all 56 flashcards in this deck.
Unlock Deck
k this deck
39
The ____ operator is the pointer-to-member operator.
A) ::
B) &
C) *
D) ->
A) ::
B) &
C) *
D) ->
Unlock Deck
Unlock for access to all 56 flashcards in this deck.
Unlock Deck
k this deck
40
A ____ class member exists, even when you have not instantiated any objects of the class.
A) public
B) private
C) static
D) const
A) public
B) private
C) static
D) const
Unlock Deck
Unlock for access to all 56 flashcards in this deck.
Unlock Deck
k this deck
41
Can you modify the this pointer? Why or why not?
Unlock Deck
Unlock for access to all 56 flashcards in this deck.
Unlock Deck
k this deck
42
What is the difference in memory allocation between a static and a non-static variable?
Unlock Deck
Unlock for access to all 56 flashcards in this deck.
Unlock Deck
k this deck
43
Write a class declaration that has three private fields and three functions that can be used to assign values to each of the data fields of the class. Write the implementation of one of the functions.
Unlock Deck
Unlock for access to all 56 flashcards in this deck.
Unlock Deck
k this deck
44
In what situation would you want to use the this pointer?
Unlock Deck
Unlock for access to all 56 flashcards in this deck.
Unlock Deck
k this deck
45
Match between columns
Unlock Deck
Unlock for access to all 56 flashcards in this deck.
Unlock Deck
k this deck
46
Match between columns
Unlock Deck
Unlock for access to all 56 flashcards in this deck.
Unlock Deck
k this deck
47
Match between columns
Unlock Deck
Unlock for access to all 56 flashcards in this deck.
Unlock Deck
k this deck
48
Match between columns
Unlock Deck
Unlock for access to all 56 flashcards in this deck.
Unlock Deck
k this deck
49
Match between columns
Unlock Deck
Unlock for access to all 56 flashcards in this deck.
Unlock Deck
k this deck
50
Should static fields always be constant? Explain your answer.
Unlock Deck
Unlock for access to all 56 flashcards in this deck.
Unlock Deck
k this deck
51
Match between columns
Unlock Deck
Unlock for access to all 56 flashcards in this deck.
Unlock Deck
k this deck
52
Match between columns
Unlock Deck
Unlock for access to all 56 flashcards in this deck.
Unlock Deck
k this deck
53
Consider the function shown below:
void Customer::setBalance(double balance)
{
Customer::balance = balance;
}
Why is the scope resolution operator needed within the function body?
void Customer::setBalance(double balance)
{
Customer::balance = balance;
}
Why is the scope resolution operator needed within the function body?
Unlock Deck
Unlock for access to all 56 flashcards in this deck.
Unlock Deck
k this deck
54
Match between columns
Unlock Deck
Unlock for access to all 56 flashcards in this deck.
Unlock Deck
k this deck
55
Should you use a static class member with an object name or with the class name?
Unlock Deck
Unlock for access to all 56 flashcards in this deck.
Unlock Deck
k this deck
56
Match between columns
Unlock Deck
Unlock for access to all 56 flashcards in this deck.
Unlock Deck
k this deck