Prog 2 - Final

अब Quizwiz के साथ अपने होमवर्क और परीक्षाओं को एस करें!

If you do NOT furnish a ________, a default one will be provided by the compiler. - constructor - copy constructor - All of these - None of these - destructor

All of these

When a class declares an entire class as its friend, the friendship status is reciprocal. That is, each class's member functions have free access to the other's private members.

False

You are more likely to find an item by using a binary search than by using a linear search. - True - False

False

On average, an item is just as likely to be found near the beginning of an array as near the end. - True - False

True

The line containing a throw statement is known as the throw point.

True

The number of comparisons made by a binary search is expressed in powers of two. - True - False

True

When you overload an operator, you can change the operator's original meaning to something entirely different.

True

Which is the base class in the following statement? class Car : public Vehicle

Vehicle

The escape sequence that represents the null terminator is

\0

An actual instance of the function is created in memory when the compiler encounters

a call to the template function

A pointer variable is designed to store

a memory address

If an exception is thrown by a member function of a class object, the class ________ is called.

destructor

Members of the class object are accessed with the

dot operator

In the following function header, the word int is known as a(n) ________. FeetInches FeetInches::operator++(int)

dummy parameter

Class templates allow you to create one general version of a class without having to

duplicate code to handle multiple data types

The compiler performs ________ on virtual functions.

dynamic binding

In C++11 you can use ________ to initialize a member variable in its declaration statement.

in-place initialization

When the body of a member function is defined inside a class declaration, it is said to be

inline

Assume you have two integer variables, num1 and num2. Which of the following is the correct way to swap the values in these two variables?

int temp = num2; num2 = num1; num1 = temp;

With an enumerated data type, the enumerators are stored in memory as

integers

If a local variable and a global variable have the same name within the same program, the ________ resolution operator must be used.

scope

A ________ of a base class expects to be overridden in a derived class.

virtual function

The following statement ________. bookList[2].publisher[3] = 't';

will store the character 't' in the fourth element of the publisher member of bookList[2]

A good reason to overload an operator is to enable it to

work in its usual way, but with programmer-defined data types

For the following code, which statement is NOT true? class Point { private: double y; double z; public: double x; };

z is not available to code that is written outside the class.

Which of the following operators may be used to assign one object to another?

=

Which of the following is an example of a C++ primitive data type? unsigned char unsigned short int long double

All of these

You may use a pointer to a structure as a function return type None of these function parameter structure member

All of these

Which of the following statements is NOT valid C++ code? float num1 = &ptr2; All of these are valid int ptr = int *num1; int ptr = &num1; - float num1 = &ptr2; - All of these are valid - int ptr = int *num1; - int ptr = &num1; - All of these are invalid

All of these are invalid

The bubble sort is an easy way to arrange data in ascending order but it cannot arrange data in descending order. - True - False

False

The linear search repeatedly divides the portion of an array being searched in half. - True - False

False

The overloaded = operator copies data from one object to another so it is known as the overload copy operator.

False

The try/catch/throw construct is able to handle only one type of exception in a try block.

False

There is no difference between declaring an object of an ordinary class and an object of a template class.

False

If Circle is a structure, what does the following statement do? Circle *pcirc = nullptr;

It declares a structure pointer called pcirc initialized with a null pointer.

Arguments are passed to the base class by the ________ class ________ function. base, constructor None of these derived, constructor derived, destructor base, destructor

None of these

Arguments are passed to the base class destructor by the ________ class ________ function. derived, constructor base, destructor base, constructor None of these derived, destructor

None of these

Regardless of the algorithm being used, a search through an array is always performed - using a binary search algorithm - None of these - from lowest to highest element - from highest to lowest element - beginning with the middle element

None of these

The constructor function's return type is char float int structure pointer

None of these

The following statement allows the ________ members of the Car class to access ________ members of the Vehicle class. class Car : public Vehicle public, protected private, private public, private None of these protected, private

None of these

The function that reverses the order of a C-string is back strrev None of these reversstr reverseit

None of these

When more than one class is derived from a base class, the situation is called encapsulation polymorphism population None of these multiplicity

None of these

When you pass a pointer as an argument to a function, you must - None of these - use the #include statement - dereference the pointer value in the function prototype - not dereference the pointer in the function's body - declare the pointer value again in the function call

