COP2000 Final

Pataasin ang iyong marka sa homework at exams ngayon gamit ang Quizwiz!

What does the following code do?

An error will occur when the code runs.

Given the following function:

1 6 3

How many elements does the following array have? int values[1000];

1000

This vector function is used to insert an item into a vector.

push_back

The advantage of a linear search is its

simplicity

To access an array element, use the array name and the element's ________.

subscript

The ________ is adequate for searching through small arrays.

the linear search

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

True

What will the following code display? int numbers[] = {99, 87, 66, 55, 101}; cout << numbers[3] << endl;

55

What will the following code display?

7

What will the following code display?

87 66 55

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

False

When a function is called, flow of control moves to the function's prototype.

False

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

True

The amount of memory used by an array depends on the array's data type and the number of elements in the array.

True

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

True

When writing functions that accept multi-dimensional arrays as arguments, ________ must be explicitly stated in the parameter list.

all but the first dimension

This following statement shows an example of ________. int grades][ ] = {100, 90, 99, 80};

implicit array sizing

What is the data type of the following function prototype's return value? int myFunction(double);

int

The range-based for loop in C++11 is designed to work with a built-in variable known as

the range variable

An element of a two-dimensional array is referred to by

the row subscript of the element followed by the column subscript of the element

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

False

You must always furnish an argument with a function call.

False

Arrays must be ________ at the time they are ________.

initialized, declared

EXIT_FAILURE and ________ are named constants that may be used to indicate success or failure when the exit() function is called.

EXIT_SUCCESS

A function's return data type must be the same as the function's parameters.

False

A linear search can only be implemented with integer values.

False

A local variable and a global variable may not have the same name within a program.

False

Although two-dimensional arrays are a novel idea, there is no known way to pass one to a function.

False

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

False

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

False

In C++11 the range-based for loop is best used in situations where you need the element subscript for some purpose.

False

Local variables are initialized to zero by default.

False

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

False

One reason for using functions is to break programs into manageable units or modules.

True

When you pass an array as an argument to a function, the function can modify the contents of the array.

True

You may use the exit() function to terminate a program, regardless of which control mechanism is executing.

True

An array can easily be stepped through by using a

a for loop

A(n) ________ is information that is passed to a function, and a(n) ________ is information that is received by a function.

argument, parameter

A function ________ contains the statements that make up the function.

definition

This type of variable is defined inside a function and is NOT accessible outside the function.

local

The name of an array stores the ________ of the first array element.

memory address

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

middle

To pass an array as an argument to a function, pass the ________ of the array.

name

This statement causes a function to end.

return

Given the following declaration, where is the value 77 stored in the scores array? int scores[] = {83, 62, 77, 97, 86}

scores[2]

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

search

The following is the pseudocode for which type of algorithm?

selection sort

Regardless of the algorithm being used, a search through an array is always performed

None of these

What will the following code display?

0

Unlike regular variables, ________ can hold multiple values.

arrays

Which statement correctly defines a vector object for holding integers?

vector<int> v;

If you leave out the size declarator in an array definition

you must furnish an initialization list

What will the following code display?

2 0 0

What is the output after the following code executes?

25/5 = 5

An array initialization must be all on one line.

False

What does the following statement do?

It creates a vector object with a starting size of 10.

The following function should swap the values contained in two integer variables, num1 and num2. What, if anything, is wrong with this function?

The swap function must use reference parameters.

________ functions may have the same name as long as their parameter lists are different.

Two or more

Subscript numbering in C++

begins with zero

The following is the pseudocode for which type of algorithm?

binary search

Functions are ideal for menu-driven programs. When the user selects a menu item, the program can ________ the appropriate function.

call

A function is executed when it is

called

An array's size declarator must be a ________ with a value greater than ________.

constant integer expression, zero

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

descending order

It is good programming practice to ________ your functions by writing comments that describe what they do.

document

The individual values contained in an array are known as

elements

This vector function returns true if the vector has no elements.

empty

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;

Which line in the following program contains a call to the showDub function?

line 7

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

linear

The following is the pseudocode for which type of algorithm?

linear search

The ________ is automatically appended to a character array when it is initialized with a string constant.

null terminator

If a function is called more than once in a program, the values stored in the function's local variables do NOT ________ between function calls.

persist

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

selection, bubble

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

sorted

An array of string objects that will hold five names would be declared with which of the following statements?

string names[5];

C++ limits the number of array dimensions to two.

False

What will the following C++11 code display?

3 , 5

An individual array element can be processed like any other type of C++ variable.

True

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

In the following function prototype, how many parameter variables does this function have? int myFunction(double, double, double);

3

What is the last legal subscript that can be used with the following array? int values[5];

4

What will the following code display?

4 2

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

True

A static variable that is defined within a function is initialized only once, the first time it is called.

True

A vector object automatically expands in size to accommodate the items stored in it.

True

Each individual element of an array can be accessed by the array name and the element subscript.

True

Global variables are initialized to zero by default.

True

If an array is partially initialized, the uninitialized elements will be set to zero.

True

It is not considered good programming practice to declare all your variables globally.

True

A ________ search is more efficient than a ________ search.

binary, linear

The following is the pseudocode for which type of algorithm?

bubble sort

Data that is to be sorted in ascending order is ordered

from lowest value to highest value

A collection of statements that performs a specific task is a(n)

function

A ________ variable is declared outside all functions.

global

A(n) ________ can be used to specify the starting values of an array.

initialization list

Which of the following is a valid C++ array definition?

int sizes[10];

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

sorting

The value in this type of variable persists between function calls.

static


Kaugnay na mga set ng pag-aaral

CH 8 Teamwork and Team performance

View Set

Continuum of Long-term Healthcare

View Set

POR Texas 2 unit 8 Property Management

View Set