OOP Final Exam

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

A range is often supplied to an algorithm by two ___________ values. A. iterator B. function object C. pointers D. integer

A

If iter is a reverse iterator, what is the expression that should be done on the iter to move it to the next object? A. iter++ B. iter-- C. (star)iter++ D. (star)iter--

A

Static type binding is when the type is determined at __________. A. compile time B. run time C. writing D. linking

A

General problems with procedural programming include: A. Data does not have an owner B. Insufficient support for abstraction C. Low security D. Insufficient access to memory E. Difficult to maintain data integrity F. Difficult to maintain

A B C E F

Which are access specifiers? A. Friend B. Public C. Reserved D. Const E. Protected F. Closed

A B E

Which are types of inheritance? A. Private B. Friend C. Protected D. Public E. Polymorphic F. Abstract

A C D

Main markers of Object Oriented Programming: A. Data integrity B. top-down programming C. Global functions D. Abstraction E. Encapsulation F. Pointer Math

A D E

Chain of Responsibility - pros:

Allows data to be handled different ways depending on what the user inputs It is easy to add more links into the chain to provide another possible way to handle that data code is flexible (can easily change the link without affecting the chain)

C++ primarily implements generic programming through ___________. A. Inheritance B. Templates C. operator overloading D. Exceptions

B

If you define a vector v with the default constructor, and define another vector w with a one-argument constructor to a size of 11, and insert 3 elements into each of these vectors with push_back(), then the size() member function will return ______ for v and ______ for w. A. 3,3 B. 3, 11 C. 4,4 D. 4,12

B

In STL, containers contain _________. A. algorithms B. data C. iterators D. templates

B

Templates are an example of _________ type binding. A. dynamic B. static C. lazy d. low

B

The Standard Template Library (STL) is an example of a collection of _________________________. A. function templates B. class templates C. exceptions D. inheritance

B

The unique() algorithm removes all ____________ element values from a container. A. unique B. duplicate C. non-unique

B

When using a reverse iterator, which function should you use to start from the end? A. begin() B. rbegin() C. end() D. rend()

B

You are asked to write a program that creates objects without exposing the instantiation logic to the client. Which design pattern do you use? A. Singleton B. Factory C. Chain of Responsibility D. Strategy

B

Main markers of procedural programming: A. Data integrity B. Top-Down programming C. Global functions D. Abstraction E. Encapsulation F. Pointer Math

B C

A C++ type that is an example of a templatized class is the following: A. int B. float C. vector D. string

C

An exception is typically caused by ___________. A. The programmer who writes an application's code B. a compile time error C. a runtime error D. an operating system malfunction that terminates the program

C

An exception is typically caused by _____________________________________. A. the programmer who writes an application's code B. the creator of a class who writes the class member functions C. a runtime error D. an operating system malfunction that terminates the program

C

At compile-time, class templates are instantiated by _____________________. A. calling it using arguments of a specific type B. defining an object of that type C. defining an object using the template argument D. defining an object using the constructor

C

Dynamic type binding is when the type is determined at run time, such as through the use of __________. A. Class templates B. Inheritance C. virtual functions D. exceptions

C

Generic programming allows the writer to create functionality in its most abstract sense, and then reuse the code for multiple types. This is generally called ____________ polymorphism. A. dynamic B. Static C. Type D. Virtual

C

If iter is an iterator to a container, what is the expression that will have the value of the object pointed to by iter, and will then cause iter to point to the next element. A. iter++ B. ++iter C. *iter++ D. &iter++

C

In order to avoid operating directly on the containers, STL has solved this problem by providing ___________. A. algorithms B. data C. iterators D. templates

C

The STL find() algorithm: A. finds matching sequences of elements in two containers B. finds a container that matches a specified container C. takes iterators as its first two arguments D. takes container elements as its first two arguments

C

The naming convention of templatized parameters is usually which three? A. x, y, z B. a, b, c C. t, u, v

C

You are asked to write a program that will control the very last part of a car's factory assembly line process: painting. There are five robots in an already existing part of the assembly line: Black, Red, Blue, Yellow, Green. There is only one of each robot. Your program will control when a car is painted by using the correct robot. The first robot will be passed a color. If it cannot paint the car that color, it will send it on down the line to the next robot. You are guaranteed that the color will be one of the five colors available. A. Singleton B. Factory C. Chain of Responsibility D. Strategy

C

Give one real world example of when Factory would be helpful to use

Creating a word document in Microsoft word or a bad guy in a game

STL sequence containers are: _________________, ________________________, ____________________, ___________________, and ___________________. A. vector, map, list, deque, set B. list, deque, vector, forward list, set C. map, multimap, set, multiset, list D. vector, deque, list, forward list, array

D

The big gain by using class templates instead of function templates is that class templates allow the use of _________________. A. multiple types B. unknown types C. more than one templatized type D. user-defined types

