• Shuffle
    Toggle On
    Toggle Off
  • Alphabetize
    Toggle On
    Toggle Off
  • Front First
    Toggle On
    Toggle Off
  • Both Sides
    Toggle On
    Toggle Off
  • Read
    Toggle On
    Toggle Off
Reading...
Front

Card Range To Study

through

image

Play button

image

Play button

image

Progress

1/100

Click to flip

Use LEFT and RIGHT arrow keys to navigate between flashcards;

Use UP and DOWN arrow keys to flip the card;

H to show hint;

A reads text to speech;

100 Cards in this Set

  • Front
  • Back
Of the interface file and the implementation file, which may be directly compiled?
only the implementation

The implementation file has function definitions, hence may be compiled. While explicitly compiling a header file, such as file.h, is illegal, the implementation will necessarily #include header files, so the interface will be compiled by inclues, but not directly.
You can have a name spelled the same in two different namespaces with no conflict in your program.
true

The namespace groups names together and provides an access method that allows the same name to be used in several namespaces without conflict.
Namespaces can be defined in pieces across several files.
true
Namespaces may not be nested.
false

Namespaces, like classes, can be nested to arbitrary depth. Nested namespaces collect together subcollections of names. (The names should be related other than just by having been collected and placed in that collection.)
If I have already written the #include <iostream> header, I can overload operator<< for class A as follows:

std::ostream& operator<< (std::ostream& out,const A& obj);
true

You can qualify any name in a namespace using the namespace name and the scope resolution operator.
If I just write code, it is not in any namespace.
false

Every piece of code that is not explicitly put into a namespace is in the global namespace, and could be addressed using the scope resolution operator, as in ::name.
A namespace grouping requires a semicolon after the closing curly brace.
false

A namespace definition is not like a class definition, in which an object of class type can be defined at the class definition. A namespace is not a type, so such a definition is not possible. There is no need for the semicolon. (At least this is not a reason for the semicolon. This writer knows of no other reason for a terminating semicolon for a class-like construct.)
Some statements about separate compilation follow. Which are correct? Comment on all the answers in the explanation section, including the ones that are wrong.
Separate files for interface and implementation enhance reuse.
Separating interface and implementation can save considerable time.
Placing client and class implementations in separate files enhances project development.
Suppose the following code is embedded in an otherwise correct and complete program.

void f(); //global
namespace A
{
void g()
{
f(); //Does this call A::f()? Or the global f()?
}
void f();
}

What version of f() is called in g()?
The call is to the global f();

The scope of an identifier starts at its declaration and runs until shadowed. In g(), the global f() is in scope. A::f() is not available.
In a particular file, the names from the global namespace and names from an unnamed namespace defined in the file are accessed the same way: by writing the name.
true

To use either name, one just uses the name. The compiler knows the difference. However, if the unnamed namespace name and the global name are the same, use of that name will cause an ambiguity error. The compiler will not be able to distinguish them. There is no mechanism to use the unnamed namespace name, but the global name can be accessed by qualifying with just the scope resolution operator, for example, ::name.
A stream is a flow of data into or out of your program.
true
When you write

ifstream inStream;
inStream.open("infile.dat");

the file infile.dat must be located in the directory where the program is being run.
false

If infile.dat is not in the directory where the program is being run, you can supply a path in addition to the file name. The details are system dependent. Though this question is predicated on input, the same thing is true of output file streams.
You are doing a binary search of the dictionary for page where a word should be, using the recursive binary search. What are stopping cases?
The dictionary being searched has one page

To search a dictionary for the page where a word should be, one divides the dictionary into first half, middle page and last half. If the word is on the middle page, then stop. "The dictionary being searched has one page." Quit. Otherwise, if the word should be in the first half of the dictionary, recursively search the first half of the dictionary, else recursively search the second half of the dictionary.
The binary search algorithm in the text makes recursive on subarrays of the array passed to the algorithm. The range passed to the search function is first to last. The search algorithm makes recursive calls on the left or right subarray that target will be in, if the target is present. What are the left and right ends of the left subarray?
first, mid - 1

The middle element has been eliminated by the following code fragment that occurs before the recursive calls:

if(key == a[mid])
{
found = true;
location = mid;
}

