Exam #2 Review Flashcards

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
Q

The statement
int grades[ ] = { 100, 90, 99, 80 };
is an example of

A

implicit array sizing

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

What statements would correctly initialize the value variable…

A

int value(8);
int value{8};
int values = 8;

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

By using the same __ you can build relationships between data stored in two or more arrays

A

subscript

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

To step through a one-dimensional array, accessing the elements one by one, it would be most appropriate to use ___ loop

A

a for loop

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

T/F: Arrays can be passed to functions, but individual array elements cannot be

A

False

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

When an array is passed to a functions, it is actually __ the array that is passed

A

the starting memory address of

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

T/F: When you pass an array as an argument to a function, the function can modify the contents of the array

A

True

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

A two-dimensional array can be viewed as

A

a table with rows and columns

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

The elements of an array can be

A
  • structures
  • strings
  • objects
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
34
Q

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

A

True

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

The following statement
for(int val : myArray) cout &laquo_space;val &laquo_space;” “;
is an example of a(n)

A

range-based for loop

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

What does the following statement do?
typedef int oneDArray[20];

A

It makes onDArray an alias for a data type that hold 20 integers

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

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

A

True

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

T/F: The range-based for loop may be used with arrays, but not with vectors

A

False

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

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.setHourlyWage2;

A

False

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

The __, also known as the address operator, returns the memory address of a variable

A

ampersand (&)

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

With pointer variables, you can ___ manipulate data stored in other variables

A

indirectly

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

T/F: With pointer variables you can access, but you cannot modify, data in other variables

A

False

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

The code segment int *ptr; has the same meaning as ___

A

int * ptr;

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

When you work with a dereference pointer, you are actually working with

A

the variable whose address is stored in the pointer variable

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

T/F: An array name is a pointer constant because the address it represents cannot be changed during run-time

A

True

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

____ can be used as pointers

A

Array names

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

With arithmetic operations can be performed on pointers

A

Addition, subtraction, preincrement, and postincrement

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

A pointer may be initialized with

A

the address of an existing object of the appropriate type

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

The statement double *num;

A

defines a pointer variable called num

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

When the less than ( < ) operator is used between two pointer variables, the expression is testing whether

A

the address of the first variable comes before the address of the second variable in the computer’s memory

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

Assuming that arr is an array identifier, the statement sum += *arr;

A

adds the value stored in arr[0] to sum.

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

T/F: Memory cannot be allocated after a program is already running

A

False

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

The delete operator should only be used on pointers that

A

point to storage allocated by the new operator

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

A function may return pointer, but the programmer must ensure that the pointer

A

is pointing to an object that is still valid after the return of the function

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

T/F: Apointer with the value 0 (zero) is called the NULL pointer

A

True

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

Which of the following statements correctly deletes a dynamically-allocated array pointed to by p?

A

delete [] p;

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

T/F: It is legal to subtract a pointer variable from another pointer variable

A

True

58
Q

The term pointer can be used interchangeable with

A

address

59
Q

T/F: The expression s->m has the same meaning as (*s).m

A

True

60
Q

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

A

True

61
Q

You may use the type pointer to a structure as the type of a

A
  • structure member
  • function parameter
  • function return type
62
Q

If arr is an array identifier and k is an integer, the expression arr[k] is equivalent to

A

*(arr + k)

63
Q

To dereference a structure pointer and simultaneously access a member of the structure, the appropriate operator to use is

A

the structure pointer operator, ->

64
Q

A function may return a pointer, but the programmer must ensure that the pointer

A

is pointing to an object that is still valid after the return of the function

65
Q

T/F: A pointer with the value 0 (zero) is called the NULL pointer

A

True

66
Q

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

A

the program will suffer from memory leaks

67
Q

The set of operations supported by the unique_ptr class include

A

the dereferencing operator * and ->

68
Q

The statement shared_ptr<int> p(new int); involves</int>

A

two allocations of two different dynamic blocks of memory

69
Q

T/F: A C++ unique pointer (unique_ptr) can be initialized with the value of another unique pointer.

A

False

70
Q

T/F: You can pass by value when passing a C++ unique pointer to a function

A

False

71
Q

A C++ smart pointer

A

is used to ensure that memory that is no longer in use is automatically deleted

72
Q

Memory leaks occur in a program when

A

a programmer fails to use delete on a pointer whose memory was allocated by the new operator

73
Q

Beginning with C++11, the recommended value for a pointer whose value is invalid is

A

nullptr

74
Q

Each object of a class has its own copy of the class’s

A

instance member variables

75
Q

A ___ member variable may be accessed before any object of the class have been declared

A

static

76
Q

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

A

False

77
Q

The ___ operator may be used to assign one object to another

A

=

78
Q

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

A

True

79
Q

C++ requires that a copy constructor’s parameter be

A

a reference to an object

80
Q

C++ allows you to overload

A

operators and functions

81
Q

When a class contains a pointer to dynamically allocated memory, it is a good idea to equip the class with

A

a copy constructor

82
Q

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

A

True

83
Q

T/F: If you overload the prefix ++ operator, the postfix ++ operator is automatically overloaded also

