Data structures midterm practice questions
two ways of repeating statements in C++
1) looping structures (for, while, do...while) 2) recursive functions
Objects in an array are accessed with ________, just like any other data type in an array. A) subscripts B) parentheses C) #include statements D) output format manipulators E) None of these
A
When you dereference an object pointer, use the ________. A) -> operator B) <> operator C) dot operator D) & operator E) None of these
A
If you do not furnish one of these, an automatic memberwise copy will be performed when one object is assigned to another object. (a) overloaded constructor function (b) overloaded assignment operator (c) default constructor function (d) overloaded copy operator (e) None of these
(b) overloaded assignment operator
This is a special built-in pointer that is available to a class's member functions. (a) overloaded -> operator (b) this pointer (c) &constructor pointer (d) ~destructor *ptr (d) None of these
(b) this pointer
It is a good idea to make a copy constructor's parameters ________ by specifying the ________ key word in the parameter list. (a) inline, inline (b) static, static (c) constant, const (d) global, global (e) None of these
(c) constant, const
This is a special function that is called whenever a new object is created and initialized with another object's data. (a) destructor (b) static function (c) copy constructor (d) assignment function (e) None of these
(c) copy constructor
Object composition is useful for creating this type of relationship between classes. (a) friend (b) static (c) has a (d) conditional (e) None of these
(c) has a
A member function that is declared ________ may not access any non-static data members in the class. (a) private (b) public (c) static (d) inline (e) None of these
(c) static
If you do not furnish one of these a default will be provided for you by the compiler. (a) copy constructor (b) constructor (c) destructor (d) All of these (e) None of these
(d) all of these
When you overload an operator, you cannot change the number of ________ taken by the operator. (a) arguments (b) parameters (c) operations (d) operands (e) None of these
(d) operands
Why are base cases necessary in recursive solutions?
A recursive solution will call itself, simplifying the problem each time until it reaches a base case. If there is no base case, then infinite recursion will occur
A stack can be adapted to store ________ data types. A) all B) only the built-in C++ C) only abstract D) deque-like E) None of these
Answer: A
This is a container that provides quick access to elements at the front and the back of the list. A) stack B) queue C) deque D) All of these E) None of these
Answer: C
A practical application of the stack data type in a computer system is: A) storage of local variables B) tracking nested loops C) tracking nested function calls D) All of these E) None of these
Answer: D
This is a double-ended queue. A) two-headed stack B) two-tailed vector C) circular array D) deque E) None of these
Answer: D
True/False: In a static stack class, the constructor function can dynamically allocate memory for the stack array.
Answer: TRUE
True/False: The STL provides containers for deque and queue.
Answer: TRUE
True/False: The pop function in the stack template does not retrieve the value from the top of the stack. It merely removes it.
Answer: TRUE
Class declarations are usually stored here. A) on separate disk volumes B) in their own header files C) in .cpp files, along with function definitions D) under pseudonyms E) None of these
B
This type of member function may be called only from a function that is a member of the same class. A) public B) private C) global D) local E) None of these
B
Why can you think of a recursive function as having an unlimited number of copies of itself?
Because every call to the recursive function has its own code and its own set of parameters and local variables
Assume that myCar is an instance of the Car class, and that the Car class has a member function named accelerate. Which of the following is a valid call to the accelerate member function? A) Car->accelerate(); B) myCar::accelerate(); C) myCar.accelerate(); D) myCar:accelerate();
C
Assuming that Rectangle is a class name, the statement: Rectangle *BoxPtr; A) declares an object of class Rectangle B) assigns the value of *BoxPtr to the object Rectangle C) defines a Rectangle pointer variable called BoxPtr D) is illegal in C++ E) None of these
C
This directive is used to create an "include guard," which allows a program to be conditionally compiled. This prevents a header file from accidentally being included more than once. A) #include B) #guard C) #ifndef D) #endif E) None of these
C
In a procedural program, you typically have ________ stored in a collection of variables, and a set of ________ that perform operations on the data. A) numbers, arguments B) parameters, arguments C) strings, operators D) data, functions E) None of these
D
True/False: A non-static member function may not access a static member variable.
False
True/False: A public data member may be declared a friend of a private function.
False
True/False: When you overload the << operator, you must also overload the >> operator.
False
The process of solving a problem by reducing it to smaller versions of itself
Recursion
True/False: A static member function does not need to be called by a specific object of the class.
True
True/False: A static member variable can be used when there are no objects of the class in existence.
True
True/False: By default, when an object is assigned to another, each member of one object is copied to its counterpart in the other object.
True
True/False: The this pointer is a special built-in pointer that is automatically passed as a hidden argument to all non-static member functions.
True
True/False: When you overload an operator, you can change the operator's original meaning to something entirely different.
True
When does recursion terminate?
When the base case is recognized.
A linear search only requires __ access. a) sequential b) random c) sorted d) arbitrary
a
Assume that you have declared a queue named myQueue to hold String elements. Which of the following statements will correctly remove an element from myQueue? a) myQueue.remove(); b) myQueue.get(); c) myQueue.delete(); d) myQueue.pop();
a
We might choose to use a linked list over an array list when we will not require frequent ____. I random access II inserting new elements III removing of elements a) I b) II c) III d) II and III
a
What type of access does a LinkedList provide for its elements? a) sequential b) semi-random c) random d) sorted
a
In Big-Oh notation, selection sort is a(n) ____ algorithm. a) O(n^2) b) O(1) c) log n d) O(log n^2)
a) O(n^2)
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
A binary search requires ___ access. a) sequential b) random c) sorted d) arbitrary
b
A collection that remembers the order of items, and allows items to be added and removed only at one end is called a ____. a) list b) stack c) set d) queue
b
The term ___ is used in computer science to describe an access pattern in which the elements are accessed in arbitrary order. a) sequential access b) random access c) sorted access d) arbitrary access
b
Which nodes need to be updated when we insert a new node to become the fourth node from the beginning of a doubly-linked list? a) The current third node. b) The current third and fourth nodes. c) The current first node. d) The current fourth and fifth nodes.
b
In an inheritance situation, you may not pass arguments to a base class constructor. a. True b. False
b. False
In the statement which is the base class? class Car : public Vehicle a. Car b. Vehicle c. public d. class e. None of these
b. Vehicle
In the following statement what is being protected? 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
The term ________ means the ability to take many forms. a. inheritance b. polymorphism c. member function d. encapsulation e. None of these
b. polymorphism
Suppose you push integer elements 1,2,3,4 onto a stack in that order. Then pop an element off the stack and add that element to a queue. You repeat that process three more times. In what order will you remove the elements from the queue? a) 1,2,3,4 b) 1,2,4,3 c) 4,3,2,1 d) 4,3,1,2
c
Polymorphism is when ________ in a class hierarchy perform differently, depending upon which object performs the call. a. base class constructors b. derived class destructors c. member functions d. derived class constructors e. None of these
c. member functions
When member functions behave differently, depending upon 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 derived classes. a. constructor functions b. static members c. private members d. public members e. None of these
c. private members
When the compiler binds a member function call with the version of the function that resides in the same class as the call itself, this is considered ________ binding. a. local b. safe c. static d. dynamic e. None of these
c. static
A collection that allows items to be added only at one end and removed only at the other end is called a ____. a) list b) stack c) set d) queue
d
________ to a base class may be assigned the address of a derived class object. a. Access specifiers b. Static members c. Private members d. Pointers e. None of these
d. Pointers
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
refers to functions that explicitly call themselves
directly recursive
Arguments are passed to the base class destructor function 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 a function calls another function that calls upon the first function.
indirectly recursive
a function that calls itself, either directly or indirectly
recursive function
Array elements must be _________ before a binary search can be performed
sorted