midterm 2 Flashcards

1
Q

t/f A new node cannot become the first node in the list.

A

f

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

t/f The Standard Template Library (STL) contains templates for useful algorithms and data
structures

A

t

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

t/f A sequential container organizes data in a sequential fashion, similar to an array or linked
list.

A

t

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

t/f Inserting an item into a linked list requires that all the items past the point of the insertion
be shifted to make room for the new item.

A

f

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

t/f At most one catch block may be attached to a single try block.

A

f

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

t/f The values stored in the value portion of a node of a linked list can be simple data types,
structures, objects of classes, or any other data type.

A

t

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
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

t

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

t/f If an exception is not caught, it is stored for later use.

A

f

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

t/f Deleting an entire linked list requires a call to the delete operator for each node in the list.

A

t

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

t/f The C++ mechanism for exception handling encloses code that might throw an exception in
a try block and puts exception handling code in catch blocks attached to the try block.

A

t

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q
t/f There is no difference between defining an object of an ordinary class and an object of a
template class.
A

f

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

t/f When you create a linked list, you must know in advance how many nodes the list will
contain.

A

f

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

t/f Nodes in a linked list are stored in contiguous memory.

A

f

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

t/f The STL vector and list classes are examples of sequential containers.

A

t

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

t/f The following statement adds a new element to the department vector at index 25:
department.push_back(25);

A

f

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

t/f An exception is a condition that can be caused by a syntax error in the program.

A

f

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

t/f Using a function template often requires writing less code than overloading a function.

A

t

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
18
Q
\_\_\_\_\_\_\_\_ to a base class may be assigned the address of a derived class object.
A) Static members
B) Access specifiers
C) Pointers
D) Private members
E) None of the above
A

c

19
Q

Which of the following operations do constant iterators not have?
A) Prefix operator* to make available the container element for use as l-value or r-value.
B) Overloaded binary operator+ to add an int value to the iterator to move the place the
iterator points forward by the argument number of elements.
C) Overloaded unary operator++ to move the place the iterator points forward by one
element.
D) Overloaded unary operator– to move the place the iterator points backward by one
element.
E) Overloaded operator== and operator!= to determine whether two iterators point to the
same element.

A

a

20
Q

Linked lists of items are commonly implemented by
A) using a class template to represent list items.
B) using a function to compute the link to the next item.
C) using an array to hold list items.
D) using a structure containing an item and a pointer to the structure type.
E) None of the above

A

d

21
Q
In the statement template , what does the word class indicate?
A) A class called T will automatically be created by the compiler.
B) You are deriving a class from an existing class called T.
C) class is a keyword that indicates that T is a type parameter.
D) You are deriving a class called T from a class called template.
E) None of the above
A

c

22
Q

The bad_alloc exception is thrown
A) by the new operator.
B) only when the program contains a catch block.
C) when program code encounters a bad memory location.
D) when you forget to free memory with the delete operator.
E) None of the above

A

a

23
Q
Types of iterators are
A) reverse.
B) random-access.
C) forward and bidirectional.
D) All of the above
E) None of the above
A

d

24
Q
A(n) \_\_\_\_\_\_\_\_ is like a pointer. It is used to access the individual data elements in a
container.
A) subscript indicator
B) element access operator
C) iterator
D) global data finder
E) None of the above
A

c

25
Q
A(n) \_\_\_\_\_\_\_\_ is used in a function template to specify a generic data type.
A) type parameter
B) dummy variable
C) catch block
D) exception
E) None of the above
A

a

26
Q

If the head pointer points to NULL, it is an indication that
A) the list needs to be destroyed.
B) the list is full and cannot accept any new nodes.
C) the list has been destroyed.
D) there are no nodes in the list.
E) None of the above

A

d

27
Q
Declaring a member function of a class to be a \_\_\_\_\_\_\_\_ will cause the C++ compiler to
use dynamic binding.
A) virtual function
B) static function
C) constructor function
D) destructor function
E) None of the above
A

a