The range will start with index first and run to index one before mid, namely, mid - 1. The rest of the answers have off-by-one errors, or they get the range backwards, or both.
The flush member function copies the file buffer to the file on the file medium (disk, tape, etc.).
true

For reasons of efficiency, files on disk are divided into blocks, usually of size between 512 and 4096 bytes. One or more blocks are kept in memory for reading and writing, and are copied to and read from disk (roughly) on an as-needed basis. The flush function copies the buffer to disk before the system would otherwise do so.
Which of the following is required in a recursive function?
one or more stopping cases that are guaranteed to be reached
one or more stopping cases after a sequence of calls to one or more recursive cases
C++ uses the system file name for the program file name.
false

Some languages do this but C++ requires that you declare a file stream variable and explicitly attach it to the system file name. System file names frequently have characters in them that are illegal in C++ names. This would place too strong a restriction on file names that C++ programs can manipulate.
How many times is the following code invoked by the call recursive(4)?

void recursive( int i )
{
using namespace std;
if (i < 8)
{
cout << i << " ";
recursive(i);
}
}
This is an infinite recursion.

This is an infinite recursion (or no recursion at all if i starts out greater than 8). There is no change in i to move closer to the non-recursive case of i >= 8.
cin is an output stream object of type ostream.
false

cin has type istream object, i.e., it is an input stream.
In a recursive solution to a problem, we solve a problem P(n) by solving another problem P(k) where
P(k) is the same problem as P(n) apart from size.
P(k) is smaller than P(n).
In recursion, it is unnecessary to decide whether a stopping case has been reached.
false

In recursion, termination requires that a stopping case be reached. It is necessary to decide whether this case has been reached.
A binary search works with any array of numbers.
false

One of the preconditions for the binary search in the text is that the array be sorted in increasing order.
A recursive function must not return a value.
false

Value returning and void recursive functions are certainly permitted.
A recursive function is one that
calls itself

To be a correct recursive function, enough more is necessary. At a minimum, there must be a guarantee termination.
It is proper for a recursion to run on without ending.
true

Nevertheless, a program that was written by a student at this level that does not terminate is likely to be wrong, whether the failure to terminate is due to an infinite loop or a recursion that does not stop. It is not true that every program that does not terminate is wrong. Some programs have an intentional infinite loop. Examples include an ATM program and reservation systems that typically have an outer loop that repeats the service menu forever. Windowing systems (a.k.a. graphical user interfaces, or GUIs) also have an event loop that does not terminate. This loop waits for an event such as a mouse click or keystroke.
In a recursive solution to a problem, we solve a problem P(n) by solving another problem P(k) where
P(k) is the same problem as P(n) apart from size.
P(k) is smaller than P(n).
In the binary search routine in the text, the first thing the code does is to check whether the object is not in the array. What is the test for this condition?
first > last

On each recursive call, first is increased and last is decreased. When these pass each other, this condition is true, so there are no more index values to test.
A recursive function can have only one recursive case.
false

There is no reason to prohibit multiple recursive cases, nor, for that matter, multiple stopping cases.
How many times is the following code invoked by the call recursive(4)?

void recursive( int i )
{
using namespace std;
if (i < 8)
{
cout << i << " ";
recursive(i);
}
}
This is an infinite recursion.

This is an infinite recursion (or no recursion at all if i starts out greater than 8). There is no change in i to move closer to the non-recursive case of i >= 8.
Which of the following is required in a recursive function?
one or more stopping cases that are guaranteed to be reached
one or more stopping cases after a sequence of calls to one or more recursive cases
You never put a declaration of an inherited member in the derived class.
false

The one exception to this rule is the need to redefine a base class member function in the derived class.
A derived class object inherits all the members of the base class. Which of these remarks about the inherited member variables are true?
Inherited members need to be allocated memory and should be initialized at creation of a derived class object.
Inherited members' memory allocation must be done by the base class constructor for the base class, which must be called.
The base class constructor is the most convenient place to initialize these inherited variables.
Given the class declaration:

class D : public class B {/*...*/};

which of the following is true?
Private members of B are inaccessible in D.
Public members of B become public members of D.
Protected members of B become protected members of D.
A programmer must have the source code for libraries to extend them, even using inheritance.
false

