Final exam(7-9, 11)

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

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

None of these

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

None of these

An array can easily be stepped through by using a

a for loop

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

a member

A pointer variable is designed to store

a memory address

Given the following structure decaration, 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

Data that is to be sorted in ascending order is ordered

from lowest value to highest value

Passing a structure as a constant reference parameter to a function

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

An array with no elements is

illegal in C++

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

implicit array sizing

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

null terminator

After the code shown executes, which of the following statements is true? int numbers[] = {0, 1, 2, 3, 4}; int *ptr = numbers; ptr++;

ptr will hold the address of numbers[1]

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

he advantage of a linear search is its

simplicity

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

sorted

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

sorting

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.

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

subscript

The name of a structure is referred to as its

tag/struct

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

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

Dynamic memory allocation occurs

when a new variable is created at runtime

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

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

If you leave out the size declarator in an array definition

you must furnish an initialization list

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

++, --

What will the following code display? int numbers[] = {99, 87, 66, 55, 101}; for (int i = 1; i < 4; i++) cout << numbers[i] << " "

87 66 55

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

1000

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

2

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

55

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

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

4

Which of the following is an example of a C++ primitive data type?

All of these

You may use a pointer to a structure as a

All of these

What does the following statement do? double *num2;

Declares a pointer variable named num2

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 functions must use reference parameters.

Data types that are created by the programmer are known as

abstract data types (ADTs)

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

abstraction

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

address

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

ampersand ( & )

Unlike regular variables, __________ can hold multiple values.

arrays

The following statement __________ int *ptr = new int;

assigns an address to the variable ptr

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

A __________ search is more efficient than a __________ search.

binary, linear

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

When a structure is passed __________ to a function, its members are not copied.

by reference

A structure __________ contain members of the same data type.

can

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

constant integer expression, zero

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

cout << student[1].gpa;

Before a structure can be used it must be

declared

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

descending order

The individual values contained in an array are known as

elements

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

employee[2].hourlyWage = 75.00;

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

indirectly

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

initialization list

Arrays must be __________ at the time they are __________.

initialized, declared

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;

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

linear

The __________ is adequate for searching through small arrays.

linear search

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

A function __________ return a structure.

may

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

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

multiply, divide

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

name

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

the dot operator

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

the memory address of the variable named num1

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

the same data type

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

to prevent changes to the structure's members

Which of the following defines a unique_ptr named uniq that points to a dynamically allocated int?

unique_ptr<int> uniq( new int );


Kaugnay na mga set ng pag-aaral

Exam 3 Chapter 5 and 6 Memory, Thinking, and Intelligence

View Set

Human Growth: Test 3; True/False

View Set

(56. What is the normal pH of blood) 18.1b Physical Characteristics of Blood

View Set

unit 2- differentiation definition and fundamental properties

View Set

Los presagios antes de los españoles y el descubrimiento de América

View Set

MAN 4720, Chapter 1, Exam 1 Review

View Set

CSC Healthcare Informatics Exam #2

View Set