cop 3363 exam 2

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

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.

20000

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

4

What will the following code display? #include using namespace std; void showDub(int);int main(){int x = 2;showDub(x);cout << x << endl;return 0;}void showDub(int num){cout << (num * 2) << endl;}

4, 2

What is a reference variable?

A nickname for another variable. When a variable is passed by reference into a function, a new variable is not created for the formal parameter. So all changes made to the reference variable are retained across the function call.

Given an array of doubles starting at address 5000, what is the starting address of element 7 of the array? (a) 5000 (b) 5048 (c) 5056 (d) 5064

Answer: 5000 + 7x8 = 5056

Which of the following is NOT a C++ reserved word? (a) float (b) array (c) void (d) return

Answer: array, everything else is a keyword.

Figure out the output generated by the following code snippet: int mat[3][3] = {{1,5,19},{6,-2,10},{12,8,5}}; int sum=0;for(int i=0;i<3;i++) sum += mat[i][i];cout<<"The sum is "<<sum<<endl;

The sum is 4

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

Subscript numbering in C++

begins with zero

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

double

Write a C++ function that accepts a double array and its size. This array represents the side lengths of a bunch of squares. Calculate areas of squares, print them, and return their sum. Once again, you don't have to read or print anything. You do not have to account for floating point precision. Sample Run:Input array:2.5, 12, 5.9, 14.82, 0.8Output:The squares are:6.25, 144, 34.81, 219.6324, 0.64 The sum is 405.3324

double sumSquares(double arr[], int size) { cout<<"The squares are: \n"; double sum=0; for(int i=0; i<size; i++) { cout<<arr[i]*arr[i]; if(i!=size-1) cout<<", "; sum +=arr[i]*arr[i]; } return sum; }

This function causes a program to terminate, regardless of which function or control mechanism is executing.

exit()

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

from lowest to highest element beginning with the middle element using a binary search algorithm from highest to lowest element NONE OF THESE

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(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];

Which line in the following program contains the header for the showDub function? 1 #include 2 using namespace std;3 void showDub(int);4 int main()5 {6 int x = 2; 7 showDub(x);8 cout << x << endl;9 return 0;10 } 11 void showDub(int num)12 {13 cout << (num * 2) << endl;14 }

line 11

Which line in the following program contains the prototype showDubfunction? 1 #include 2 using namespace std;3 void showDub(int);4 int main()5 {6 int x = 2; 7 showDub(x);8 cout << x << endl;9 return 0;10 } 11 void showDub(int num)12 {13 cout << (num * 2) << endl;14 }

line 3

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

linear

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

local

The advantage of a linear search is its

simplicity

This vector function returns the number of elements in a vector.

size

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

sorting

The value in a ________ variable persists between function calls.

static local

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

string names[5];

This is a dummy function that is called instead of the actual function it represents:

stub

Which statement correctly defines a vector object for holding integers?

vector <int> v;

This vector function removes an item from a vector.

pop_back

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?For start = each array subscript, from the first to the next-to-lastminIndex = startminValue = array[start]For index = start + 1 To size - 1If array[index] < minValueminValue = array[index]minIndex = indexEnd IfEnd Forswap array[minIndex] with array[start]End For

selection sort

The ________ is adequate for searching through small arrays.

the linear search

An array can store a group of values, but the values must be

the same data type

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

two or more


Ensembles d'études connexes

KNES 371 Chapter 10 Augmented Feedback and Motor Learning

View Set

Mosaik 1 Lektion 2 ,,Checkpoint Charlie"

View Set

Ch. 13: Mutual Funds and Insurance

View Set

Chapter 4: Policy Provisions, Options and Riders (Exam 2)

View Set

Forecasting with the A/F Ratio Method

View Set

Vocabulary Workshop Level B Unit 8 Choosing the Right Word

View Set

FIN219T Chapter 13 Connect Practice

View Set

Chapter 50 Evolve Questions (Pharm)

View Set

Spelling Week 5 Practice Activity 2: Vowel Concerns: O

View Set

Graphs of lines, Slope & y- intercept Review

View Set