The programmer only needs the interface, including the type definition, to create derived classes to extend an existing library.
The ability to reuse objects already defined, perhaps for a different purpose, with modification appropriate to the new purpose, is referred to as
inheritance.

If class D inherits from class B, D automatically receives all of the members of B, and the members defined in D.
Suppose class Child is derived from class Parent that was in turn derived from class GrandParent. When we declare an object of class Child, three constructors are called: i) Child, ii) Parent, iii )GrandParent. What is the order?
GrandParent, Child, Parent

In an inheritance chain, the base class constructor is called first, then the constructor of the first class in the inheritance chain, and so on.
A base/member initialization list is preceded by
a single colon.
If B is a base class of D, then D's members cannot invoke private member functions of B without regard to the kind of inheritance.
true

With any kind of derivation -- public, protected, or private -- private function and data members of the base class are inaccessible to any function not declared in the base class.
Suppose class Child is derived from class Parent that was in turn derived from class GrandParent. The class Parent and GrandParent are the
ancestor classes of class Child.
Consider the class inheritance:

class B
{
public:
B();
B(int nn);
void f();
void g();
private:
int n;
};
class D: private B
{
public:
D(int nn, float dd);
void h();
private:
double d;
};

Which of the following functions can be invoked by an object of class D?
h()

Only h() is available to an object of class D. The inheritance is private. Although the members are public in the base class, objects of the derived class cannot access these members.
The binding of a virtual function is done at runtime if called using an object.
true

If the binding can be done at compile time, the compiler is smart enough to avoid the overhead of the virtual table.
Destructors are automatically virtual.
false

They are not virtual unless you include the modifier "virtual" in the destructor declaration.
A program decides after it begins to run what function to execute in response to a statement such as

refToObject.func()

is an example of
dynamic binding.
virtual functions.
late binding.
polymorphism.
No objects can be defined of abstract base class type since it is an incomplete definition.
true

Presence of a pure virtual function member makes a class abstract. A derived class must define the pure virtual member function or that member function must be pure virtual in the derived class and the derived class must itself be abstract. No objects can be defined of an abstract class.
Which of the following refer to the same topic?
late binding
polymorphism
virtual functions
This is legal code.

class B
{
public:
// . . .
virtual void f() = 0;
};
int main() { B b1, b2; /*. . .*/ }
false

This code attempts to define objects of an abstract class. The pure virtual function

virtual void f() = 0;

makes the class an abstract base class. Objects may not be defined of abstract base class type.
Virtual functions allow old code to call new code.
true

Take, for example, the base class (already defined) called Figure. Figure has a draw member function declared with the virtual keyword and a member center. The center function, to do its job, calls erase, then calls draw to center the figure. In this case, a programmer can derive a class Triangle from the already defined (old) code for Figure. The derived class can have a different implementation (new code) of the virtual function draw, which will be called by the center member function. Thus old code calls new code.
The base class destructor must be virtual.
false

There is no requirement that the base class destructor be virtual, but if pointers and allocation are involved, it is wise to do so. It is easy to construct examples where the derived class constructors allocate resources and the corresponding destructors are not called unless the base class destructor is virtual. Many authorities say destructors should always be virtual, but the compiler does not say that.
Suppose class D is derived from class B, and class B has a public member function whose declaration is virtual void f();. Suppose class D has its version of the function, void f(). Here is a function definition and an invocation:

void g( B& b)
{
// other code
b.f();
// other code
};

g( dObject );

Suppose this is embedded in an otherwise correct and complete program. Which version of f() will be called?
D::f()

When the functions are virtual, and access is made through a pointer or a reference (here a reference), the function called follows the type of the object.
It is useful to define a class for which no objects may be defined.
true

An abstract class is such a class. These are useful to prevent the implementation of incomplete class definitions and to force the implementation of pure virtual function members in the derived class.
In the template prefix template<class T> what kinds of variables can the parameter T be?
T can be any type, whether built into C++ or programmer defined, but subject to restrictions. Explain what these are.

Any type whether struct, enum, class, pointer, array, or any type built into C++ may be used. User defined types must have features used in the code. For example, the swapValues function requires a working operator assignment. A sort template function would probably require a working operator <.
A class template can be derived from a non-template class.
true
Templates provide an overloading of the function for every possible type that is consistent with the use in the template.
false

