Exam #2 Review Flashcards
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.
Fales
T/F: In C++ and other object-oriented programming languages, ADTs are normally implemented as classes
True
An object is a ___ of a class
instance
T/F: A class declaration creates an object
False
The bundling of an object’s data and functions together is called…
Encapsulation
The ___ is used to protect important data
private access specifier
Public members of a class object can be accessed from outside the class by using the…
dot operator
A C++ member function that sets or changes the value stored in a member variable is called
a mutator
T/F: A private member function may only be called from a function that is a member of the same class
True
T/F: A constructor is a public class function that gets called whenever you want to re-initialize an object’s member data
False
A constructor must have the same name as the…
class
The name of a destructor must begin with…
a tilde (~)
A class may have ___ default constructor(s) and ____ destructor(s)
only one, only one
When a member function is defined outside of the class declaration, the function name must be qualified with the class name, followed by…
the scope resolution operator (::)
If Square is the name of a class, which of the following statements would create a Square object named box…
Square box;
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
box.setSide(5);
T/F: A class can have a member variable that is an instance of another class. This is called object composition
True
A structure variable is similar to a class object in which way?
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
When an object or structure variable is passed to a function as a constant reference
- 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
What will the following code segment display?
enum Season {Spring, Summer, Fall, Winter} favoriteSeason;
favoriteSeason = Summer;
cout «_space;favoriteSeason;
1
Unlike regular variables, arrays can hold multiple….
values
T/F: The amount of memory used by an array depends solely on the number of elements the array can hold
False
To access an array element, use the array name and the element’s…
subscript
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;
False
The statement
int grades[ ] = { 100, 90, 99, 80 };
is an example of
implicit array sizing
What statements would correctly initialize the value variable…
int value(8);
int value{8};
int values = 8;
By using the same __ you can build relationships between data stored in two or more arrays
subscript
To step through a one-dimensional array, accessing the elements one by one, it would be most appropriate to use ___ loop
a for loop
T/F: Arrays can be passed to functions, but individual array elements cannot be
False
When an array is passed to a functions, it is actually __ the array that is passed
the starting memory address of
T/F: When you pass an array as an argument to a function, the function can modify the contents of the array
True
A two-dimensional array can be viewed as
a table with rows and columns
The elements of an array can be
- structures
- strings
- objects
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
The following statement
for(int val : myArray) cout «_space;val «_space;” “;
is an example of a(n)
range-based for loop
What does the following statement do?
typedef int oneDArray[20];
It makes onDArray an alias for a data type that hold 20 integers
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
T/F: The range-based for loop may be used with arrays, but not with vectors
False
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;
False
The __, also known as the address operator, returns the memory address of a variable
ampersand (&)
With pointer variables, you can ___ manipulate data stored in other variables
indirectly
T/F: With pointer variables you can access, but you cannot modify, data in other variables
False
The code segment int *ptr; has the same meaning as ___
int * ptr;
When you work with a dereference pointer, you are actually working with
the variable whose address is stored in the pointer variable
T/F: An array name is a pointer constant because the address it represents cannot be changed during run-time
True
____ can be used as pointers
Array names
With arithmetic operations can be performed on pointers
Addition, subtraction, preincrement, and postincrement
A pointer may be initialized with
the address of an existing object of the appropriate type
The statement double *num;
defines a pointer variable called num
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
Assuming that arr is an array identifier, the statement sum += *arr;
adds the value stored in arr[0] to sum.
T/F: Memory cannot be allocated after a program is already running
False
The delete operator should only be used on pointers that
point to storage allocated by the new operator
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
T/F: Apointer with the value 0 (zero) is called the NULL pointer
True
Which of the following statements correctly deletes a dynamically-allocated array pointed to by p?
delete [] p;