Midterm Flashcards

1
Q

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

A

False

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

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

A

True

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

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

A

True

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

A linear search can only be implemented with integer values.

A

False

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

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

A

False

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

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

A

True

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

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

A

True

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

a method of locating a specific item in a larger collection of data

A

search algorithm

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

The advantage of a linear search is its

A

simplicity

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

A ____ search is more efficient than a ____ search.

A

binary
linear

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

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

A

middle

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

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

A

selection
bubble

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

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.

A

20,000

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

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

A

linear

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

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

A

descending order

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

The ___ is adequate for search through small arrays.

A

linear search

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

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

A

sorting

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
17
Q

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

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

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

num1 = num2;
num2 = num1;

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

None of these

A

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

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
18
Q

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

A

binary search

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
19
Q

The binary search algorithm, a maximum of ___ comparisons will be made on an array of 25,000 elements.

A

15

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
20
Q

With pointer variables you can access but not modify data in other variables.

A

False

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
21
Q

An array name is a pointer constant because the address stored in it cannot be changed at runtime.

A

True

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
22
Q

C++ does not perform array bounds checking, making it possible for you to assign a pointer the address of an element out of the boundaries of an array.

A

True

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
23
Q

In C++11 you can use smart pointers to dynamically allocate memory and not worry about deleting the memory when you are finished using it.

A

True

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
24
Q

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

a variable whose memory has been allocated

a copy of the value pointed to by the pointer variable

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

None of these

A

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

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
25
Q

What does the following statement do?
double *num2;

Declares a double variable named num2

Declares and initializes a pointer variable named num2

Initializes a pointer variable named num2

Declares a pointer variable named num2

None of these

A

Declares a pointer variable named num2

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
26
Q

What does the following statement do?
sum += *array++;

This statement is illegal in C++

This statement will cause a compiler error

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

This statement increments the dereferenced pointer’s value by one, the assigns that value

None of these

A

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

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
27
Q

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

The variable named *ptr will store an integer value

The variable named *ptr will store an asterisk and an integer value

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

The variable named *ptr will store the value in nullptr

None of these

A

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

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
28
Q

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

the string “*ptr”

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

the address of the variable whose address is stored in ptr

the address of the variable stored in ptr

None of these

A

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

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
29
Q

Which of the following statements is not valid C++ code?

int ptr = &num1;

int ptr = int *num1;

float num1 = &ptr2;

All of these are valid

All of these are invalid

A

All of these are invalid

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
30
Q

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

delete [] array;

int array = delete memory;

int delete [ ];

new array = delete;

None of these

A

delete [] array;

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
30
Q

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

cout &laquo_space;numb;

cout &laquo_space;*numb;

cin &laquo_space;&numb;

cout &laquo_space;&numb;

A

cout &laquo_space;&numb;

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
31
Q

What does the following statement do?
cin&raquo_space; *num3;

stores the keyboard input in the variable num3

stores the keyboard input in the variable pointed to by num3

stores the keyboard input into the pointer num3

is illegal in C++

None of these

A

stores the keyboard input in the variable pointed to by num3

32
Q

What does the following statement do?
int *ptr = new int;

results in compiler error

assigns an integer less that 32767 to the variable ptr

assigns an an address to the variable ptr

creates a new pointer named int

None of these

A

assigns an address to the variable ptr

33
Q

Dynamic memory allocation occurs

A

allocation occurs
when a new variable is created at runtime

34
Q

When you pass pointer as an argument to a function, you must

declare the pointer value again in the function call

dereference the pointer value in the function prototype

use the #include statement

not dereference the pointer in the function’s body

None of these

A

None of these

35
Q

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

A

smart pointer

36
Q

What will the following code output?

int number = 22;
int *var = &number;
cout &laquo_space;*var &laquo_space;end1;

A

22

37
Q

What will the following code output?

int number = 22;
int *var = &number;
cout &laquo_space;var &laquo_space;end1;

A

the address of the number

38
Q

The test using the isupper function will return false if the argument is an uppercase character.

A

False

39
Q

int numbers[] = {0, 1, 2, 3, 4};
int *ptr = numbers;
ptr++;

ptr will hold the address of the numbers[0]

ptr will hold the address of the second byte within the element numbers[0]

ptr will hold the address of numbers[1]

this code will no compile

A

ptr will hold the address of numbers[1]

40
Q

By being able to pass arrays as arguments, you can write your own functions for processing C-strings.

A

True

41
Q

If an uppercase character is passed as an argument to the toupper function, the result will be an uppercase character.

A

True

42
Q

You may use the <, >, <=, >=, and != relational operators to compare string objects.

A

True

43
Q

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

isnumber

