Exam 2 C++

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

A function can have no parameters, one parameter, or many parameters and can return ________ value(s).

only one

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]

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

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

sorted

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

static

Assuming narray is an int array, what type of statement is this? auto [v1, v2, v3] = narray;

structured binding declaration

Given the following function: void calc (int a, int& b) { int c; c = a + 2; a = a * 3; b = c + a; } What is the output of the following code segment that invokes calc()? int x = 1; int y = 2; int z = 3; calc(x, y); cout << x << " " << y << " " << z << endl;

1 6 3

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

55

What will the following code display? #include <iostream> using namespace std; int getValue(int); int main() { int x = 2; cout << getValue(x) << endl; return 0; } int getValue(int num) { return num + 5; }

7

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

1000

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

2 0 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

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

What will the following code display? vector<int> numbers {3, 5}; for (int val : numbers) cout << val << endl;

3 5

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 <iostream> 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 does the following code do? const int SIZE = 5; double x[SIZE]; for (int i = 2; i <= SIZE; i++) { x[i] = 0.0; }

An error will occur when the code runs.

What does the following statement do? vector<int> v(10);

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? void swap(int num1, int num2) { int temp = num2; num2 = num1; num1 = temp; }

The swap function must use reference parameters.

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] equals 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] swap array[index] with array[index + 1] End If End For End For

bubble sort

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

constant integer expression, zero

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

int

Which line in the following program contains the prototype showDub function? 1 #include <iostream> 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

Which line in the following program contains a call to the showDub function? 1 #include <iostream> 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 7

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

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


Conjuntos de estudio relacionados

Chapter 19 Documenting and Reporting Fundamentals of Nursing Module 3

View Set

Pharmacology Chapter 32 Antidiabetic Drugs - evolve

View Set

NUR243 PrepU ch16 Nursing Care of the Child With an Alteration in Intracranial Regulation/Neurologic Disorder

View Set

6650 Chapter 8: Corporate Strategy: Vertical Integration and Diversification

View Set

Biology Chapter 4: Cell membranes and Transport

View Set

Chapter 5 Terms - Small Business management

View Set