Exam #2 Review Flashcards

(141 cards)

1
Q

T/F: An Abstract data type (ADT) is a programmer-define data type that specifies the values the type can hold, the operations that can be performed on them, and how the operations will be implemented.

A

Fales

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

T/F: In C++ and other object-oriented programming languages, ADTs are normally implemented as classes

A

True

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

An object is a ___ of a class

A

instance

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

T/F: A class declaration creates an object

A

False

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

The bundling of an object’s data and functions together is called…

A

Encapsulation

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

The ___ is used to protect important data

A

private access specifier

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

Public members of a class object can be accessed from outside the class by using the…

A

dot operator

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

A C++ member function that sets or changes the value stored in a member variable is called

A

a mutator

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

T/F: A private member function may only be called from a function that is a member of the same class

A

True

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

T/F: A constructor is a public class function that gets called whenever you want to re-initialize an object’s member data

A

False

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

A constructor must have the same name as the…

A

class

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

The name of a destructor must begin with…

A

a tilde (~)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

A class may have ___ default constructor(s) and ____ destructor(s)

A

only one, only one

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

When a member function is defined outside of the class declaration, the function name must be qualified with the class name, followed by…

A

the scope resolution operator (::)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

If Square is the name of a class, which of the following statements would create a Square object named box…

A

Square box;

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

If setSide is a Square class function and box is a Square object, which of the following statements would set the length of box’s side to 5

A

box.setSide(5);

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
17
Q

T/F: A class can have a member variable that is an instance of another class. This is called object composition

A

True

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
18
Q

A structure variable is similar to a class object in which way?

A

Its data can be initialized with a constructor, and it can be passed to a function or returned from a function, but not. It has member data that is usually private and accessed through public member functions

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
19
Q

When an object or structure variable is passed to a function as a constant reference

A
  • More efficient than passing by value
  • Function cannot make any changes to the member variables
  • Function accesses the original object, rather than a copy of it
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
20
Q

What will the following code segment display?
enum Season {Spring, Summer, Fall, Winter} favoriteSeason;
favoriteSeason = Summer;
cout &laquo_space;favoriteSeason;

A

1

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
21
Q

Unlike regular variables, arrays can hold multiple….

A

values

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
22
Q

T/F: The amount of memory used by an array depends solely on the number of elements the array can hold

A

False

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
23
Q

To access an array element, use the array name and the element’s…

A

subscript

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
24
Q

T/F: If a C++ program contains the following array definition
int score[10];
the following statement would store 100 in the first array element;
score[1]=100;

A

