C S 235: Data Structures; Exam 1

¡Supera tus tareas y exámenes ahora con Quizwiz!

What is a C++ concept? a. A C++ concept serves as a constraint by limiting the set of arguments that are accepted as template parameters. b. Concepts are an instantiation of a C++ template. c. Concepts can be used to introduce types to template programming. d. Violations of constraints are detected at run time.

a. A C++ concept serves as a constraint by limiting the set of arguments that are accepted as template parameters.

What is true of C++ strings? a. A C++ string is an alias for a basic_string<char> b. Character arrays and strings are identical. c. Memory for a C++ string must be pre-allocated. d. C++ strings lose type and dimension when passed to a function.

a. A C++ string is an alias for a basic_string<char>

What is TRUE of the friend functions? a. A friend function is a non-member function with access to the class private and protected members. b. Friend function in a class definition are member functions of that class. c. Friendship is inherited. d. If A is friend of B, then B automatically becomes a friend of A.

a. A friend function is a non-member function with access to the class private and protected members.

Which of the following is an example of an 'is-a' relationship? a. A jet plane is a plane b. A plane is a jet plane. c. A train engine is a train. d. A train is a train engine.

a. A jet plane is a plane

What kind of pointer should be included in a singly linked node? a. A pointer to the next node. b. A pointer to the previous node. c. A pointer to the beginning of the list. d. A pointer to the end of the list.

a. A pointer to the next node.

How are iterators implemented? a. All STL iterators support pre- and post- increment operators. b. Dereferenced iterators return const items. c. Iterators are always implemented as nested structs. d. Post-increment operators return a new reference to the iterator.

a. All STL iterators support pre- and post- increment operators.

_______ errors probably exist in a significant portion of commercial software. a. Logic b. Run-time c. Syntax d. Waterfall

a. Logic

What order is used in the C++ tool chain? a. Compiler, preprocessor, assembler, linker. b. Compiler, preprocessor, linker, assembler. c. Preprocessor, compiler, assembler, linker. d. Preprocessor, compiler, linker, assembler.

c. Preprocessor, compiler, assembler, linker.

What would be the Big O of a reserve function which creates a new array that is twice the size of the current array for an object of class Vector, and copies the contents from the old array into the new array? a. order 1 b. order n c. amortized order 1 d. amortized order n

c. amortized order 1

The pre-processor conditional compilation directives a. act the same as the /*...*/. b. are evaluated at run-time. c. are used to eliminate lines at compilation time. d. cannot be nested.

c. are used to eliminate lines at compilation time.

The separation of what is to be done from how it is to be done is called: a. data abstraction. b. information hiding. c. procedural abstraction. d. top-down design.

c. procedural abstraction.

Which of the following is an example of an 'has-a' relationship? a. A jet plane is a plane b. A plane is a jet plane. c. A train engine is a train. d. A train has a train engine.

d. A train has a train engine.

Which of the following stack configurations are correct in terms of precedence? Let the far left be the bottom of the stack, and the right be the top. a. + % b. * - c. + + d. / *

a. + %

What is true of translation units? a. All source files, together with their included header files, are called the translation unit. b. Translation units are compiled into object files that are joined together by the the linker. c. Local objects in a source file are accessible across translation units. d. A single translation unit can't be compiled into a library.

a. All source files, together with their included header files, are called the translation unit.

What is true of C++ streams? a. The class istream defines the extraction operator (>>) for primitive data types. b. A stream is an entity where a program can only extract characters. c. The stream class istream inherits from the class ifstream. d. File streams associate streams with C++ data types.

a. The class istream defines the extraction operator (>>) for primitive data types.

What is NOT true of a const_iterator and the iterator? a. The compiler ensures that any attempt to do so results in an error. b. The const in the operator heading means that the reference item can be changed. c. The dereferencing operator returns a const reference. d. The member access operator returns a const pointer.

a. The compiler ensures that any attempt to do so results in an error.