A

False

84
Q

A good reason for overloading an operator is to enable it to

A

be used with types define by the programmer

85
Q

The process of having a class contain an instance of another class is know as

A

object composition

86
Q

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

A

False

87
Q

T/F: C++ permits you to overload the sizeof operator

A

False

88
Q

T/F: A static member variable can be used when there are no objects of the class in existence

A

True

89
Q

If you do not furnish a __ , an automatic memberwise copy will be performed when one object is assigned to another object

A

overloaded assignment operator

90
Q

It is a good idea to make a copy constructor’s parameters __ by specifying the ___ keyword in the parameter list

A

constant, const

91
Q

A reason to overload the ___ is to write classes that have array-like behaviors

A

square brackets []

92
Q

T/F: When you overload the &laquo_space;operator, you must also overload the&raquo_space; operator

A

False

93
Q

T/F: You can overload the conditional operator to make it function as an unconditional operator

A

False

94
Q

___ allows us to create new classes based on existing classes

A

inheritance

95
Q

When you derive a class from an existing class, you

A

can add both new data and new functions

96
Q

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

A

aggregation

97
Q

___ members of a base class are never accessible to a derived class

A

Private

98
Q

The ___ class constructor is called before the __ class constructor

A

base, derived

99
Q

T/F: In an inheritance situation, you can’t pass arguments to a base class constructor

A

False

100
Q

T/F: A derived class may become a base class, if another class is derived from it

A

True

101
Q

In the statement class Car:public Vehicle, which is the base class?

A

Vehicle

102
Q

Arguments are passed to the base class destructor function by the ___ class ___ function

A

derived, destructor

103
Q

T/F: A member function of a derived class may not have the same name as a member function of a base class

A

False

104
Q

T/F: A derived class may not have any classes derived from it

A

False

105
Q

T/F: Some C++ operators cannot be overloaded by the programmer

A

True

106
Q

The library function move() can be used to

A

transfer ownership of a managed object from one unique_ptr object to another

107
Q

T/F: If an rvalue reference refers to a memory location, that memory location becomes an lvalue

A

True

108
Q

If a member variable is declared ___, all objects of that class share access to that variable

A

static

109
Q

A member function that is declared __ cannot use the this pointer

A

static

110
Q

T/F: A static member function can be called independently of any object of the class

A

True

111
Q

A ___ function is not a member of a class, but it has access to the private members of the class

A

friend

112
Q

T/F: It is possible to declare an entire class as a friend of another class

A

True

113
Q

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

A

copy constructor

114
Q

If you do not furnish a ___ for a class, for a default will be provided for you by the compiler

A
  • copy constructor
  • constructor
  • assignment operator
115
Q

When you redefine the way a standard operator works when it is used with class objects, you have ___ the operator

A

overloaded

116
Q

To overload the + operator, you would write a function called

A

operator +

117
Q

The ___ is a special built-in pointer that is available to a class’s instance member functions

A

this pointer

118
Q

T/F: You may overload any C++ operator, and you may use the operator function to define non-standard operators, such as @ and ^

A

False

119
Q

T/F: The this pointer is a special built-in pointer that is automatically passed as a hidden argument to all instance member functions

A

True

120
Q

Object composition is useful for creating a ___ relationship between classes

A

has-a

121
Q

An ___ operator can work programmer-defined data type

A

overloaded

122
Q

T/F: In C++ if you overload the < operator, you must also overload the > operator

A

False

123
Q

T/F: When you overload an operator, you cannot change the number of operands taken by the operator

A

True

124
Q

T/F: A static member function cannot be called if no objects of the class exist

A

False

125
Q

T/F: The structure member selector operator . cannot be overloaded

A

True

126
Q

T/F: he this pointer is automatically passed to static member functions of a class

A

False

127
Q

When overloading the operator++ ___ is used to distinguish preincrement from postincrement

A

a dummy integer parameter

128
Q

To dereference an object pointer and access one of the object’s members, use the

A

-> operator

129
Q

T/F: A constructor that takes a single parameter of a type other than its class is called a convert constructor

A

True

130
Q

In an inheritance situation, the new class that you create from an existing class is known as the

A

both derived class and child class

131
Q

The base class’s ___ affects the way its members are inherited by the derived class

A

access specification

132
Q

Protected members of a base class are like ___, with the exception that they may be accessed by derived classes

A

private members

133
Q

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

A

True

134
Q

The ___ class destructor is called before the __ class destructor

A

derived, base

135
Q

T/F: When arguments must be passed to the base class constructor, they are passed from the derived class constructor’s header line

A

True

136
Q

___ is commonly used to extend a class, or to give it additional capabilities

A

Inheritance

137
Q

In the statement class Car:protected Vehicle, which is the derived class?

A

Car

138
Q

In the statement class Car:protected Vehicle, what is being protected?

A

Base class members

139
Q

T/F: A base class cannot contain a pointer to one of its derived classes

A

True

140
Q

An lvalue is

A

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
Q

An rvalue is

A

a temporary value that cannot be accessed from a different part of the program