None of these

The destructor function's return type is

Nothing; destructors have no return type

What does the T represent in the following statement? template < class T >

a generic data type that is used in a function template

Given the following structure declaration, idNum is struct Employee { string name; int idNum; };

a member

Given the following structure declaration, Employee is struct Employee { string name; int idNum; };

a tag

A pointer variable may be initialized with

a valid address in the computer's memory

Which of the following describes only the general characteristics of an object?

abstraction

The base class's ________ affects the way its members are inherited by the derived class.

access specification

Multiple inheritance opens the opportunity for a derived class to have ________ members.

ambiguous

The ________, also known as the address operator, returns the memory address of a variable.

ampersand ( & )

The following statement ________. int *ptr = new int;

assigns an address to the variable ptr

The function that accepts a C-string containing a number as its argument and returns the integer equivalent is

atoi

The function that converts a C-string to an integer and returns the integer value is

atoi

Which of the following converts the string "10" to the integer value 10?

atoi("10");

The function that accepts a C-string as an argument and converts the string to a long integer is

atol

In OOP terminology, an object's member variables are often called its ________ and its member functions can be referred to as its behaviors or its ________.

attributes, methods

A(n) ________ is a special function that is called whenever a new object is created and initialized with another object's data.

copy constructor

When objects contain pointers, it is a good idea to create an explicit ________ function.

copy constructor

Which of the following statements displays the address of the variable numb?

cout << &numb;

Which of the following statements outputs the value of the gpa member of element [1] of the student array?

cout << student[1].gpa;

Use the delete operator only on pointers that were

created with the new operator

In a procedural program you typically have ________ stored in a collection of variables and a set of ________ that perform operations on the data.

data, functions

Objects are created from abstract data types that encapsulate ________ and ________ together.

data, functions

Before a structure can be used it must be

declared

When a constructor function accepts no arguments, or does NOT have to accept arguments because of default arguments, it is called a(n)

default constructor

Which of the following statements deletes memory that has been dynamically allocated for an array?

delete [] array;

The ________ destructor is called before the ________ destructor.

derived, base

Multiple inheritance is when a ________ class has ________ base classes.

derived, two or more

When an array is sorted from highest to lowest, it is said to be in

descending order

The C-string company[12] can hold

eleven characters and the null terminator

Which of the following assigns a value to the hourlyWage member of employee[2]?

employee[2].hourlyWage = 75.00;

A declaration for an enumerated type begins with the ________ key word.

enum

A(n) ________ is a value or an object that signals an error.

exception

Catch blocks serve as

exception handlers

Which of the following is used to signal errors or unexpected results that happen as a program runs?

exceptions

Given the following declaration: enum Tree { OAK, MAPLE, PINE }; What is the value of the following relational expression? OAK > PINE

false

A(n) ________ informs the compiler that a class will be declared later in the program.

forward declaration

Which type of function is NOT a member of a class but has access to the private members of the class?

friend

Which of the following will return true if the argument is a printable character other than a digit, letter, or space?

ispunct

To determine whether a character entered is whitespace, use the ________ function.

isspace

A(n) ________ search uses a loop to sequentially step through an array.

linear

The following is the pseudocode for which type of algorithm? Set found to false Set position to -1 Set index to 0 While found is false and index < number of elements If list(index) is equal to search value found = true position = index End If Add 1 to index End While Return position

linear search

Not all arithmetic operations can be performed on pointers. For example, you cannot ________ or ________ pointers.

multiply, divide

When the ________ operator fails to allocate memory, C++ throws a bad_alloc exception.

new

How much memory is reserved for a function template?

no memory

In C++ a C-string is a sequence of characters stored in consecutive memory, terminated by a

null character

In C++11, the ________ keyword was introduced to represent address 0.

nullptr

When a class contains an instance of another class, it is known as

object composition

A function template's prefix contains ________ enclosed in angle brackets.

one or more generic data types

How many default constructors can a class have?

only one

When you overload an operator, you cannot change the number of ________ taken by the operator.

operands

To overload the + operator, you would write a function named

operator +

If a is a structure variable and p, a pointer, is a member of the structure, what will the following statement do? cout << *a.p;

output the dereferenced value pointed to by p

An ________ operator can work with programmer-defined data types.

overloaded

When you redefine the way a standard operator works when it is used with class objects, you have ________ the operator.