Both the client and programmer can do _________ testing. Typically only the ________ does ______ testing. a. black box; programmer; white box. b. closed-box; client; glass box. c. functional; client; open box. d. white box; programmer; functional.

a. black box; programmer; white box.

What is the matching postfix expression to the following infix expression: 7 + (2 * 3) / 9 ? a. 7 2 3 * + 9 / b. 7 2 3 * 9 / + c. 2 3 * 9 / 7 + d. There is none, it is an invalid expression.

b. 7 2 3 * 9 / +

What is true of an iterator? a. All iterators have the same functionality as pointers. b. An iterator is an object pointer to an item that is part of a larger container of items. c. Iterators are only used for accessing container items. d. Most iterators only support pre-decrement operators.

b. An iterator is an object pointer to an item that is part of a larger container of items.

What is the best way to visit every node of a circular list exactly once? a. Add a boolean data member and set it after a node is visited. b. Begin at the head and ask if the next node in the list is the head. c. Count the nodes and use a for loop. d. Set the data member to a value (such as NULL or 0 or """) to mark it as visited.

b. Begin at the head and ask if the next node in the list is the head.

Pick the best statement: a. Both the preconditions and postconditions must be met. b. If the preconditions are met, the postconditions must be achieved. c. If the preconditions are not met, the postconditions will not be achieved. d. The preconditions and postconditions are independent of each other.

b. If the preconditions are met, the postconditions must be achieved.

Which of the following is NOT a disadvantage of a singly linked list compared to a doubly linked list? a. Nodes in a singly linked list contain more data than nodes in a doubly linked list. b. A singly linked list can only insert a node after a node we have a pointer to. c. A singly linked list can only be traversed in the forward direction. d. A singly linked list can remove a node only if it was a previous node.

a. Nodes in a singly linked list contain more data than nodes in a doubly linked list.

What typically happens as a consequence of the ++iter component of: for (list<Item_Type>::iterator iter = a_list.begin(); iter != a_list.end(); ++iter) { // Sequence of statements } a. The iterator pointer advances to the next element of the list. b. The value of the data element referenced by the iter is incremented by 1. c. The value of the data element referenced by iter is incremented by one and the iter advances to the next element of the list. d. The iterator pointer advances to the next element of the list and the value of the data element now referenced by the iter is increases by one.

a. The iterator pointer advances to the next element of the list.

To check for balanced parentheses, use a stack of: a. parentheses. b. operators and operands. c. operands. d. operators.

a. parentheses.

What is true about the main function? a. Command line parameters are passed thru three arguments to the main() function. b. The 1st parameter of main() is the number of arguments and the 2nd is an array of char* pointers to those arguments. c. The main() function parameters are always called argc and argv. d. The main() function parameters are required even when they are not used.

b. The 1st parameter of main() is the number of arguments and the 2nd is an array of char* pointers to those arguments.

What is the difference between variable scope and lifetime? a. The lifetime of a variable is the region of the code where variable can be accessed. b. The lifetime of an object is the time duration where an object is in a valid state. c. A static local variable has limited scope but an unlimited lifetime. d. Two variables with the same name always exhibit undefined behavior.

b. The lifetime of an object is the time duration where an object is in a valid state.

The most obvious from of an iterator is: a. & operator. b. a pointer. c. destructor d. an at operator.

b. a pointer.

Why is a Node typically defined as a struct in the private part of a host class? a. Because structs cannot be #included. b. Because C++ allows inner structs, but not inner classes. c. Because a struct's data members are public by default. d. To permit multiple containers to have Nodes as data members.

c. Because a struct's data members are public by default.

What features are considered fundamental by the C++ standard on containers? a. Containers grow as needed. b. Containers hold objects. c. Both of the above. d. None of the above.

c. Both of the above.

What best describes a C++ template? a. A template saves memory by reusing code. b. All possible class templates are defined at run-time. c. C++ uses a class template as a pattern to create a new class of a specified type. d. Templates can only be used to build classes.

c. C++ uses a class template as a pattern to create a new class of a specified type.

Why are iterators useful? a. All containers have the same iterator capabilities and hence the choice of the container doesn't matter. b. Iterators are faster than pointers. c. Iterators isolate the user from the internal structure of a container. d. You cannot sort a container without an iterator.

c. Iterators isolate the user from the internal structure of a container.

What is the principal advantage of having a template class? a. It serves as a skeleton from which other classes can be built. b. It serves as the root of a(n anticipated) hierarchy. c. Its ability to contain different types of data (determined at run time). d. Its ability to contain different types of data (determined at compile time)

c. Its ability to contain different types of data (determined at run time).

Inclusion of the keyword const in a function header does all of the following EXCEPT: a. alert the user that the function will not change values. b. disallow changes in values. c. force the return type to be a constant. d. incorporate optimizations.

c. force the return type to be a constant.

In a class that contains a pointer to a dynamically allocated int, the destructor ________ delete the pointer because _________. a. should not, primitive data types are handled automatically. b. should not, ints do not cause memory leaks, only classes. c. should, the memory pointed to by the pointer must be freed to prevent memory leaks. d. should, every data member of a class should be deleted in the destructor.

c. should, the memory pointed to by the pointer must be freed to prevent memory leaks.

There are two general ways to implement ADT stacks. These are: a. using an array or vector. b. using a single-linked list or a double-linked list c. using a contiguous structure or a linked structure. d. (none of the above; always use the standard library implementation)

c. using a contiguous structure or a linked structure.

With an iterator named iter, how would the data in the iterator be accessed? a. iter* b. iter& c. &iter d. *iter.

d. *iter.

What is the matching infix expression to the following postfix expression: 8 9 + 4 * - ? a. - ((8 + 9) * 4) b. ((8 + 9) * 4) c. - (8 + 9 * 4) d. There is none, it is an invalid expression.

d. There is none, it is an invalid expression.

Which of the following is TRUE of UML diagrams? a. A UML "Has-a" relationship is indicated with a white triangle arrowhead facing the parent class. b. A UML "Is-a" relationship is indicated with a filled diamond arrow. c. The circle with a cross through it indicates an inheritance relationship. d. UML virtual functions are italicized.

d. UML virtual functions are italicized.

Which of the following describes testing the smallest testable piece of the software? a. Acceptable testing. b. Integration testing. c. System testing. d. Unit testing.

d. Unit testing.

Which of the following IS NOT included in the C++ memory model? a. Heap. b. Initialized data. c. Stack. d. Virtual memory.

d. Virtual memory

Suppose the following operations are performed on an empty stack: Push A, push B, push C, push E, pop, and push D. What would be the next value to be accessed from this stack? a. A b. B c. C d. D

d. D

Which of the following is in correct descending precedence order? a. () ~ == || b. [] << + % c. * (unary) * & + d. & && ^ |

a. () ~ == ||

What is C++ object delegation? a. Delegation allow exposure to some functionality of a pre-existing class, but still control access through your own interface. b. Delegation and inheritance are the same concept. c. Delegation is when an object of one is a data member in another class. d. Delegation refers to one object being independent of another object but providing same functionalities.

a. Delegation allow exposure to some functionality of a pre-existing class, but still control access through your own interface.

What is NOT TRUE about switch statements? a. Every case needs to contain a break. b. It is not required that each case be enclosed in braces. c. The expression used in a switch statement must have an integral enumerated type. d. When a break statement is reached, control jumps to the next line following the switch statement.

a. Every case needs to contain a break.

What is the fundamental flaw with the Waterfall software development model? a. It assumes that each stage can be completed correctly and fully before advancing to the next stage. b. It ignores the "salmon" among us. c. It is not compatible with object-oriented programming. d. It requires some stages which skilled programmers can safely omit.

a. It assumes that each stage can be completed correctly and fully before advancing to the next stage.

A private data member is visible: a. in the class in which it is declared. b. nowhere. c. (a) and in all derived classes d. (a) and in any class that 'has-a' object of the class in which it is declared.

a. in the class in which it is declared.

Software practitioners sometimes object to the term "bugs" because: a. it tends to trivialize potentially serious consequences of program defects. b. there are three general categories of defects or errors, not just one. c. they consider it inappropriate to assign life-like characteristics to any aspect of computing. d. we no longer use vacuum-tube computers where insects could intrude.

a. it tends to trivialize potentially serious consequences of program defects.

All of the following are true of iterators EXCEPT: a. the iterator end() function returns a pointer to the last element on the container. b. iterators allow you to traverse container members using pointer-like semantics. c. iterators provide abstraction away from the "how" to traverse a container. d. iterators are in essence improved versions of pointers from C. e. iterators in STL allow algorithms to be written independent of the manner in which the data is stored.

a. the iterator end() function returns a pointer to the last element on the container.

Suppose you want to access the next element of a stack. Which function would you call? a. top() b. pop() c. push() d. next()

a. top()

The default copy constructor may be used EXCEPT: a. when a deep copy is required. b. when an object is constructed based on another object of the same class. c. when an object of the class is passed (to a function) by the value as an argument. d. when an object of the class is returned by the value. e. when the compiler generates a temporary object.

a. when a deep copy is required.

What is true of C++ pointer variables? a. A pointer variable contains the variable value. b. Array pointers enable us to conveniently process groups of data such as vectors, lists, and strings. c. Pointers prevent functions from modifying the arguments passed by the called function. d. The ampersand (&) indicates that the following identifier is a pointer variable.

b. Array pointers enable us to conveniently process groups of data such as vectors, lists, and strings.

What is the difference between const and the pre-processor directive #define? a. A symbolic debugger is able to resolve #define directives. b. As a general rule you should give the compiler preference to the preprocessor. c. The C++ compiler always sees the #define directive. d. The used of const always yields smaller code size.

b. As a general rule you should give the compiler preference to the preprocessor.

Which of the following describes testing the interactions among smaller units? a. Acceptance testing. b. Integration testing. c. System testing. d. Unit testing.

b. Integration testing.

In what order should catch clauses appear? a. It makes no difference. b. Most specific to most general. c. Most general to most specific. d. All of the above.

b. Most specific to most general.

Which of the following is true about multiple inheritance? a. C++ does not support multiple inheritance. b. Multiple inheritance can often be avoided by refactoring. c. The constructors of inherited classes are called in reverse order in which they are inherited. d. With multiple inheritance, all the variables of the base class have different names.

b. Multiple inheritance can often be avoided by refactoring.

If one class has two functions with the same name, but that take different arguments, this is an example of: a. Overriding. b. Overloading. c. An error. d. Polymorphism.

b. Overloading

For which type of error are try and catch most appropriate? a. Logic errors. b. Run-time errors. c. Syntax error. d. All of the above.

b. Run-time errors.

What is regression testing? a. Testing code against old versions to make sure that progress is being made. b. Testing to make sure a change did not have an unintended consequence. c. Testing your code to make sure that it did not degrade over time. d. Writing new tests for old versions of code.

b. Testing to make sure a change did not have an unintended consequence.

What happens if an exception is thrown in a program and not caught? a. The compiler crashes. b. The program aborts. c. The program begins executing again from the point the exception was thrown. d. The program will not compile.

b. The program aborts.

/* /* This is an invalid command. Why? */ */ a. Comments should start with the # character. b. You cannot nest comments. c. Single line comments can only be done with // d. The outer comment would be empty, and empty comments are not allowed.

b. You cannot nest comments.

Which of the following is NOT a reason to override a function? a. You are writing a function to implement an ADT. b. You made a child class so you need to override every function. c. You want to change the functionality of a derived class. d. You want to add to functionality of the base class.

b. You made a child class so you need to override every function.

A template class typically: a. accommodates a variety of containers that have the same set of core operations. b. facilitates the same set of operations on a variety of data types. c. is a class (such as vector) that has a data member of another class (such as array). d. is an abstract class without a specific implementation.

b. facilitates the same set of operations on a variety of data types.

A private data member is visible: a. nowhere. b. in the class in which it is declared. c. (b) and in all derived classes. d. (c) and in any class that instantiates an object of the class in which it is declared.

b. in the class in which it is declared.

Inserting at the head of a single-linked list is ________ inserting at the tail. a. equivalently efficient to b. more efficient than c. less efficient than d. impossible, bu if there is sufficient available space, it is reasonable to think in terms of doing so.

b. more efficient than

A vector is _________ efficient than an array __________. a. more, in terms of execution time and memory usage. b. more in terms of coding time, but not execution time or memory usage. c. less, in terms of coding time. d. less, for any reasonable definition of efficiency.

b. more in terms of coding time, but not execution time or memory usage.

The scope of a variable refers to: a. logical groups that prevent name collision from multiple file includes. b. the region or section of code where a variable can be accessed. c. the time duration when a variable is in a valid state. d. which translation unit is being referenced.

b. the region or section of code where a variable can be accessed.

What is the result of the postfix expression 4 7 * 20 - ? a. -136 b. -52 c. 8 d. There is none. It is an invalid expression.

c. 8

What is FALSE concerning pointers and references? a. A pointer variable can be assigned a value at any time, while a reference variable cannot be re-assigned. b. A pointer variable is a variable that holds a memory address. c. A reference variable has a different memory address than the item it references. d. A reference variable is an alias for an already existing variable.

c. A reference variable has a different memory address than the item it references.

Which of the following is TRUE concerning abstract classes and concrete classes? a. Concrete classes can define variables, but abstract classes cannot. b. Concrete classes can extend another class, but abstract classes cannot. c. Abstract classes can declare abstract member functions, but concrete classes cannot. d. Abstract classes can extend another class, but concrete classes cannot.

c. Abstract classes can declare abstract member functions, but concrete classes cannot.

Which of the following is NOT a reason to use a linked list over a vector? a. Removal from a linked list is more efficient. b. Inserting at the beginning of a linked list is more efficient. c. Accessing any given element in a linked list is more efficient. d. All of the above are reasons why the linked list is superior.

c. Accessing any given element in a linked list is more efficient.

Pick the best statement: a. An ADT is represented by a .cpp file. b. An ADT is represented by a .h file. c. An ADT is represented by a class consisting of abstract functions. d. An ADT is represented by the combination of a .h file and an associated .cpp file.

c. An ADT is represented by a class consisting of abstract functions.

Which of the following most accurately describes the behavior of a stack? a. First in, first out. b. Last in, last out. c. Last in, first out. d. None of the above.

c. Last in, first out.

If N = size / 2 and M = size * size, what is the Big-O of the following: for(i = 0; i < N; i++) { // Sequence of statements } for (j = 0; j < M; j++) { // Sequence of statements } a. O(max(N, M)) b. O(N x M) c. O(n^2) d. O(n)

c. O(n^2)

What is NOT true of an array? a. An array name is the address of its first element. b. Statically declared arrays are allocated memory at compiler time. c. The C++ compiler is able to deduce an array size from the array pointer. d. You can use array notation (e.g., int[]) or a pointer notation (e.g., int*) in a function declaration.

c. The C++ Compiler is able to deduce an array size from the array pointer.

Why is the list class required to have a push_front function, but the vector is not? a. It is impossible to add something to the front of a vector. b. The list class was designed later, and the push_front function had not been thought of yet. c. The push_front function would be O(n), and the function must be at least amortized constant time to be required. d. The list class has a vector, and it adds more functionality.

c. The push_front function would be O(n), and the function must be at least amortized constant time to be required.

Suppose we are writing a program with polymorphism, but only our base class functions are being called. What is likely the source of our bug? a. We are not using pointers. b. We forgot to make the derived classes inherit from the base class. c. We have forgotten to make our base class functions virtual. d. We forgot to #include the base class in the derived .h class.

c. We have forgotten to make our base class functions virtual.

What is the advantage of placing the word const in the function declaration and in the function definition? a. Any operation that could modify the object is flagged. b. it facilitates optimizations in the machine code. c. This tells the user that the function will not modify the associated object. d. All of the above are true.

d. All of the above are true.

Polymorphism expects: a. functions with common signatures at different levels in hierarchy. b. functions with common signatures at different levels, with at least the highest-level function declared virtual. c. pointers to objects (probably to objects higher in the hierarchy). d. All of the above.

d. All of the above.

Suppose we are trying to use multiple inheritance, but the compiler reports that there is an ambiguity about our variable named 'var'. What can we do to resolve this error? a. Refactor the parent classes by combining them. b. Rename the variable of one of the parent classes. c. Specify which parent you are taking the variable from with 'Parent::var". d. All of the above.

d. All of the above.

Which of the following is a FALSE statement? a. An abstract class can extend another abstract class. b. An abstract class cannot be instantiated. c. Pointers to an abstract class may be declared. d. An abstract class contains only abstract functions.

d. An abstract class contains only abstract functions.

Which of the following most closely describes the functionality of a debugger? a. It sweeps your code and fixes bugs it encounters. b. It allows you to run your code directly from the IDE. c. It underlines in red all the parts of the program that are syntactically incorrect. d. It allows you to monitor the variables at individual steps during the execution of the program.

d. It allows you to monitor the variables at individual steps during the execution of the program.

An abstract data type (ADT) has all of the following EXCEPT: a. a name. b. a set of data elements. c. a set of operations. d. an implementation.

d. an implementation

What is the proper relationship between a class List and class Ordered_List? a. class List has-a Ordered_List. b. class List is-a Ordered_List. c. class Ordered_List is-a List. d. class Ordered_List has-a List.

d. class Ordered_List has-a List.

To convert from infix (without parentheses) to postfix, use a stack of: a. parentheses. b. operators and operands. c. operands. d. operators

d. operators

Which of the following CANNOT be overloaded? a. the << operator. b. the <= operator. c. the == operator. d. the dot operator.

d. the dot operator.

What is the output of the following code fragment? double d = 53.12345; cout << setprecision(3) << "|"; cout << left << fixed << setfill('-'); cout << setw(10) << d << "|" << endl; a. | 53.12345| b. |----53.123| c. |-53.12345 | d. |53.123----|

d. |53.123----|

Streams are used for input and output. What else? a. The console is represented by input stream cin and output stream cout. b. You can declare your own input (or output) streams as type ifstream (or ofstream) objects. c. Class istringstream extends istreams to extract from a string. d. Output files can be formatted using I/O manipulators. e. All of the above

e. All of the above

Which of the following are part of the C++ federation? a. C. b. Object-Oriented C++ c. Standard Library Templates (STL) d. Template Metaprogramming (TMP) e. All of the above.

e. All of the above

Which of the following may be included in C S 235 C++ header files? a. Executable code and object instantiations where needed. b. Inline functions of any length. c. Pre-processor macros. d. Use of #pragma once to guard header inclusion. e. None of the above.

e. None of the above


Conjuntos de estudio relacionados

Articles of Confederation & Shay's Rebellion

View Set

Postpartum Hemorrhage: Postpartum Oxytocin

View Set

THE EXOTIC FETISHIST - THE ART OF SEDUCTION - ROBERT GREENE

View Set

ACSM CH4: Health-Related Physical Fitness Testing & Interpretation - Body Composition

View Set

Potential Bone Growth and Growth in Length of Long Bones ( PART 7)

View Set

Unit 7: Chapter 14: The Power of Art

View Set

PH Chapter 15 & 16 - Opioid Analgesics & Opioid Antagonists

View Set