False

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
25
The statement int grades[ ] = { 100, 90, 99, 80 }; is an example of
implicit array sizing
26
What statements would correctly initialize the value variable...
int value(8); int value{8}; int values = 8;
27
By using the same __ you can build relationships between data stored in two or more arrays
subscript
28
To step through a one-dimensional array, accessing the elements one by one, it would be most appropriate to use ___ loop
a for loop
29
T/F: Arrays can be passed to functions, but individual array elements cannot be
False
30
When an array is passed to a functions, it is actually __ the array that is passed
the starting memory address of
31
T/F: When you pass an array as an argument to a function, the function can modify the contents of the array
True
32
A two-dimensional array can be viewed as
a table with rows and columns
33
The elements of an array can be
- structures - strings - objects
34
T/F: An element of a two-dimensional array is referenced by the array name and two subscripts, first the element row number and then the element column number
True
35
The following statement for(int val : myArray) cout << val << " "; is an example of a(n)
range-based for loop
36
What does the following statement do? typedef int oneDArray[20];
It makes onDArray an alias for a data type that hold 20 integers
37
T/F: When you create a vector it is unnecessary to specify how many elements it will hold because it will expand in size as you add new values to it
True
38
T/F: The range-based for loop may be used with arrays, but not with vectors
False
39
T/F: If employee is an array of objects with a public member function named setHourlyWage, the following statement correctly calls this method for employee[2]. employee.setHourlyWage[2](20.00);
False
40
The __, also known as the address operator, returns the memory address of a variable
ampersand (&)
41
With pointer variables, you can ___ manipulate data stored in other variables
indirectly
42
T/F: With pointer variables you can access, but you cannot modify, data in other variables
False
43
The code segment int *ptr; has the same meaning as ___
int * ptr;
44
When you work with a dereference pointer, you are actually working with
the variable whose address is stored in the pointer variable
45
T/F: An array name is a pointer constant because the address it represents cannot be changed during run-time
True
46
____ can be used as pointers
Array names
47
With arithmetic operations can be performed on pointers
Addition, subtraction, preincrement, and postincrement
48
A pointer may be initialized with
the address of an existing object of the appropriate type
49
The statement double *num;
defines a pointer variable called num
50
When the less than ( < ) operator is used between two pointer variables, the expression is testing whether
the address of the first variable comes before the address of the second variable in the computer's memory
51
Assuming that arr is an array identifier, the statement sum += *arr;
adds the value stored in arr[0] to sum.
52
T/F: Memory cannot be allocated after a program is already running
False
53
The delete operator should only be used on pointers that
point to storage allocated by the new operator
54
A function may return pointer, but the programmer must ensure that the pointer
is pointing to an object that is still valid after the return of the function
55
T/F: Apointer with the value 0 (zero) is called the NULL pointer
True
56
Which of the following statements correctly deletes a dynamically-allocated array pointed to by p?
delete [] p;
57
T/F: It is legal to subtract a pointer variable from another pointer variable
True
58
The term pointer can be used interchangeable with
address
59
T/F: The expression s->m has the same meaning as (*s).m
True
60
T/F: The expression s->m is meaningful only when s if a pointer to a structure and m is a member of the structure
True
61
You may use the type pointer to a structure as the type of a
- structure member - function parameter - function return type
62
If arr is an array identifier and k is an integer, the expression arr[k] is equivalent to
*(arr + k)
63
To dereference a structure pointer and simultaneously access a member of the structure, the appropriate operator to use is
the structure pointer operator, ->
64
A function may return a pointer, but the programmer must ensure that the pointer
is pointing to an object that is still valid after the return of the function
65
T/F: A pointer with the value 0 (zero) is called the NULL pointer
True
66
Suppose that a function dynamically allocates a block of memory with a local pointer variable p pointing to the allocated block. Suppose further that there are no other pointers referencing that block of memory, and the function returns without doing a delete on p. Then
the program will suffer from memory leaks
67
The set of operations supported by the unique_ptr class include
the dereferencing operator * and ->
68
The statement shared_ptr p(new int); involves
two allocations of two different dynamic blocks of memory
69
T/F: A C++ unique pointer (unique_ptr) can be initialized with the value of another unique pointer.
False
70
T/F: You can pass by value when passing a C++ unique pointer to a function
False
71
A C++ smart pointer
is used to ensure that memory that is no longer in use is automatically deleted
72
Memory leaks occur in a program when
a programmer fails to use delete on a pointer whose memory was allocated by the new operator
73
Beginning with C++11, the recommended value for a pointer whose value is invalid is
nullptr
74
Each object of a class has its own copy of the class's
instance member variables
75
A ___ member variable may be accessed before any object of the class have been declared
static
76
T/F: When a class declares an entire class as its friend, the friendship status is reciprocal. That is, each class's member functions have free access to the other's private members
False
77
The ___ operator may be used to assign one object to another
=
78
T/F: By default, when an object is assigned to another, each member of one object is copied to its counterpart in the other project
True
79
C++ requires that a copy constructor's parameter be
a reference to an object
80
C++ allows you to overload
operators and functions
81
When a class contains a pointer to dynamically allocated memory, it is a good idea to equip the class with
a copy constructor
82
T/F: When a class contains a pointer to dynamically allocated memory, it is a good idea to have the class overload the assignment operator
True
83
T/F: If you overload the prefix ++ operator, the postfix ++ operator is automatically overloaded also
False
84
A good reason for overloading an operator is to enable it to
be used with types define by the programmer
85
The process of having a class contain an instance of another class is know as
object composition
86
T/F: If a function f is a friend of a class A, and the class A is a friend of a class B, then the function f is able to access private members of B
False
87
T/F: C++ permits you to overload the sizeof operator
False
88
T/F: A static member variable can be used when there are no objects of the class in existence
True
89
If you do not furnish a __ , an automatic memberwise copy will be performed when one object is assigned to another object
overloaded assignment operator
90
It is a good idea to make a copy constructor's parameters __ by specifying the ___ keyword in the parameter list
constant, const
91
A reason to overload the ___ is to write classes that have array-like behaviors
square brackets []
92
T/F: When you overload the << operator, you must also overload the >> operator
False
93
T/F: You can overload the conditional operator to make it function as an unconditional operator
False
94
___ allows us to create new classes based on existing classes
inheritance
95
When you derive a class from an existing class, you
can add both new data and new functions
96
A situation in which every object of a class A has a pointer to an object of a class B, and the objects of the class B may outlive object of class A, is called
aggregation
97
___ members of a base class are never accessible to a derived class
Private
98
The ___ class constructor is called before the __ class constructor
base, derived
99
T/F: In an inheritance situation, you can't pass arguments to a base class constructor
False
100
T/F: A derived class may become a base class, if another class is derived from it
True
101
In the statement class Car:public Vehicle, which is the base class?
Vehicle
102
Arguments are passed to the base class destructor function by the ___ class ___ function
derived, destructor
103
T/F: A member function of a derived class may not have the same name as a member function of a base class
False
104
T/F: A derived class may not have any classes derived from it
False
105
T/F: Some C++ operators cannot be overloaded by the programmer
True
106
The library function move() can be used to
transfer ownership of a managed object from one unique_ptr object to another
107
T/F: If an rvalue reference refers to a memory location, that memory location becomes an lvalue
True
108
If a member variable is declared ___, all objects of that class share access to that variable
static
109
A member function that is declared __ cannot use the this pointer
static
110
T/F: A static member function can be called independently of any object of the class
True
111
A ___ function is not a member of a class, but it has access to the private members of the class
friend
112
T/F: It is possible to declare an entire class as a friend of another class
True
113
A ___ is a special function that is called whenever a new object is created and initialized with data from another object of the same class
copy constructor
114
If you do not furnish a ___ for a class, for a default will be provided for you by the compiler
- copy constructor - constructor - assignment operator
115
When you redefine the way a standard operator works when it is used with class objects, you have ___ the operator
overloaded
116
To overload the + operator, you would write a function called
operator +
117
The ___ is a special built-in pointer that is available to a class's instance member functions
this pointer
118
T/F: You may overload any C++ operator, and you may use the operator function to define non-standard operators, such as @ and ^
False
119
T/F: The this pointer is a special built-in pointer that is automatically passed as a hidden argument to all instance member functions
True
120
Object composition is useful for creating a ___ relationship between classes
has-a
121
An ___ operator can work programmer-defined data type
overloaded
122
T/F: In C++ if you overload the < operator, you must also overload the > operator
False
123
T/F: When you overload an operator, you cannot change the number of operands taken by the operator
True
124
T/F: A static member function cannot be called if no objects of the class exist
False
125
T/F: The structure member selector operator . cannot be overloaded
True
126
T/F: he this pointer is automatically passed to static member functions of a class
False
127
When overloading the operator++ ___ is used to distinguish preincrement from postincrement
a dummy integer parameter
128
To dereference an object pointer and access one of the object's members, use the
-> operator
129
T/F: A constructor that takes a single parameter of a type other than its class is called a convert constructor
True
130
In an inheritance situation, the new class that you create from an existing class is known as the
both derived class and child class
131
The base class's ___ affects the way its members are inherited by the derived class
access specification
132
Protected members of a base class are like ___, with the exception that they may be accessed by derived classes
private members
133
T/F: The base class access specification can be viewed as a filter that base class members must pass through when becoming inherited members of a derived class
True
134
The ___ class destructor is called before the __ class destructor
derived, base
135
T/F: When arguments must be passed to the base class constructor, they are passed from the derived class constructor's header line
True
136
___ is commonly used to extend a class, or to give it additional capabilities
Inheritance
137
In the statement class Car:protected Vehicle, which is the derived class?
Car
138
In the statement class Car:protected Vehicle, what is being protected?
Base class members
139
T/F: A base class cannot contain a pointer to one of its derived classes
True
140
An lvalue is
a memory location that is associated with a name that can be used by different parts of the program to access the memory location
141
An rvalue is
a temporary value that cannot be accessed from a different part of the program