Midterm Flashcards

(80 cards)

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
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
the actual value of the variable whose address is stored in the pointer variable
25
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
Declares a pointer variable named num2
26
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
This statement assigns the dereferenced pointer's value, then increments the pointer's address.
27
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
ptr is a pointer variable and will stored the address of an integer value.
28
Assuming ptr is a pointer variable, what will the following statement output? cout << *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
the value stored in the variable whose address is contained in ptr
29
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
All of these are invalid
30
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
delete [] array;
30
Which of the following statements displays the address of the variable numb? cout << numb; cout << *numb; cin << &numb; cout << &numb;
cout << &numb;
31
What does the following statement do? cin >> *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
stores the keyboard input in the variable pointed to by num3
32
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
assigns an address to the variable ptr
33
Dynamic memory allocation occurs
allocation occurs when a new variable is created at runtime
34
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
None of these
35
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.
smart pointer
36
What will the following code output? int number = 22; int *var = &number; cout << *var << end1;
22
37
What will the following code output? int number = 22; int *var = &number; cout << var << end1;
the address of the number
38
The test using the isupper function will return false if the argument is an uppercase character.
False
39
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
ptr will hold the address of numbers[1]
40
By being able to pass arrays as arguments, you can write your own functions for processing C-strings.
True
41
If an uppercase character is passed as an argument to the toupper function, the result will be an uppercase character.
True
42
You may use the <, >, <=, >=, and != relational operators to compare string objects.
True
43
To test whether a character is a numeric digit character, use the ___ function. isnumber notAlpha isnumeric isdigit none of these
isdigit
44
The escape sequence that represents the null terminator is \0 \t \n nullptr none of these
\0
45
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
strlen
46
The arguments of the strcpy function are two C-strings two addresses three pointers one array and one pointer none of these
two addresses
47
A library function that can find one C-string inside another is strcmp strstr strfind strsearch none of these
strstr
48
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
atol
49
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
ispunct
50
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
both an alphabetic character and a symbol such as $ or &
51
To determine whether a character entered is whitespace, use the ___ function. iswhite isspace iswhitespace isblank none of these
isspace
52
What is the output of the following statement? cout << tolower(toupper('Z')) << end1; uppercase z a lowercase z followed by an uppercase z lowercase z compiler error none of these
lowercase z
53
The ___ functin concatenates the contents of on C-string with another C-string. strcat strcopy strappend stradd none of these
strcat
54
What is the value stored in num after the following statement executes? num = atoi("1000"); 999 "1000" 1000 "1 thousand" none of these
1000
55
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
char str[50];
56
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
var1 stores the ASCII value for the lowercase 'a'
56
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
5
57
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
the first character of mystring
58
A struct can contain members with varying data types.
True
59
A function cannot modify the members of a structure.
False
60
The expression s->m; indicates that s is a structure pointer and m is a structure member.
True
61
It is possible to output the contents of all members of a structure using a cout<< statement followed by the name of the structure variable.
False
62
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.
True
63
You cannot directly assign an enumerator to an int variable.
False
64
Which of the following describes only the general characteristics of an object? abstraction initialization detailed specification initiation none of these
abstraction
65
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
will store the character 't' in the fourth element of the publisher member of bookList[2]
66
When a structure passed ___ to a function, its members are NOT copied. by value by reference either of these none of these
by reference
67
You may use a pointer to structure as a function parameter structure member function return type All of these None of these
All of these
68
Data types that are created by the programmer are known as variables functions parameters abstract data types (ADTs) none of these
abstract data types (ADTs)
69
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
the address of a structure variable
70
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
employee[2].hourlyWage = 75.00;
71
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
takes a Circle structure as a parameter, does something, and returns a Circle structure
72
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
the dot operator
73
To dereference a structure pointer, the appropriate operator is the ampersand (&) an asterisk (*) the -> operator the operator () none of these
the -> operator
74
If a structure variable and p, a pointer, is a member of the structure, what will the following statement do? cout << *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
output the dereferenced value pointed to by p
75
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
It declares a structure pointer called pcirc initialized with a null pointer.
76
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
strongly typed enum
77
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
1