D

You are asked to write a program for checking out of an online store. There are 5 consecutive steps that need to take place for the user every time. The user will complete a step and then their information will always be passed on to the next step. Which design pattern will you use? A. Singleton B. Factory C. Chain of Responsibility D. Strategy E. None of the above

E

Give one real world example of when Strategy would be helpful to use

Elf "has a" weapon - character has an object of a type

(T/F) A statement that throws an exception does not need to be located in a try block.

F

(T/F) An iterator can always move forward and backwards through a container.

F

(T/F) Generic programming is fully supported by C++.

F

(T/F) Polymorphism is when a derived class uses base class functionality.

F

(T/F) STL is hard to use because it is not guaranteed to be on every system.

F

(T/F) STL is highly accurate but comes at the cost of lower performance

F

(T/F) STL keeps programmers from having to reinvent the wheel, but comes at the cost of increased code length, making it less readable.

F

(T/F) Statements that might cause an exception must be part of a catch block

F

(T/F) Statements that might cause an exception must be part of a catch block.

F

(T/F) The "friend" access specifier breaks encapsulation.

F

(T/F) The back() member function removes the element at the back of the container and returns the value just removed.

F

(T/F) a class is defined as: a set of objects that share a common purpose

F

(T/F) private inheritance means that all derived classes will have access to the private member data and functions of the base class.

F

Member variables and functions that are protected are kept safe from derived classes

F

Give a real world example of when Singleton would be helpful to use

Google Doc

Chain Responsibility - cons:

Handling isn't guaranteed Slow because might have to check all options before getting to the correct one

Whats the point of encapsulation?

Hides the implementation of an object from the outside world

When should a function be const?

If no changes are made to MEMBER data within that function

Describe the Chain of Responsibility Pattern:

Involves looking through a series of options for how something will be handled depending on a given criteria. Commands are passed down through the chain and then handled based on where they fit avoids attaching a sender to a receiver (de-coupling)

Singleton - pros:

Lazy instantiation (only create object if needed), static instantiation (works like a global variable)

Describe the Singleton design pattern

Only one instantiation of the class, so only one object created. When you ask for a new one, the original is returned. Utilizes a private constructor.

(T/F) A program can continue to operate after an exception has occurred.

T

(T/F) Class A declares that the "foo()" function in class B is a friend. Code inside of "foo()" may now modify private member data in A.

T

(T/F) In STL, if I write an algorithm, then I must write a new iterator for every container.

T

(T/F) encapsulation hides the details of the implementation of an object

T

Everything is private in a class by default

T

Functions inside of a class that are available to outsiders are known as the public interface of a class

T

Polymorphism is when a base class uses derived class functionality.

T

What is the "this" keyword in C++?

The "this" keyword is a pointer to the object which invoked the member function currently being called

Describe the Strategy Design Pattern

The strategy pattern is when a class uses an object from a family of encapsulated algorithm classes. This is called composition and is an alternative to inheritance. Composition provides the "has a" relationship to the class.

Give one real world example of when Chain of Responsibility would be helpful to use

Vending machine SAT scores for scholarships

When is polymorphism helpful?

When you need a behavior to be defined for more than one situation

Describe deep copy

a new place in memory is being used to hold a copy of the value stored in the original memory space (high speed)

Describe shallow copy

a pointer has been created to be an additional reference to the same address where the original value is still being stored

Factory - pros:

allows code reusability makes sure all objects are created the same way allows for additional objects to be created while the program is already running objects that are from classes derived from the same base class can be grouped together and pointed to with a base class pointer consistent method of access and delivery can change existing or add new derived class types without breaking others retrieved by the same method

Singleton - cons:

bad when used inappropriately no inheritance not thread safe memory management difficult over long time

Generic programming is a style of programming that maximizes reusability by specifying types at ___________(compile time/run time).

compile time

Strategy - cons:

could get too abstract and have too many objects/classes

Factory: cons

difficult to switch code to factory if it wasn't originally designed that way inheritance breaks because the classes have private constructors can't easily change the access and delivery method

Strategy - pros:

flexible to swap behaviors, don't have to break client, greater abstraction

Describe the Factory Design Pattern

large batch of objects using classes with a private constructor so that the instantiation logic is hidden from the client Not known at compile time what specific objects will be created, but known what options are available Objects from different classes are created the same way so that adding another kind of object does not break the code


Conjuntos de estudio relacionados

How to Say Hi in different languages

View Set

PH450: Screening in Public Health

View Set

EMT Chapter 37: Obstetrics and Care of the Newborn

View Set

NCLEX Skin and Integumentary Diseases Part 1

View Set

National Real Estate Exam: Conveyances or Deeds

View Set

Chapter 38: Caring for Clients With Cerebrovascular Disorders

View Set