COSC 1437 - Midterm
Given the string shown below, if the delimiter is a space, how many tokens are in the string? "Tony's email address is [email protected]" - 4 - 5 - 6 - 7 - 9
5
T/F You may use the <, > , <=, >=, ==, and ! = relational operators to compare string objects.
True
Which of the following will 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
T/F Before you can perform a bubble sort, the data must be stored in descending order.
False
T/F It is possible to output the contents of all members of a structure variable using a cout << statement followed by the name of the structure variable.
False
T/F The bubble sort is an easy way to arrange data in ascending order but it cannot arrange data in descending order.
False
T/F You cannot directly assign an enumerator to an int variable.
False
The escape sequence that represents the null terminator is \n \t \0 nullptr None of these
\0
The expression being tested by the statement shown below will evaluate to true if var1 is ______. if (!isdigit(var1)) - an alphabetic character - 9 - a symbol such as $ or & - both an alphabetic character and a symbol such as $ or & - None of these
both an alphabetic character and a symbol such as $ or &
The ____ is adequate for searching through small arrays. binary search linear search unary search bubble sort None of these
linear search
A binary search begins with the _____ element of an array. first last largest middle None of these
middle
The following statement _______ cin >> *num3; - stores the keyboard input in the variable num3 - stores the keyboard input into the pointer num3 - is illegal in C++ - stores the keyboard input into the variable pointed to by num3 - None of these
stores the keyboard input into the variable pointed to by num3
The arguments of the strcpy function are - two C-strings - two addresses - three pointers - one array and one pointer - None of these
two addresses
T/F A selection sort and a binary search can be applied to STL vectors as well as arrays.
True
T/F A struct can contain members with varying data types.
True
T/F An array name is a pointer constant because the address stored in it cannot be changed at runtime.
True
T/F By being able to pass arrays as arguments, you can write your own functions for processing C-strings.
True
T/F 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.
True
T/F If an uppercase character is passed as an argument to the toupper function, the result will be an uppercase character.
True
T/F If you are using the bubble sort algorithm to sort an array in descending order, the smaller values move toward the end.
True
T/F 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.
True
T/F On average, an item is just as likely to be found near the beginning of an array as near the end.
True
T/F The expression *s->p; indicates that s is a structure pointer and p, which is also a pointer, is a member of the structure pointed to by s.
True
T/F The expression s->m; indicates that s is a structure pointer and m is a structure member.
True
T/F The number of comparisons made by a binary search is expressed in powers of two.
True
When you pass a 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
After the following statement executes, what value will the MAPLE enumerator be stored as, in memory? enum Tree ( OAK, MAPLE, PINE ); - "MAPLE" - 2 - 'M' - 1 - 1.0
1
What is the value stored in num after the following statement executes? num = atoi("1000"); - 1000 - 999 - "1000" - "1 thousand" - None of these
1000
With binary search algorithm, a maximum of _______ comparisons will be made on an array of 25,000 elements. 8 14 15 16
15
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 only the first two only half 2,000 None of these
20,000
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
Which of the following is TRUE about this statement? 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, then assign that value. - None of these
This statement assigns the dereferenced pointer's value, then increments the pointer's address.
The following statement ______. int *ptr = new int; - results in a compiler error - assigns an integer less than 32767 to the variable ptr - assigns an address to the variable ptr - creates a new pointer named int - None of these
assigns an address to the variable ptr
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
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 linear sort linear search binary search selection sort None of these
binary search
When a structure is passed ______ to a function, its members are NOT copied. - by reference - by value - Either of these - Neither of these
by reference
Which of the following statements deletes memory that has been dynamically allocated for an array? - int array = delete memory; - int delete [ ]; - delete [] array; - new array = delete; - None of these
delete [] array;
When an array is sorted from highest to lowest, it is said to be in reverse order forward order ascending order descending order None of these
descending order
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;
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 = 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
int temp = num2; num2 = num1; num1 = temp;
To test whether a character is a numeric digit character, use the _____ function. - isnumber - notAlpha - isnumeric - isdigit - None of these
isdigit
Which of the following will return true if the argument is a printable character other than a digit, letter, or space? - isprint - ispunct - ischar - isnotdls - None of these
ispunct
To determine whether a character entered is whitespace, use the _____ function. - iswhite - isspace - iswhitespace - isblank - None of these
isspace
A(n) _____ search uses a loop to sequentially step through an array. binary unary linear relative None of these
linear
If a is 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 a 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
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 variable. - The variable named *ptr will store the value in nullptr. - None of these
ptr is a pointer variable and will store the address of an integer variable.
The ______ sort usually performs fewer exchanges than the _______. bubble, selection binary, linear selection, bubble ANSI, ASCII None of these
selection, bubble
The advantage of a linear search is its complexity efficiency simplicity speed None of these
simplicity
To help prevent memory leaks from occurring in C++11, a _______ automatically deletes a chunk of dynamically allocated memory when the memory is no longer being used. - null pointer - smart pointer - dereferenced pointer - None of these
smart pointer
Algorithms used to arrange random data in some order are ___ algorithms. standard search sorting linear binary search None of these
sorting
The ________ function concatenates the contents of one C-string with another C-string. - strcopy - strappend - strcat - stradd - None of these
strcat
You may use a pointer to a structure as a - function parameter - structure member - function return type - All of these - None of these
All of these
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
If Circle is a structure, what does the following statement do? Circle *pcirc = nullptr; - It declares an empty structure variable named *pcirc. - It declares a structure pointer called pcirc initialized with a null pointer. - The statement is illegal in C++. - It initializes a null pointer with the value of the Circle pointer. - None of these
It declares a structure pointer called pcirc initialized with a null pointer.
Data types that are created by the programmer are known as - variables - abstract data types (ADTs) - functions - parameters - None of these
abstract data types (ADTs)
Which of the following describes only the general characteristics of an object? - initialization - abstraction - detailed specification - initiation - None of these
abstraction
Which of the following statements displays the address of the variable numb? - cout << numb; - cout << *numb; - cin >> &numb; - cout << &numb; - None of these
cout << &numb;
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[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 not compile
ptr will hold the address of numbers[1]
A ______ algorithm is a method of locating a specific item of information in a larger collection of data. sort search standard linear None of these
search
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 - strength - strlen - countstring - None of these
strlen
In C++11, you can use a new type of enum known as a(n) ________, (also known as an enum class) to have multiple enumerators with the same name, within the same scope. - universal enum - auto enum - multi-cast enum - strongly typed enum - None of these
strongly typed enum
A library function that can find one C-string inside another is - strcmp - strstr - strfind - strsearch - None of these
strstr
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
To dereference a structure pointer, the appropriate operator is - the ampersand (&) - an asterisk (*) - the -> operator - the operator () - None of these
the -> operator
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
Assuming ptr is a pointer variable, what will the following statement output? cout << *ptr; - the value stored in the variable whose address is contained in ptr - the string "*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
What is the result after the following statement executes? char var1 = tolower ('A' ); - var1 stores the character value 'A' - var1 stores the ASCII value for lowercase 'a' - the character A is output to the monitor - the character a is output to the monitor - None of these
var1 stores the ASCII value for lowercase 'a'
Dynamic memory allocation occurs - when a new variable is created by the compiler - when a new variable is created at runtime - when a pointer fails to dereference the right variable - when a pointer is assigned an incorrect address - None of these
when a new variable is created at runtime
The following statement -------. bookList[2].publisher[3] = 't'; - is illegal in C++ - will change the name of the second book in booklist to 't' - will store the character 't' in the fourth element of the publisher member of bookList[2] - will result in a runtime error - None of these
will store the character 't' in the fourth element of the publisher member of bookList[2]
T/F With pointer variables you can access but not modify data in other variables.
False
What will the following code output? int number = 22; int *var = &number; cout << *var << endl; - the address of number - 22 - an asterisk followed by 22 - an asterisk followed by the address of number
22
T/F A test using the isupper function will return false if the argument is an uppercase character.
False
T/F A linear search can only be implemented with integer values.
False
T/F A function cannot modify the members of a structure.
False
A ____ search is more efficient than a _____ search. character, string integer, double binary, linear linear, binary None of these
binary, linear
Which of the following defines an array of C-strings that will hold 49 characters and the null terminator? - char [49]; - char str [50]; - char (50) str; - character str [50]; - None of these
char str [50];
What is the output of the following statement? cout << tolower(toupper('Z') ) << endl; - uppercase Z - lowercase z - a lowercase z followed by an uppercase Z - a compiler error - None of these
lowercase z
A structure pointer contains - the address of a structure variable - the dereferenced address of a structure tag - the name and address of the structure tag - the address of a structure tag - None of these
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 - 22 - an asterisk followed by 22 - an asterisk followed by the address of number
the address of number
In C++11, 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 a compiler error
the first character of mystring