28
Q
A \_\_\_\_\_\_\_\_ is used to step through a linked list and search for data.
A) node
B) NULL value
C) traversal operator
D) pointer
E) None of the above
A

d

29
Q
To catch an exception, a program must
A) have a try/catch construct.
B) have a throw() function.
C) first experience an unrecoverable error.
D) first experience a fatal error.
E) None of the above
A

a

30
Q
Polymorphism in C++ will not work unless \_\_\_\_\_\_\_\_.
A) the members of the class are public
B) the  header file is included
C) pointers or references are being used
D) All of the above
E) None of the above
A

c

31
Q
In a function template, the programmer substitutes \_\_\_\_\_\_\_\_ for \_\_\_\_\_\_\_\_.
A) angle brackets, parentheses
B) parameters, data types
C) parameters, arguments
D) arguments, parameters
E) None of the above
A

b

32
Q
How much memory is reserved for a function template?
A) four bytes
B) no memory
C) two bytes
D) eight bytes
E) None of the above
A

b

33
Q
Which of the following does not refer to the same topic?
A) Late binding
B) Virtual functions
C) Polymorphism
D) Static binding
E) none of the above
A

d

34
Q

An exception is propagated
A) From a place where the error occurs to the handler in the ‘catch’ block.
B) From the ‘throw’ statement buried in the ‘try’ block to the handler in the ‘catch’
block.
C) From a ‘throw’ statement, not in a ‘try’ block to the handler in the ‘catch’ block.
D) From the ‘catch’ block to the ‘try’ block.
E) From the handler in the ‘throw’ block to the ‘try’ block

A

b

35
Q
The algorithms provided by the STL are implemented as \_\_\_\_\_\_\_\_, and perform various
operations on elements of containers.
A) virtual functions
B) private data members
C) function templates
D) global variables
A

c

36
Q

I have a pointer, nodePtr to a node that is a struct in a linked list. I want to access the
member named data. I do this using the expression
A) nodePtr.data
B) nodePtr->data
C) nodePtr.data
D) (
nodePtr).data
E) both b and d

A

e

37
Q
Suppose we have the following definition:
vector vec(5);
vector::iterator p = vec.begin();
vector::const_iterator q = vec.begin();
Which of the following expressions is not legal? Treat the effect of these as non-cumulative.
A) *p = 1;
B) *q = 1;
C) p = vec.end ();
D) q = vec1.end();
A

b

38
Q

An abstract class is
A) one that has all of its member functions declared private.
B) one that has all of its member variables declared private.
C) one that has at least one pure virtual function.
D) one that supports polymorphism.
E) None of the above

A

c

39
Q

An abstract class is somewhat restricted in how it can be used because
A) all of its members must be public.
B) it cannot use dynamic binding for its member functions.
C) the compiler does not allow objects of the class to be created.
D) it cannot use static binding for its member functions.
E) None of the above

A

c

40
Q

EC I have an algorithm that runs in O(N1/2), where n is the size of the problem. For N = 100,
the time the algorithm runs is 1 minute. How long does the algorithm take for N=1000?
Hint: sqrt(1000) is approximately 31.6.
A) Same time
B) About 3 minutes
C) About 10 minutes
D) About 30 minutes
E) You haven’t given enough information. I can’t tell.

A

b

41
Q

EC True /False: Insertion into a vector runtime is O(1) at any position in the
vector. This means that inserting into a vector is constant time and does not depend on
the number of elements in the vector.

A

f

42
Q

EC True /False : In a non-empty list, there must be exactly one list item with no
successor.

A

t

43
Q

EC The code for a template function is generated when:
A) The function template declaration (prototype) appears in the C++ program.
B) The function template is encountered in the C++ program.
C) The function call is encountered in the C++ program
D) At runtime, when the function call is executed.

A

c

44
Q

EC True /False: Suppose the swapValue template is instantiated as follows:
int x = 2, y =3;
swapValue(x, y);
double d= 3.0, f=4.5;
swapValue(d, f);
Then the compiler generates code for two copies of the swapValue template.

A

t