Final exam COSC(11,12,13,14,15,19,10,9,8) missing 7
5) ________ can be used as pointers. A) Array names B) Numeric constants C) Punctuation marks D) All of these E) None of these
A
12) A function may return a pointer, but the programmer must ensure that the pointer ________. A) still points to a valid object after the function ends B) has not been assigned an address C) was received as a parameter by the function D) has not previously been returned by another function E) None of these
A
7) In C++ 11, the ________ key word was introduced to represent the address 0. A) nullptr B) NULL C) weak_ptr D) All of these E) None of these
A
7) Using a linear search to find a value that is stored in the last element of an array of 20,000 elements, ________ element(s) must be compared. A) 20,000 B) only the first C) only half D) 2000 E) None of these
A
9) Data that is sorted in ascending order is ordered ________. A) from lowest to highest value B) from highest to lowest value C) always with a binary sort algorithm D) always with a linear sort algorithm E) None of these
A
12) The ________ is adequate for searching through small arrays. A) binary search B) linear search C) unary search D) bubble sort E) None of these
B
16) What will the following statement output? cout << &num1; A) The value stored in the variable called num1 B) The memory address of the variable called num1 C) The number 1 D) The string "&num1" E) None of these
B
Starting Out with C++ from Control Structures to Objects, 8e (Gaddis) Chapter 8 Searching and Sorting Arrays 8.1 Multiple Choice Questions 1) A ________ algorithm is a method of locating a specific item of information in a larger collection of data. A) sort B) search C) standard D) linear E) None of these
B
Starting Out with C++ from Control Structures to Objects, 8e (Gaddis) Chapter 9 Pointers 9.1 Multiple Choice Questions 1) The ________, also known as the address operator, returns the memory address of a variable. A) asterisk ( * ) B) ampersand ( & ) C) percent sign (%) D) exclamation point ( ! ) E) None of these
B
___________: the class which is inherited from: -Sometimes called the "Parent" class -Sometimes called the "Superclass"
Base
10) Look at the following statement: sum += *array++; This statement ________. A) is illegal in C++ B) will always result in a compiler error C) assigns the dereferenced pointer's value, then increments the pointer's address D) increments the dereferenced pointer's value by one, then assigns that value E) None of these
C
15) When this is placed in front of a variable name, it returns the address of that variable. A) asterisk ( * ) B) conditional operator C) ampersand ( & ) D) semicolon ( ; ) E) None of these
C
6) Array elements must be ________ before a binary search can be performed. A) summed B) set to zero C) sorted D) positive numbers E) None of these
C
11) Use the delete operator only on pointers that were ________. A) never used B) not correctly initialized C) created with the new operator D) dereferenced inappropriately E) None of these
C
11) When an array is sorted from highest to lowest, it is said to be in ________ order. A) reverse B) forward C) descending D) ascending E) None of these
C
13) ________ algorithms are used to arrange random data into some order. A) Standard search B) Linear C) Sorting D) Binary search E) None of these
C
14) Which of the following statements deletes memory that has been dynamically allocated for an array? A) int array = delete memory; B) int delete[ ]; C) delete [] array; D) new array = delete; E) None of these
C
17) A pointer variable is designed to store ________. A) any legal C++ value B) only floating-point values C) a memory address D) an integer E) None of these
C
2) The advantage of a linear search is its ________. A) complexity B) efficiency C) simplicity D) speed E) None of these
C
2) With pointer variables, you can ________ manipulate data stored in other variables. A) never B) seldom C) indirectly D) All of these E) None of these
C
3) A(n) ________ search is more efficient than a ________ search. A) character, string B) integer, double C) binary, linear D) linear, binary E) None of these
C
4) When you work with a dereferenced pointer, you are actually working with ________. A) a variable whose memory has been allocated B) a copy of the value pointed to by the pointer variable C) the actual value of the variable whose address is stored in the pointer variable D) All of these E) None of these
C
5) The ________ sort usually performs fewer exchanges than the ________ sort. A) bubble, selection B) binary, linear C) selection, bubble D) ANSI, ASCII E) None of these
C
6) The contents of pointer variables may be changed with mathematical statements that perform ________. A) all mathematical operations that are legal in C++ B) multiplication and division C) addition and subtraction D) B and C E) None of these
C
8) A(n) ________ search uses a loop to sequentially step through an array. A) binary B) unary C) linear D) relative E) None of these
C
9) When the less than ( < ) operator is used between two pointer variables, the expression is testing whether ________. A) the value pointed to by the first is less than the value pointed to by the second B) the value pointed to by the first is greater than the value pointed to by the second C) the address of the first variable comes before the address of the second variable in the computer's memory D) the first variable was declared before the second variable E) None of these
C
Write the syntax the defines a derived class constructor Cube that takes arguments from the base class constructor Rectangle (not inline)
Cube::Cube(double w, double len, double h) : Rectangle(w, len)
3) The statement: int *ptr = nullptr; has the same meaning as ________. A) int ptr = nullptr; B) *int ptr = nullptr; C) int ptr* = nullptr; D) int* ptr = nullptr; E) None of these
D
8) What does the following statement do? double *num2; A) Declares a double variable named num2. B) Declares and initializes an pointer variable named num2. C) Initializes a variable named *num2. D) Declares a pointer variable named num2. E) None of these
D
10) Regardless of the algorithm being used, a search through an array is always performed ________. A) from lowest to highest element B) from highest to lowest element C) beginning with the middle element D) using a binary search E) None of these
E
13) Which of the following statements is not valid C++ code? A) int ptr = &num1; B) int ptr = int *num1; C) float num1 = &ptr2; D) All of these are valid. E) All of these are invalid.
E
4) True/False: A linear search can only be implemented with integer values.
FALSE
5) True/False: Before you can perform a selection sort, the data must be stored in ascending order.
FALSE
6) True/False: Before you can perform a bubble sort, the data must be stored in descending order.
FALSE
7) True/False: Using a binary search, you are more likely to find an item than if you use a linear search.
FALSE
8.2 True/False Questions 1) True/False: The bubble sort is an easy way to arrange data into ascending order, but it cannot arrange data into descending order.
FALSE
___________ provides a way to create a new class from an existing class.
Inheritance
create a new instance of cube and assign it to a rectangle base class pointer (use default constructor)
Rectangle *rectangle = new Cube();
3) True/False: In the average case, an item is just as likely to be found near the beginning of an array as near the end.
TRUE
Which is the derived class in the following statement? class Car : protected Vehicle a. Car b. Vehicle c. protected d. There is no way to tell. e. None of these
a. Car
The ________ constructor is called before the ________ constructor. a. base, derived b. derived, base c. public, private d. private, public e. None of these
a. base, derived
Which of the following is commonly used to extend a class or to give it additional capabilities? a. inheritance b. privacy c. the constructor d. the destructor e. None of these
a. inheritance
When a derived class has two or more base classes, the situation is called a. multiple inheritance b. multiplicity c. polymorphism d. encapsulation e. None of these
a. multiple inheritance
A virtual function is declared by placing the ___ key word in front of the return type in the base class's function declaration. a. virtual b. private c. public d. protected e. None of these
a. virtual
_________ _________ _________ is a class that can have no objects. It serves as a basis for derived classes that may/will have objects
abstract base class
____________ refers to when a "has a" relationship is formed between classes.
aggregation
What is being protected in the following statement? class Car : protected Vehicle a. derived class functions b. base class members c. derived class data d. future inherited classes e. None of these
b. base class members
The ________ destructor is called before the ________ destructor. a. base, derived b. derived, base c. public, private d. private, public e. None of these
b. derived, base
In OOP programming, ________ allows you to create new classes based on existing classes. a. polymorphism b. inheritance c. function overloading d. the copy constructor e. None of these
b. inheritance
The term ________ means the ability to take many forms. a. inheritance b. polymorphism c. member function d. encapsulation e. None of these
b. polymorphism
When an object of a derived class is created, the _________ class's constructor is executed first, followed by the ____________ class's constructor
base, derived
The base class's ________ affects the way its members are inherited by the derived class. a. name b. return data type c. access specification d. construction e. None of these
c. access specification
When you derive a class from an existing class, you ________ add new data and functions. a. never b. must c. may d. None of these
c. may
Polymorphism is when ________ in a class hierarchy perform differently, depending on which object performs the call. a. base class constructors b. derived class constructors c. member functions d. derived class destructors e. None of these
c. member functions
A virtual function is a function that expects to be ________ in a derived class. a. ignored b. called frequently c. overridden d. private e. None of these
c. overridden
C++11 introduced the ________ key word to help prevent subtle errors when overriding virtual functions. a. const b. final c. override d. virtual e. None of these
c. override
When member functions behave differently depending on which object performed the call, this is an example of a. chaos theory b. virtual insubordination c. polymorphism d. encapsulation e. None of these
c. polymorphism
Protected members of a base class are like ___, but they may be accessed by the derived class. a. constructor functions b. static members c. private members d. public members e. None of these
c. private members
________ __________ __________ determines how members of a base class are inherited by the derived class
class access specification
Multiple inheritance opens the opportunity for a derived class to have ________ members. a. dynamic b. private c. public d. ambiguous e. None of these
d. ambiguous
The compiler performs ________ on virtual functions. a. local binding b. additional error checking c. static binding d. dynamic binding e. None of these
d. dynamic binding
Functions that are dynamically bound by the compiler are ________ functions. a. constructor b. destructor c. static d. virtual e. None of these
d. virtual
An object of the ___________ class has: *all members defined in the child class *all members defined in the parent class
derived
An object of the derived class can use: *all public members defined in the child class *all public members defined in the parent class
derived
When an object of a derived class is destroyed, the __________ class's destructor is called first, then the _________ class's destructor
derived, base
assume a derived class redefined a function of it's base class. when the ____________ binding is used, the function that gets used is the one that is associated with the actual object argument type (not the parameter type).
dynamic
Arguments are passed to the base class by the ________ class ________ function. a. derived, constructor b. derived, destructor c. base, constructor d. base, destructor e. None of these
e. None of these
The following statement allows the ________ members of the Car class to access ________ members of the Vehicle class. class Car : public Vehicle a. private, private b. public, private c. protected, private d. public, protected e. None of these
e. None of these
When more than one class is derived from a base class, the situation is called a. polymorphism b. multiplicity c. population d. encapsulation e. None of these
e. None of these
(conceptual) why is it a good idea to make destructors virtual if the class could ever become a base class?
if a destructor is not made virtual and it becomes a base class, then when an instance of the base class is assigned to a based class pointer, then only the destructor for the base class will be called. To fix this, make the base class destructor "virtual"
_________ refers to when an "is a" relationship is formed between classes.
inheritance
_____________: specification that is restrictive, but does all derived classes to know the details of parents
protected
___________: specification that allows an object of a derived class to be treated as an object of the base class (not vise-versa)
public
a ________ _________ _________ is a member function of an abstract class that must be overridden in every instance of the derived class. abstract classes have at least one of these.
pure virtual function
____________ a function means defining a function in the derived class with the same name and parameter list as a function in the base class.
redefining
assume a derived class redefines a function of it's base class. when the default ____________ binding is used, which function that gets called depends on the type of object variable used in the function call (whether the function's parameter takes a type of the base or derived)
static
by default, does C++ engage in static binding or dynamic binding?
static
A base class can be derived from another base class
true
A specialized object has all of the characteristics of the general class, plus its own characteristics
true
In C++, redefined functions are statically bound and overridden functions are dynamically bound
true
in order to assign a new instance of a derived class to a base class variable, you need to use a base class pointer
true
polymorphic behavior is only possible when an object is references by a reference variable or a pointer
true
a ___________ function expects to be redefined in a derived class and supports dynamic binding
virtual
what keyword do you use to ensure that a function will engage in dynamic binding (this is done in the function prototype in the base class)
virtual
(conceptual) how does a class become an abstract class?
when one or more of its member functions is a pure virtual function
If a base class is declared as private, how will the derived class "receive" its members: private x -? protected y -? public z -?
x inaccessible y private z private
If a base class is declared as public, how will the derived class "receive" its members: private x -? protected y -? public z -?
x inaccessible y protected z public
Does aggregation establish an "is a" relationship or a "has a" relationship with another class?
"has a"
Does inheritance establish an "is a" relationship or "has a" relationship between classes?
"is a"
4) A binary search begins with the ________ element of an array. A) first B) last C) largest D) middle E) None of these
D
____________: the class inherits from the base class: -Sometimes called the "Parent" class. -Sometimes called the "Subclass"
Derived
2) True/False: The number of comparisons made by a binary search is expressed in powers of two.
TRUE
The ___ members of a base class are never accessible to a derived class. a. private b. public c. protected d. All of these e. None of these
a. private
Which is the base class in the following statement? class Car : public Vehicle a. Car b. Vehicle c. public d. class e. None of these
b. Vehicle
When the compiler binds a member function call with the version of the function that resides in the same class as the call itself, it is considered a. local binding b. safe binding c. static binding d. dynamic binding e. None of these
c. static binding
A ________ of a base class expects to be overridden in a derived class. a. constructor function b. destructor function c. static function d. virtual function e. None of these
d. virtual function
____________: specification that prevents objects of a derived class from being treated as objects of the base class (this is the default).
private
Commonly, you will make your class data members ____________ and your class member functions ____________.
private, public
_____________ member access specification is like private, but is accessible by objects of the derived class
protected
If a base class is declared as protected, how will the derived class "receive" its members: private x -? protected y -? public z -?
x inaccessible y protected z protected