overloaded

If you do NOT furnish a(n) ________, an automatic memberwise copy will be performed when one object is assigned to another object.

overloaded assignment operator

A virtual function is a function that expects to be ________ in a derived class.

overridden

C++11 introduced the ________ key word to help prevent subtle errors when overriding virtual functions.

override

In a function template, the programmer substitutes ________ for ________.

parameters, data types

The term ________ means the ability to take many forms.

polymorphism

When member functions behave differently depending on which object performed the call, this is an example of

polymorphism

If you do NOT declare an access specification, the default for members of a class is

private

The ________ members of a base class are never accessible to a derived class.

private

Which type of member function may only be called from a function that is a member of the same class?

private

Examples of access specifiers are the key words

private and public

Protected members of a base class are like ________, but they may be accessed by derived classes.

private members

In the following statement, what does int mean? int *ptr = nullptr;

ptr is a pointer variable and will store the address of an integer variable.

The type of member function that may be called from a statement outside the class is

public

C++ requires that a copy constructor's parameter be a(n)

reference object

In C++11 reference variables that can refer only to temporary objects that would otherwise have no name are called ________ and are declared with a ________.

rvalues, double ampersand (&&)

A ________ algorithm is a method of locating a specific item of information in a larger collection of data.

search

When the compiler binds a member function call with the version of the function that resides in the same class as the call itself, it is considered

static binding

A function may return a pointer but the programmer must ensure that the pointer

still points to a valid object after the function ends

The following statement ________. cin >> *num3;

stores the keyboard input into the variable pointed to by num3

The ________ function concatenates the contents of one C-string with another C-string.

strcat

The function that accepts a pointer to a C-string as an argument and returns the length of the C-string, not including the null terminator is

strlen

The function that accepts pointers to two C-strings and an integer argument that indicates how many characters to copy from the second string to the first is

strncpy

In C++11, you can use a new type of enum known as a(n) ________ (also known as an enum class) to have multiple enumerators with the same name, within the same scope.

strongly typed enum

A library function that can find one C-string inside another is

strstr

A C++ class is similar to a(n)

structure

Objects in an array are accessed with ________.

subscripts

Which of the following is a directive used to create an "include guard" that allows a program to be conditionally compiled to prevent a header file from accidentally being included more than once?

#ifndef

If you want to catch a bad_alloc exception in a program, you should include

#include <new>

The ________ and ________ operators can be used to increment or decrement a pointer variable.

++, --

When you dereference an object pointer, use the

-> operator

The null terminator stands for ASCII code

0

After the following statement executes, what value will the MAPLE enumerator be stored as, in memory? enum Tree { OAK, MAPLE, PINE };

1

What is the value stored in num after the following statement executes? num = atoi("1000");

1000

What will the following code output? int *numbers = new int[5]; for (int i = 0; i <= 4; i++) *(numbers + 1) = i; cout << numbers[2] << endl;

2

Using a linear search to find a value that is stored in the last element of an array that contains 20,000 elements, ________ elements must be compared.

20,000

Which is the derived class in the following statement? class Car : protected Vehicle

Car

What does the following statement do? double *num2;

Declares a pointer variable named num2

A linear search can only be implemented with integer values. - True - False

False

A program may not contain both a "regular" version of a function and a template version of the function.

False

Before you can perform a bubble sort, the data must be stored in descending order. - True - False

False

Before you can perform a selection sort, the data must be stored in ascending order. - True - False

False

If an exception is not caught, it is stored for later use.

False

In an inheritance situation, you may not pass arguments to a base class constructor.

False

Given the following code, what will happen if the value of denom is 0? double divide(int numer, int denom) { if (denom == 0) throw "ERROR: Cannot divide by zero.\n"; else return static_cast<double>(numer)/denom; }

The program will display ERROR: Cannot divide by zero.and then halt.

Assuming that Rectangle is a class name, what can you say is TRUE, given the following statement? Rectangle *BoxPtr;

The statement defines a Rectangle pointer variable named *BoxPtr.

The following function should swap the values contained in two integer variables, num1 and num2. What, if anything, is wrong with this function? void swap (int num1, int num2) { int temp = num2; num2 = num1; num1 = temp; }

The swap function must use reference parameters.

Which of the following is TRUE about this statement? sum += *array++;