The compiler does not provide every possible overloading. Nevertheless, the compiler does behave as though overloadings for every possible type were present.
A non-template class can be derived from a class template instantiation.
true

This is ordinary inheritance.
In writing a class template, the function declarations within the class require special placement.
false

The member functions for a class template are defined the same way and put in the same location as member functions for ordinary classes. The only difference is that the member functions are themselves templates.
How many type parameters may a function template have?
as many as are needed

There is no restriction on the number of function template type parameters.
With regard to programming usage, consistency in coding is more important than optimality.
true

If one is inconsistent with many details in coding, the reader will make more errors than would happen otherwise.
The template prefix can be written template <typename identifier> or template <class identifier> with the same results.
true

The C++ Standard provides for use of either class or typename in here, but the text, recognizing common usage, has standardized on the use of the keyword class. Nevertheless, you may see this in code you read, so you should be able to recognize it.
In the implementation of a class template function, the class name before the scope resolution operator is just the class name, with no additional syntax.
false

If the template class name is Pair, the class name before the scope resolution operator must be Pair<T>, not just Pair. If only Pair is used, without the <T>, there will be no function instance generated, causing hard to understand error messages.
Suppose the swapValues template is instantiated as follows:

int x = 2, y =3;
swapValues(x, y);
// use x and y
x = 4; y =5;
swapValues(x, y);
// use x and y

The compiler generates code for two copies of the swapValues template.
false

The compiler generates code for one function of every type for which the template is instantiated. There is only one type; hence, there is only one copy of the function generated. The second call invokes the first instantiation.
Placing data on a stack is called popping the stack.
false

The correct term is pushing the item onto the stack.
Which of the following are potential problems when we assign pointer variables?
inaccessible heap memory

If only one pointer points to allocated memory, and that pointer has its pointer value changed so that it points some place else, there is no way to access or deallocate (delete) that memory. That memory remains locked up for the life of the program.
A linked list
can vary in size, shrinking or growing as there is need.
Which of these operations does an iterator class typically have?
overloaded operator!= to compare iterators and return false if the iterators do not point to the same item
overloaded increment and decrement operators to move the next node forward or backward, respectively
overloaded unary operator* that returns the item to which the iterator points
A queue is first-in-first-out data structure.
true

A queue is fair. Entries are serviced and removed from the queue in the order of arrival.
There is no need for error checking when popping a stack.
false

It is an error to attempt to remove data from an empty stack. Such an error is called a stack underflow.
Which of the following is in order processing for a binary tree?
i) process the left subtree
ii) process the root node data
iii) process the right subtree
What is the discipline for a stack?
Data last inserted is the data first out.

A stack is LIFO, last-in/first-out.
Insertion into a linked list takes the same number of operations no matter where the insertion occurs.
true

Given a pointer to the node in the list prior to position of the new node. In addition to allocation, it will require two operations to insert a node into this list. This is independent of the position in the list.
If a class is declared a friend of another class, typically the classes refer to each other. The classes cannot each be defined before the other. To refer to a class, the class must have been declared. This is accomplished by a
placing a declaration of one class prior to the definition of the other.
forward declaration.
Insertion into a linked list takes the same number of operations no matter where the insertion occurs.
true

Given a pointer to the node in the list prior to position of the new node. In addition to allocation, it will require two operations to insert a node into this list. This is independent of the position in the list.
A tree is a recursive structure.
true

Each tree is composed of two subtrees whose root nodes are the nodes pointed to by leftLink and rightLink of the root node.
The exception facility should be used when
a program encounters an error and cannot recover, but needs to shut down gracefully, perhaps saving work.
a program requests a resource that is not available.
an array index value is out-of-bounds.
A friend class is made to further a sense of community among the students.
false

Making class F a friend of class C is the equivalent of making every member function of F a friend of class C. The purpose is to grant to F's member functions access to C's private data members.
There is no need for error checking when popping a stack.
false

It is an error to attempt to remove data from an empty stack. Such an error is called a stack underflow.
A queue is first-in-first-out data structure.
true

