COSC 052 Midterm 1

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

By default, all members of a class are public. a. true b. false

b. false

Physical queues are routine in day-to-day life, but queue data structures are uncommon in compute operating systems. a. true b. false

b. false

The advantage of the linear search is its efficiency, however it is difficult to understand and complex to implement. a. true b. false

b. false

The binary search is a(n) ____________________ algorithm that is much more ____________________ than the linear search. awesome/awesome clever/efficient simple/recursive n^2/asymptotic

clever/efficient

Arithmetic expressions that we typically write use _____________________ notation. prefix dequeue infix postfix

infix

Consider the following function stub: LL_iterator LL::begin() { } Select the best option from the given choices for this method's implementation code. return LL_iterator(NULL); return LL_iterator(head); return LL_iterator(tail); cout << "Hello World!" << endl;

return LL_iterator(head);

Copy of Consider the following function stub: int& LL_iterator::operator*() const { } Select the best option from the given choices for this method's implementation code. return current->info; return current; return *current; cout << "Hello World!" << endl;

return current->info;

A try block must be followed by one or more catch blocks. a. true b. false

a. true

Dynamically allocated data structures may be linked together in memory to form a chain. a. true b. false

a. true

Existing classes, from which you create new classes, are called ____ classes. a. child b. base c. sibling d. derived

b. base

If a circular linked list is empty, then its tail pointer points to itself. a. true b. false

b. false

Consider the program below. What is output when this program executes? #include <iostream> #include <vector> #include <exception> #include <stdexcept> using namespace std; int main() { try { vector<int> a; a.push_back(132); a.push_back(126); a.push_back(49); a.push_back(13); a.push_back(20); int i = 40; if ( i > 4 ) throw "ERROR: index is out of range!"; cout << "a[i] = " << a.at(i) << endl; } catch(out_of_range) { cout << "caught out_of_range exception in function main...\n"; } catch(...) { cout << "unknown exception caught in function main...\n"; } return 0; } a. caught out_of_range exception in function main... b. unknown exception caught in function main... c. nothing, lines 13 and 14 are incorrect and will cause a compile-time error. d. nothing, lines 13 and 14 are incorrect and will cause a run-time error. e. a[i] = 13 f. a[i] = 20 g. a message that the program crashed with an uncaught exception h. a message that a segmentation fault occured

b. unknown exception caught in function main...

A linked list class that uses iterators provides the following member functions specifically for that purpose. init() default constructor begin() end()

begin() end()

The _____________________ search algorithm repeatedly divides the portion of an array being searched in half. linear binary bubble selection

binary

What will the following program display on the screen? #include <iostream> using namespace std; class Tank { private: int gallons; public: Tank() { gallons = 50; } Tank( int gal ) { gallons = gal; } int getGallons() { return gallons; } }; int main(int argc, const char * argv[]) { Tank storage1, storage2, storage3(20); cout << storage1.getGallons() << endl; cout << storage2.getGallons() << endl; cout << storage3.getGallons() << endl; return 0; } a. 50 50 50 b. 50 50 20 c. 50 50 20 d. 20 20 20

c. 50 50 20

The process of beginning at the head of a list and going through the entire list while doing some processing at each node is called ______________ the list. a. processing b. deallocating c. traversing d. filtering

c. traversing

If I write code that dynamically allocates memory with the operator new, I must remember to deallocate that memory using the operator delete. Failing to do so results in a(n) ___________________ . a. good grade b. recursion c. infinite loop d. memory leak

d. memory leak

Assume that an iterator class having identifier LL_iterator exists. The iterator class implements an overloaded dereferencing operator: LL_iterator::operator*(). The return value for this operator is ________________________. an LL_iterator object The value stored in the current data member of the LL_iterator object (e.g. the address of the node to which the iterator points) a pointer to a linked list object a reference to the info data member of the node to which the iterator points

a reference to the info data member of the node to which the iterator points

In C++, ____ is called the address operator. a. & b. * c. # d. ->

a. &

A ____ sign in front of a member name on a UML diagram indicates that this member is a public member. a. + b. - c. # d. $

a. +

Inheritance is an example of a(n) ____ relationship. a. is-a b. has-a c. was-a d. had-a

a. is-a

In C++, an array name is a constant pointer. a. true b. false

a. true

Using a function template is no different than using overloaded functions. a. true b. false

b. false

A programmer-defined copy constructor must have a single parameter that is a reference to the _________ class. a. public b. same c. vector d. string

