COSC 52 Final: General Knowledge

Réussis tes devoirs et examens dès maintenant avec Quizwiz!

In C++, ____ is called the address operator.

&

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.

1/2

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

12, 81

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

43, 43

What is the value of x after the following statements execute? int x = 25; int *p; p = &x; *p = 46;

46

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; }

50 50 20

A linked list class that uses iterators provides the following member functions specifically for that purpose.

Begin() and End()

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

Binary

The ________________________ search algorithm requires that the array's contents be sorted.

Binary

The try block is immediately followed by one or more __________ blocks.

Catch

The binary search is a(n) ____________________ algorithm that is much more ____________________ than the linear search.

Clever, efficient

____ is the ability to combine data, and operations on that data, in a single unit.

Encapsulation

A class can have more than one destructor.

False

A derived class can directly access any member of the base class.

False

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

False

A pointer variable is declared using an ampersand (&) character.

False

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

False

In C++, &p, p, and *p all have the same meaning.

False

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

False

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

False

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

False

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

False

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

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.

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.

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.

False (i.e. circular linked lists or doubly linked lists)

Arithmetic expressions that we typically write use _____________________ notation.

In-fix

In a circular linked list we maintain a pointer to keep tract of the ________________ Node in the list.

Last

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

Linear

The _____________________ search algorithm is adequate for small arrays but not large arrays.

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.

Linear, sequential

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.

Memberwise

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 past the last node on the linked list

A programmer-defined copy constructor must have a single parameter that is a reference to the _________ class.

Same

A data structure that points to an object of the same type as itself is known as a(n) ____________________ data structure.

Self-referential

What is it called when two objects point to the same data?

Shallow copy

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?

The first node on the linked list

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.

Traversing

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

True

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

True

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

True

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

True

A try block must be followed by one or more catch blocks.

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.

True

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

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.

True

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.

True

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

True

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

True

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

True

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

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

Inheritance is an example of a(n) ____ relationship.

is-a

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) ___________________ .

memory leak

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);

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(head);

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;

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

False

All operators can be overloaded as member functions of the class.

False

By default, all members of a class are public.

False

Constructors are called like any other function.

False

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

False

Arithmetic expressions written in Polish Notation are using _____________ notation.

Pre-fix

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.

Pre-increment

Iterators are objects that behave like pointers.

True

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

True

Using operator overloading, it is possible to change an operator's entire meaning.

True

A ____ sign in front of a member name on a UML diagram indicates that this member is a private member.

-

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 - Destructor - Overloaded assignment operator

A copy constructor is automatically called in the what situations?

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

What are the basic operations of a circular linked list?

- add - remove - advance - front - back - empty

What are basic linked list operations?

- adding an element to a list - traversing the list - removing an element from the list - destroying the list

A thrown exception could go uncaught if _______________________________________.

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

A C++ implementation file has the extension ____.

.cpp

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

False

Exceptions are used to signal errors or unexpected events that occur at compile time.

False

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

True

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

True

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

True

A ____ sign in front of a member name on a UML diagram indicates that this member is a public member.

+

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; }

unknown exception caught in function main...

Existing classes, from which you create new classes, are called ____ classes.

Base

What are the three characteristics of Object Oriented Design (OOD) / Object Oriented Programming (OOP)?

Polymorphism, Inheritance, Encapsulation

Arithmetic expressions written in Reverse Polish Notation are using _____________ notation.

Post-fix

There are ________ possible ways for a thrown exception to go uncaught.

Two

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[3] = 13

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 = 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[i] = 20

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; }

caught out_of_range exception in function main...

Two linked list iterator objects are equal if

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


Ensembles d'études connexes

412 -- Exam 4 (neuro, neo, vis, hearing) -- quizzes, jeopardy, socratives -- ADD LAST QUIZ

View Set

Introduction to Organization Theory, Behavior, and Management Chapter one

View Set

NURA 1500 test 5-endocrine and musculoskeletal

View Set

U.S. Government & Politics Exam #17

View Set