This statement assigns the dereferenced pointer's value, then increments the pointer's address.

A selection sort and a binary search can be applied to STL vectors as well as arrays. - True - False

True

A struct can contain members with varying data types.

True

Any mathematical operation that can be performed on regular C++ variables can be performed on structure members.

True

More than one class may be derived from a base class.

True

Data types that are created by the programmer are known as

abstract data types (ADTs)

Every byte in the computer's memory is assigned a unique

address

What is being protected in the following statement? class Car : protected Vehicle

base class members

The ________ constructor is called before the ________ constructor.

base, derived

When a constructor has a member initialization list, the initializations take place

before any statements in the body of the constructor execute

A function template prefix is placed before the function header while a class template prefix is placed

before the class declaration

A ________ search is more efficient than a ________ search.

binary, linear

The expression being tested by the statement shown below will evaluate to true if var1 is ________. if (!isdigit(var1))

both an alphabetic character and a symbol such as $ or &

When a structure is passed ________ to a function, its members are NOT copied.

by reference

A class is a(n) ________ that is defined by the programmer.

data type

What is the output of the following statement? cout << tolower(toupper('Z')) << endl;

lowercase z

A function ________ return a structure.

may

When you derive a class from an existing class, you ________ add new data and functions.

may

Polymorphism is when ________ in a class hierarchy perform differently, depending on which object performs the call.

member functions

Each object of a class has its own copy of the class's

member variables

A binary search begins with the ________ element of an array.

middle

In C++11 the ________ operator swaps the members of the object being assigned with the temporary object.

move assignment

When a derived class has two or more base classes, the situation is called

multiple inheritance

The following is the pseudocode for which type of algorithm? For start = each array subscript, from the first to the next-to-last minIndex = start minValue = array[start] For index = start + 1 To size - 1 If array[index] < minValue minValue = array[index] minIndex = index End If End For swap array[minIndex] with array[start] End For

selection sort

The ________ sort usually performs fewer exchanges than the ________ sort.

selection, bubble

Which of the following is required after the closing brace of the structure definition?

semicolon

The advantage of a linear search is its

simplicity

To help prevent memory leaks from occurring in C++11, a ________ automatically deletes a chunk of dynamically allocated memory when the memory is no longer being used.

smart pointer

Array elements must ________ before a binary search can be performed.

sorted

If Circle is a structure tag, then the following statement can be the header line for a function that ________. Circle doSomething(Circle c2)

takes a Circle structure as a parameter, does something, and returns a Circle structure

What will the following code output? int number = 22; int *var = &number; cout << *var << endl;

22

What is the output after the following code executes? int numerator = 5; int denominator = 25; int temp = 0; temp = numerator; numerator = denominator; denominator = temp; cout << numerator << "/" << denominator << " = " << (numerator/denominator) << endl;

25/5 = 5

Given the string shown below, if the delimiter is a space, how many tokens are in the string? "Tony's email address is [email protected]"

5

By default, when an object is assigned to another object, each member of one object is copied to its counterpart in the other object.

True

If you are using the bubble sort algorithm to sort an array in descending order, the smaller values move toward the end. - True - False

True

The following is the pseudocode for which type of algorithm? Set first to 0 Set last to the last subscript in the array Set found to false Set position to -1 While found is not true and first is less than or equal to last Set middle to the subscript halfway between array[first] and array[last] If array[middle] is greater than the desired value Set found to true Set position to middle Else If array[middle] is greater than the desired value Set last to middle - 1 Else Set first to middle + 1 End If End While Return position

binary search

The following is the pseudocode for which type of algorithm? For maxElement = each subscript in the array, from the last to the first For index = 0 To maxElement - 1 If array[index] > array[index +1] sway array[index] with array[index + 1] End If End For End For

bubble sort

A structure ________ contain members of the same data type.

can

The try block is immediately followed by one or more

catch blocks

An exception thrown from outside a try block will

cause the program to abort execution

Which of the following statements appropriately defines a C-string that stores names of up to 25 characters?

char name[26];

Which of the following defines an array of C-strings that will hold 49 characters and the null terminator?

char str[50];

What does the word class indicate in the following statement? template < class T >

class is a key word that is used to precede the type parameter.

When a member function is defined outside of the class declaration, the function name must be qualified with the