b. same

A thrown exception could go uncaught if _______________________________________. a. it flies over the fence. b. the program contains no catch blocks with an exception parameter of the correct data type. c. the exception is not an instance of a class. d. the function does not have nested try blocks. e. it is thrown from outside a try block.

b. the program contains no catch blocks with an exception parameter of the correct data type. e. it is thrown from outside a try block.

If I implement a stack data structure using a dynamically allocated array to store the elements on the stack, it is still considered a static stack. a. true b. false

b. true

The ________________________ search algorithm requires that the array's contents be sorted. linear binary bubble selection

binary

There are ________ possible ways for a thrown exception to go uncaught. a. 0 b. 1 c. 2 d. infinite

c. 2

If the programmer does not specify a copy constructor for a class, then the compiler calls a default copy constructor when necessary; resulting in a ________ assignment. a. wrong b. partial c. memberwise d. pointer

c. memberwise

A data structure that points to an object of the same type as itself is known as a(n) ____________________ data structure. a. recursive b. dynamic c. self-referential d. linked

c. self-referential

The beginning of a template is marked by a(n) _________________. pound symbol (#) template prefix capital letter return type

template prefix

Two linked list iterator objects are equal if _____________________________________________________. they both store the same memory address in their current data member the value stored in the info data member of the node object to which they point is equal the address of each iterator object is the same this is a trick question, two iterator objects cannot be equal

they both store the same memory address in their current data member

When writing function or class templates, you use a(n) _____________________ to specify a generic data type. catch block specification type parameter template prefix

type parameter

A copy constructor is automatically called in the following situations: a. When an object is being created and initialized with another object of the same class b. When an object goes out of scope c. An instance of a class with at least one friend function is instantiated d. An object is passed by value as an argument to a function d. A function returns an instance of a class, by value e. An instance of a class is instantiated and the class has no constructors with parameters f. An instance of a base class is instantiated

a. When an object is being created and initialized with another object of the same class c. An object is passed by value as an argument to a function d. A function returns an instance of a class, by value

Consider the program below. What is output when this program executes? #include <iostream> #include <vector> #include <exception> #include <stdexcept> using namespace std; int main() { try { vector<int> a; a.push_back(132); a.push_back(126); a.push_back(49); a.push_back(13); a.push_back(20); cout << "a[3] = " << a.at(30) << endl; } catch(out_of_range) { cout << "caught out_of_range exception in function main...\n"; } catch(...) { cout << "unknown exception caught in function main...\n"; } return 0; } a. caught out_of_range exception in function main... b. unknown exception caught in function main... c. nothing, lines 13 and 14 are incorrect and will cause a compile-time error. d. nothing, lines 13 and 14 are incorrect and will cause a run-time error. e. a[3] = 13 f. a[3] = 49 g. a message that the program crashed with an uncaught exception h. a message that a segmentation fault occured

a. caught out_of_range exception in function main...

From the list below, select the three characteristics of Object Oriented Design (OOD) / Object Oriented Programming (OOP). a. polymorphism b. difficulty c. instantiation d. inheritance e. encapsulation f. entropy g. composition h. parametrization

a. polymorphism d. inheritance e. encapsulation

A class and its members can be described graphically using Unified Modeling Language (UML) notation. a. true b. false

a. true

A derived class can redefine a public member function of the base class. a. true b. false

a. true

A function template is not a function, but rather a "generic pattern" for generating functions that can work with different data types. a. true b. false

a. true

A pointer variable is a variable that stores the address of a memory location. a. true b. false

a. true

A stack is a data structure that stores and retrieves items in a last-in-first-out (LIFO) manner. a. true b. false

a. true

An exception can propagate backwards along the chain of functions calls until the exception is thrown out of a try block that has a catch block that can handle it. a. true b. false

a. true

Consider the following function template. template <typename T> T surprise(T x, T y) { return x * y; } The output of the statement cout << surprise(3, 4) << endl; is 12. a. true b. false

a. true

Given the declaration int *p; The statement p = new int[50]; dynamically allocates an array of 50 elements of type int and p contains the address of the first element in the array. a. true b. false

a. true

If a circular linked list contains only one Node, then that Node's next pointer points to itself. a. true b. false

a. true

If p is a pointer variable, the statement p = p + 1; is valid in C++. a. true b. false

a. true

In many cases, a program will need to test for several different types of errors and signal which one has occured. a. true b. false

a. true

Iterators are objects that behave like pointers. a. true b. false

a. true

Linear and binary searches can also be used to search for a specific entry in an array of objects or structures. a. true b. false

a. true

Templates may be used to create generic classes and abstract data types. a. true b. false

a. true

The preprocessor directive #ifndef is used to prevent multiple inclusions of a header file in a program. a. true b. false

a. true

Using operator overloading, it is possible to cange an operator's entire meaning. a. true b. false

a. true

When a throw statement is executed, control is passed to another part of the program known as an exception handler. a. true b. false

a. true

The basic operations of a circular linked list are: push_back empty push_front add front back traverse clear remove advance

add remove front back advance empty

basic linked list operations are: adding an element to a list making a copy of the list printing the list contents in order sorting the list removing an element from the list traversing the list partitioning the list destroying the list

adding an element removing an element traversing the list destroying the list

A ____ sign in front of a member name on a UML diagram indicates that this member is a private member. a. + b. - c. # d. $

b. -

What is the output of the following code? int *p; int x; x = 12; p = &x; cout << x << ", "; *p = 81; cout << *p << endl; a. 12, 12 b. 12, 81 c. 81, 12 d. 81, 81

b. 12, 81

____ is the ability to combine data, and operations on that data, in a single unit. a. inheritance b. encapsulation c. polymorphism d. composition

b. encapsulation

A class can have more than one destructor. a. true b. false

b. false

A derived class can directly access any member of the base class. a. true b. false

b. false

A derived class cannot directly access public members of a base class. a. true b. false

b. false

A function template is an actual function. a. true b. false

b. false

A linked list consists of a series of self-referential objects. Each object has a pointer to the next object in the list. This is the only possible design of a linked list. a. true b. false

b. false

A pointer variable is declared using an ampersand (&) character. a. true b. false

b. false

A queue is a data structure that stores and retrieves items in a last-in-first-out (LIFO) manner. a. true b. false

b. false

A stack can be useful in a hand held calculator, but in computer software, stacks are not very useful. a. true b. false

b. false

All operators can be overloaded as member functions of the class. a. true b. false

b. false

Constructors are called like any other function. a. true b. false

b. false

Exceptions are used to signal errors or unexpected events that occur at compile time. a. true b. false

b. false

Exceptions signal errors or unexpected events that occur when code is compiled. a. true b. false

b. false

If a stack is implemented as a linked list, it is still considered to be a static stack. a. true b. false

b. false

In C++, &p, p, and *p all have the same meaning. a. true b. false

b. false

The enqueue operation returns true if the value specified is stored in the queue. a. true b. false

b. false

The process of propagating uncaught exceptions from a function to its caller is called propagating the stack of function calls. a. true b. false

b. false

There is no way to definitively indicate the end of a linked list. a. true b. false

b. false

When a node is inserted into a linked list, all of the elements after the insertion point must be moved one position toward the end of the list. a. true b. false

b. false

When the linear search algorithm is used to search for an item that is not present in an array, it must make a comparison with slightly less than half of the elements in the array. a. true b. false

b. false

In a circular linked list we maintain a pointer to keep tract of the ________________ Node in the list. a. first b. last c. largets d. n/a no such thing as a circular linked list

b. last

What will the following program display on the screen? #include <iostream> using namespace std; class Tank { private: int gallons; public: Tank() { gallons = 50; } Tank( int gal ) { gallons = gal; } int getGallons() { return gallons; } }; int main(int argc, const char * argv[]) { Tank storage1, storage2, storage3(20); cout << storage1.getGallons() << endl; cout << storage2.getGallons() << endl; cout << storage3.getGallons() << endl; return 0; } a. 50 50 50 b. 50 50 20 c. 50 50 20 d. 20 20 20

c. 50 50 20

If I define a class that has a data member that is a pointer, what other members should I also include in the class? copy constructor linked list template NULL pointer overloaded assignment operator destructor convert constructor

copy constructor overloaded assignment operator destructor

A C++ implementation file has the extension ____. a. .imp b. .h c. .exe d. .cpp

d. .cpp

What is the output of the following code? int *p; int x; x = 76; p = &x; *p = 43; cout << x << ", " << *p << endl; a. 76, 76 b. 76, 43 c. 43, 76 d. 43, 43

d. 43, 43

What is the value of x after the following statements execute? int x = 25; int *p; p = &x; *p = 46; a. NULL b. 0 c. 25 d. 46

d. 46

The try block is immediately followed by one or more __________ blocks. a. building b. else c. conditional d. catch

d. catch

Consider the program below. What is output when this program executes? #include <iostream> #include <vector> #include <exception> #include <stdexcept> using namespace std; int main() { try { vector<int> a; a.push_back(132); a.push_back(126); a.push_back(49); a.push_back(13); a.push_back(20); cout << "a[3] = " << a.at(3) << endl; } catch(out_of_range) { cout << "caught out_of_range exception in function main...\n"; } catch(...) { cout << "unknown exception caught in function main...\n"; } return 0; } a. caught out_of_range exception in function main... b. unknown exception caught in function main... c. nothing, lines 13 and 14 are incorrect and will cause a compile-time error. d. nothing, lines 13 and 14 are incorrect and will cause a run-time error. e. a[3] = 13 f. a[3] = 49 g. a message that the program crashed with an uncaught exception h. a message that a segmentation fault occured

e. a[3] = 13

#include <iostream> #include <vector> #include <exception> #include <stdexcept> using namespace std; int main() { try { vector<int> a; a.push_back(132); a.push_back(126); a.push_back(49); a.push_back(13); a.push_back(20); int i = 4; if ( i > 4 ) throw "ERROR: index is out of range!"; cout << "a[i] = " << a.at(i) << endl; } catch(out_of_range) { cout << "caught out_of_range exception in function main...\n"; } catch(...) { cout << "unknown exception caught in function main...\n"; } return 0; } a. caught out_of_range exception in function main... b. unknown exception caught in function main... c. nothing, lines 13 and 14 are incorrect and will cause a compile-time error. d. nothing, lines 13 and 14 are incorrect and will cause a run-time error. e. a[i] = 13 f. a[i] = 20 g. a message that the program crashed with an uncaught exception h. a message that a segmentation fault occured

f. a[i] = 20

The ___________________ search algorithm steps sequentially through an array, comparing each item with the search value. linear binary bubble selection

linear

The _____________________ search algorithm is adequate for small arrays but not large arrays. linear binary bubble selection

linear

The _____________________ search is a very simple algorithm. Sometimes called the ________________________ search, it compares each element with the value being searched for, and stops when either the value is found or the end of the array is encountered. fast/quick binary/log n quadratic / n^2 linear/sequential

linear/sequential

Every time the binary search algorithm makes a comparison and fails to find the desired item, it eliminates _______________________ of the remaining portion of the array that must be searched. all most one third one half

one half

Assume that a linked list class having identifier LL exists. The class provides a method end() returns an iterator object. The iterator object returned by end() points to what position within the linked list? one position prior to the first node on the linked list one position past the last node on the linked list the first node on the linked list the last node on the linked list

one position past the last node on the linked list

Class templates can be used whenever we need several classes that only differ in the types of some of their data members, or in the types of the ___________________ of their member functions. logic structure members parameters

parameters

From the list below, select the three characteristics of Object Oriented Design (OOD) / Object Oriented Programming (OOP). polymorphism difficulty instantiation inheritance encapsulation entropy composition parameterization

polymorphism encapsulation inheritance

Arithmetic expressions written in Reverse Polish Notation are using _____________ notation. enqueue infix postfix prefix

postfix

Assume that an iterator class having identifier LL_iterator exists. The iterator class implements the following overloaded operator: LL_iterator::operator++(). This is the _________________________ operator. dereferencing left bit shift post-increment pre-increment

pre-increment

Arithmetic expressions written in Polish Notation are using _____________ notation. enqueue infix posfix prefix

prefix

Consider the following function stub: LL_iterator LL::end() { } Select the best option from the given choices for this method's implementation code. return LL_iterator(NULL); return LL_iterator(head); return LL_iterator(tail); cout << "Hello World!" << endl;

return LL_iterator(NULL);

Assume that a linked list class having identifier LL exists. The class provides a method begin() returns an iterator object. The iterator object returned by begin() points to what position within the linked list? one position prior to the first node on the linked list one position past the last node on the linked list the first node on the linked list the last node on the linked list

the first node on the linked list


Conjuntos de estudio relacionados

False or False: The Question of Falsifiability

View Set

Patho Unit 2 Chapter 11 PrepU with explanations

View Set

World History Since 1500 Test #3

View Set

Robin Hood - Grade 7 - Characters

View Set