notAlpha

isnumeric

isdigit

none of these

A

isdigit

44
Q

The escape sequence that represents the null terminator is

\0

\t

\n

nullptr

none of these

A

\0

45
Q

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

numchar

strlen

strlength

countstring

none of these

A

strlen

46
Q

The arguments of the strcpy function are

two C-strings

two addresses

three pointers

one array and one pointer

none of these

A

two addresses

47
Q

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

strcmp

strstr

strfind

strsearch

none of these

A

strstr

48
Q

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

atol

strlong

strtolong

stringlong

none of these

A

atol

49
Q

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

isprint

ischar

isnotdls

ispunct

none of these

A

ispunct

50
Q

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 &

an alphabetical character

9

a symbol such as $ or &

none of these

A

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

51
Q

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

iswhite

isspace

iswhitespace

isblank

none of these

A

isspace

52
Q

What is the output of the following statement?
cout &laquo_space;tolower(toupper(‘Z’)) &laquo_space;end1;

uppercase z

a lowercase z followed by an uppercase z

lowercase z

compiler error

none of these

A

lowercase z

53
Q

The ___ functin concatenates the contents of on C-string with another C-string.

strcat

strcopy

strappend

stradd

none of these

A

strcat

54
Q

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

999

“1000”

1000

“1 thousand”

none of these

A

1000

55
Q

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

char [49];

char[50] str;

char str[50];

character str[50];

none of these

A

char str[50];

56
Q

What is the result after the following code executes?
char var1 = tolower(‘A’);

var1 stores the character value ‘A’

the character A is output to the monitor

the character a is output to the monitor

var1 stores the ASCII value for the lowercase ‘a’

none of these

A

var1 stores the ASCII value for the lowercase ‘a’

56
Q

Given the string shown below, if the delimiter is a space, how many tokens are in the string?
“Tony’s email address is tony_g@mycollege.edu

4

5

6

7

9

A

5

57
Q

In C++, 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 ASCII value of the first character of mystring

the first character of mystring

nothing, the function is missing an argument

this will cause compiler error

A

the first character of mystring

58
Q

A struct can contain members with varying data types.

A

True

59
Q

A function cannot modify the members of a structure.

A

False

60
Q

The expression s->m; indicates that s is a structure pointer and m is a structure member.

A

True

61
Q

It is possible to output the contents of all members of a structure using a cout&laquo_space;statement followed by the name of the structure variable.

A

False

62
Q

The expression *s->p; indicates that is a structure pointer and p, which is also a pointer, is a member of the structure pointed to by s.

A

True

63
Q

You cannot directly assign an enumerator to an int variable.

A

False

64
Q

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

abstraction

initialization

detailed specification

initiation

none of these

A

abstraction

65
Q

The following statement ___.
bookList[2].publisher[3] = ‘t’;

is illegal in C++

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

will result in runtime error

will change the name of the second book in bookList to ‘t’

none of these

A

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

66
Q

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

by value

by reference

either of these

none of these

A

by reference

67
Q

You may use a pointer to structure as a

function parameter

structure member

function return type

All of these

None of these

A

All of these

68
Q

Data types that are created by the programmer are known as

variables

functions

parameters

abstract data types (ADTs)

none of these

A

abstract data types (ADTs)

69
Q

A structure pointer contains

the address of structure variable

the dereferenced address of a structure tag

the name and address of the structure tag

the address of structure tag

none of these

A

the address of a structure variable

70
Q

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

employee[2] -> hourlyWage = 50.00;

employee2.hourlyWage = 7.50;

hourlywage[2].employee = 29.75;

employee[2].hourlyWage = 75.00;

none of these

A

employee[2].hourlyWage = 75.00;

71
Q

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

determines and returns the area of a circle

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

operates on a constant reference to a circle structure

takes two Circle parameters and does something

none of these

A

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

72
Q

Which of the following allow you to access structure members?

the structure access operator

the dot operator

the #include directive

the getmember function

none of these

A

the dot operator

73
Q

To dereference a structure pointer, the appropriate operator is

the ampersand (&)

an asterisk (*)

the -> operator

the operator ()

none of these

A

the -> operator

74
Q

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

output the dereferenced value pointed to by p

result in compiler error

output the address stored in p

output the value stored in a

none of these

A

output the dereferenced value pointed to by p

75
Q

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

It declares an empty structure variable named *pcirc.

The statement in illegal in C++

It initializes a null pointer with the value of the Circle pointer.

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

None of these

A

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

76
Q

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

universal enum

strongly type enum

multi-cast enum

auto enum

none of these

A

strongly typed enum

77
Q

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

“MAPLE”

1

2

‘M’

1.0

A

1