class name, followed by the scope resolution operator

It is a good idea to make a copy constructor's parameters ________ by specifying the ________ key word in the parameter list.

constant, const

A ________ is a member function that is automatically called when a class object is ________.

constructor, created

Data that is to be sorted in ascending order is ordered

from lowest value to highest value

All type parameters defined in a function template must appear at least once in the

function parameter list

A generic function that can work with any data type is a

function template

Passing a structure as a constant reference parameter to a function

guarantees not to result in changes to the structure's members

The process of object-oriented analysis can be viewed as the following steps:

identify objects, then define each object's attributes, behaviors, and relationships

Where are class declarations usually stored?

in their own header files

With pointer variables you can ________ manipulate data stored in other variables.

indirectly

In OOP programming, ________ allows you to create new classes based on existing classes.

inheritance

Which of the following is commonly used to extend a class or to give it additional capabilities?

inheritance

To determine whether a character entered is a letter of the alphabet, use the ________ function.

isalpha

To test whether a character is a numeric digit character, use the ________ function.

isdigit

To test whether a character is a printable character, use the ________ function.

isprint

Algorithms used to arrange random data in some order are ________ algorithms.

sorting

A reason to overload the ________ is to allow you to write classes that have array-like behaviors.

square brackets [ ] operator

C++ allows you to redefine the way ________ work when used with class objects.

standard operators

A member function that is declared ________ may not access any non-static data members in the class.

static

If a member is declared ________, all objects of that class have access to that variable.

static

The ________ member variable may be accessed before any objects of the class have been created.

static

The beginning of a function template is marked by a

template prefix

To dereference a structure pointer, the appropriate operator is

the -> operator

When you work with a dereferenced pointer, you are actually working with

the actual value of the variable whose address is stored in the pointer variable

A structure pointer contains

the address of a structure variable

What will the following code output? int number = 22; int *var = &number; cout << var << endl;

the address of number

If a variable uses more than one byte of memory, for pointer purposes its address is

the address of the first byte of storage

When the less than operator (<) is used between two pointer values, the expression is testing whether

the address of the first variable comes before the address of the second variable in the computer's memory

The constructor function always has the same name as

the class

Which of the following is automatically called when an object is destroyed?

the destructor function

Which of the following will allow you to access structure members?

the dot operator

In C++11, assuming mychar is a char variable and mystring is a string, what is the value of mychar after the following statement executes? mychar = mystring.front();

the first character of mystring

If you are using an older computer that does NOT support the C++11 standard, you should initialize pointers with

the integer 0 or the value NULL

The ________ is adequate for searching through small arrays.

the linear search

What will the following statement output? cout << &num1;

the memory address of the variable named num1

Which of the following is used to protect important data?

the private access specifier

Assuming ptr is a pointer variable, what will the following statement output? cout << *ptr;

the value stored in the variable whose address is contained in ptr

A(n) ________ is a special built-in pointer that is available to a class's member functions.

this pointer

In the following code, which statement is the throw point? double divide(int numer, int denom) { if (denom == 0) throw "ERROR: Cannot divide by zero.\n"; else return static_cast<double>(numer)/denom; }

throw "ERROR: Cannot divide by zero.\n";

When an error occurs, an exception is

thrown

A good reason to pass a structure as a constant reference is

to prevent changes to the structure's members

The ________ function will change a character argument from uppercase to lowercase.

tolower

The ________ function will change a character argument from lowercase to uppercase.

toupper

The ________ starts with the key word try and is followed by a block of code that executes any statement that might cause an exception to be thrown.

try block

To handle an exception that has been thrown, a program must have a(n)

try/catch construct

The arguments of the strcpy function are

two addresses

A(n) ________ is used in a function template to specify a generic data type.

type parameter

What is the result after the following statement executes? char var1 = tolower('A');

var1 stores the ASCII value for lowercase 'a'

A virtual function is declared by placing the ________ key word in front of the return type in the base class's function declaration.

virtual

Functions that are dynamically bound by the compiler are ________ functions.

virtual

Dynamic memory allocation occurs

when a new variable is created at runtime


संबंधित स्टडी सेट्स

Texas State Exam Realtor Salesperson

View Set

Western Civilizations) Ancient Near East) Egypt (unfinished)

View Set

Fire 1 Comprehensive Study Guide

View Set