A queue is fair. Entries are serviced and removed from the queue in the order of arrival.
Typically __________ causes an error that causes an exception to be thrown.
the author of the application code
the user who enters data
Data is inserted into a queue at the back.
true

Just like the lunch line, data is "added" at the back of the queue. Data is serviced at the front, and then removed once service is complete.
Which of the following are events that a programmer would want to throw an exception to manage?
Operator new fails to find sufficient memory in the free store to satisfy a call.
A user enters a name too long for the C-string buffer, threatening a buffer overflow.
Placing data on a stack is called popping the stack.
false

The correct term is pushing the item onto the stack.
Which of the following member functions do all the sequential containers (vector, list, deque) have? In the explanation, tell what the member does/returns.
push_back()
begin()
rbegin()
rend()
The operator * is prefixed to an iterator to
extract the element in the container as either an l-value or an r-value.
Which of the following operations do bidirectional iterators have?
overloaded operator++ to move the place the iterator points forward by one element
prefix operator* to make available the container element for use as l-value or r-value
overloaded operator-- to move the place the iterator points backward by one element
I have an algorithm that runs in O(N2), 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?
100 minutes
Which of the following are STL container types? In which containers does the position of an inserted element depend on the data and which does the order of insertion?
sequence containers
associative containers
container adapters
Suppose we have the following definition:

vector<int> vec;
// use push_back to put 10 values into vec here.
vector<int>::iterator itr1, itr2,itr3;
itr1 = vec.begin();
itr2 = vec.begin() + 5;
itr3 = vec.end();

For this iterator which of the following are correct? If correct, what does the expression produce?
itr2[3]
itr3 - itr1
itr3 + 3
itr2 - 3
*iter1
The expression 4N2-2N+1 is __________.
quadratic (degree 2)

The degree of the term with highest degree is 2. That is called quadratic. The terms of lower order will be completely "swamped" by the term in N2 for sufficiently large N. (See figure 19.15 page 822 in the text for the flavor.)
Which of the following are member functions of the queue adaptor template? For members of queue, specify any needed arguments.
empty()
push()
front()
size()
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?
about 3 minutes
Which of the following are Standard Template Library components?
iterators
template containers
generic algorithms
The Adaptor pattern transforms a class by layering a new interface over the class.
true

Typically, the stack and queue template adapter containers by default modify the interface of the deque container. These adapters hide the deque interface, and provide interface appropriate to stack and queue respectively.
This chapter (20) has described and applied the following patterns:
Divide and Conquer Sort
Adapter
Model-View-Controller
Container-Iterator
Iterator
UML has annotations for inheritance and data flow.
true

Inheritance is of importance in OOP, as is the flow of data between classes. Notation is provided.
Design patterns are restricted to particular programming languages, of which C++ is one.
false

One of the features of patterns and UML (Unified Modeling Language) is that they apply to any problem and any programming language that supports classes and features for Object Oriented Programming.
Which of the following are true of the Model-View-Controller pattern?
This pattern presents a way to separate (at least logically) I/O from the process part of the application.
In this pattern, the Controller is the input portion of the task.
In this pattern, the Controller accepts data and commands from the user, it sends the to the Model. The Model processes commands, operates on the data, and changes the state of the program, notifies the View. The View presents the state of the program.
Consider the quick sort algorithm as implemented in the text using the sort pattern. Which of the following data characteristics give the fastest run time? Explain.
an array of random values

An array of random values will have the least chance of having the split create consistently equal subarrays, hence give a runtime of O(N log N). All the other choices guarantee split gives subarrays of size 1 and N-1, hence give quadratic performance.
If the sort pattern split routine consistently splits the array into two pieces of equal size the runtime is:
O(N log N)
UML requires that the programmer understand every detail and dark corner of C++ to be useful.
false

You need the mainstream parts of C++, including the parts that support OOP. If the student has an understanding of much of this book, UML should not be a problem for her.
UML provides no facility for describing libraries.
false

Actually, UML has annotations for library-like aggregates.
Patterns are so general they need not make assumptions about the application(s) to which they are being applied.
false

To be substantive, each pattern must make assumptions about its application. The iterator pattern applies to very nearly all containers, but to apply the iterator pattern to a container, the iterator designer must know the structure of the container. You don't create efficient random access iterators for a doubly linked list.