COMSC165 Midterm Review
null character
In C++, a string is a sequence of characters stored in consecutive memory, terminated by a: ・semicolon ・space ・period ・null character ・None of these
Sorting
________ algorithms are used to arrange random data into some order. ・Linear ・Sorting ・Standard search ・Binary search
Two or more
________ functions may have the same name, as long as their parameter lists are different. ・Zero ・Two or more ・Only two ・Un-prototyped ・None of these
Variables
________ represent storage locations in the computer's memory. ・Comments ・Integers ・Variables ・Literals ・None of these
strstr
A library function that can find one string inside another is: ・strsearch ・strcmp ・strstr ・strfind ・None of these
the address of an existing object
A pointer may be initialized with: ・the value of an integer variable ・the value of a floating point variable ・the address of an existing object ・All of these ・None of these
preprocessor directive
A statement that starts with a # is called a: ・preprocessor directive ・function ・key word ・comment ・None of these
one
A two-dimensional array can have elements of ________ data type(s). ・four ・one ・two ・Any of these ・None of these
All of these
A two-dimensional array of characters can contain: ・strings of different lengths ・strings of the same length ・uninitialized elements ・All of these ・None of these
binary, linear
A(n) ________ search is more efficient than a ________ search. ・linear, binary ・character, string ・integer, double ・binary, linear
sequential
A(n) ________ search uses a loop to sequentially step through an array. ・relative ・sequential ・Unary ・Binary
15
After execution of the following code, what will be the value of input_value if the value 0 is entered at the keyboard at run time? cin >> input_value; if (input_value > 5) input_value = input_value + 5; else if (input_value > 2) input_value = input_value + 10; else input_value = input_value + 15; ・10 ・25 ・5 ・66 ・15
char names[5][21];
An array that will hold 5 names with 20 characters in the name would be declared using which statement? ・char names[21][5]; ・char names[5][21]; ・char names[5][20]; ・None of these will work.
sorted
Array elements must be ________ before a binary search can be performed. ・summed ・shuffled ・sorted ・zeroed
False
Before you can perform a selection sort, the data must be stored in ascending order. ・True ・False
from lowest to highest value
Data that is sorted in ascending order is ordered ・from highest to lowest value ・from lowest to highest value ・always with a linear sort algorithm
1 6 3
Given the following function definition 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 fragment that invokes calc? (All variables are of type int) x = 1; y = 2; z = 3; calc(x, y); cout << x << " " << y << " " << z << endl; ・1 6 3 ・1 14 9 ・1 2 3 ・3 6 3 ・None of these
toupper
To change a character argument from lower case to upper case, use this function. ・isupper ・tolarge ・fromlower ・toupper ・None of these
assigns the dereferenced pointer's value, then increments the pointer's address
Look at the following statement: sum += *array++; This statement: ・is illegal in C++ ・increments the dereferenced pointer's value by one, then assigns that value ・will always result in a compiler error ・assigns the dereferenced pointer's value, then increments the pointer's address ・None of these
All of the above are valid identifiers
Of the following, which is a valid C++ identifier? ・___department ・_employee_number ・June1997 ・myExtraLongVariableName ・All of the above are valid identifiers.
linear search
The ________ is adequate for searching through small arrays. ・linear search ・bubble sort ・simplified binary search ・unary search
selection, bubble
The ________ sort usually performs fewer exchanges than the ________ sort. ・binary, linear ・ANSI, ASCII ・bubble, selection ・selection, bubble
ampersand ( & )
The ________, also known as the address operator, returns the memory address of a variable. ・percent sign (%) ・asterisk ( * ) ・exclamation point ( ! ) ・ampersand ( & ) ・None of these
char lastName[26];
To define an array that will store students' last names of up to 25 characters in length, which is an appropriate statement? ・char lastName[26]; ・string lastName[25]; ・string lastName[24]; ・char lastName[25]; ・None of these
isalpha
To determine whether a character entered is a letter of the alphabet, use this function. ・alphaok ・isdigit ・isalpha ・fromkeyboard ・None of these
int* ptr;
The statement int *ptr; has the same meaning as ・int ptr*; ・int ptr; ・*int ptr; ・int* ptr; ・None of these
stores the keyboard input into the variable pointed to by num3
The statement cin >> *num3; ・stores the keyboard input into the variable num3 ・stores the keyboard input into the pointer called num3 ・stores the keyboard input into the variable pointed to by num3 ・is illegal in C++ ・None of these
at least once
The statements in the body of a while loop may never be executed, whereas the statements in the body of a do-while loop will be executed: ・at least once ・never ・as many times as the user wishes ・at least twice ・None of these
static
The value in this type of local variable persists between function calls. ・static ・global ・internal ・dynamic ・None of these
default
These types of arguments are passed to parameters automatically if no argument is provided in the function call. ・relational ・local ・default ・global ・None of these
strncpy
This function accepts pointers to two strings and an integer argument, which indicates how many characters to copy from the second string to the first. ・strcpy ・copystring ・strncpy ・strintcpy ・None of these
strcat
This function concatenates the contents of one string with another string. ・strappend ・stradd ・strcat ・strcopy ・None of these
atoi
This function converts a string to an integer and returns the integer value. ・strtoint ・strint ・atoi ・atoint ・None of these
\0
This is the escape sequence representing the null terminator. ・/NULL ・\n ・\t ・\0 ・None of these
push_back
This vector function is used to insert an item into a vector. ・push_back ・store ・add_item ・insert_item
pop_back
This vector function removes an item from a vector. ・pop_back ・delete_item ・remove_item ・erase
size
This vector function returns the number of elements in a vector. ・length ・size ・num_elements ・elements
empty
This vector function returns true if the vector has no elements. ・null_size ・has_no_elements ・is_empty ・empty
False
Using a binary search, you are more likely to find an item than if you use a linear search. ・False ・True
20,000
Using a linear search to find a value that is stored in the last element of an array of 20,000 elements, ________ element(s) must be compared. ・only half ・only the first ・2000 ・20,000
declares a pointer variable named num2
What does the following statement do? double *num2; ・declares a double variable named num2 ・declares and initializes an pointer variable named num2 ・declares a pointer variable named num2 ・initializes a variable named *num2 ・None of these
It creates a vector object with a starting size of 10.
What does the following statement do? vector<int> v(10); ・It creates a vector object with a starting size of 10. ・It creates a vector object and initializes the first element with the value 10. ・It creates a vector object and initializes all of its elements to the value 10. ・It creates a vector object that can store only values of 10 or less.
It creates a vector object with a starting size of 10 and all elements are initialized with the value 2.
What does the following statement do? vector<int> v(10, 2); ・It creates a vector object and initializes all the first two elements with the values 10 and 2. ・It creates a vector object with a starting size of 10 and all elements are initialized with the value 2. ・It creates a vector object with a starting size of 10 and the first element initialized with the value 2. ・It creates a vector object with a starting size of 2 and the first element initialized with the value 10.
1 1 1... and on forever
What is the output of the following code segment? n = 1; while (n <= 5) cout << n << ' '; n++; ・1 1 1... and on forever ・2 3 4 5 6 ・2 3 4 5 ・1 2 3 4 ・1 2 3 4 5
2 0 0
What is the output of the following program? # 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 0 ・0 0 0 ・2 0 2 ・2 2 2
2 0 2
What is the output of the following program? # 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 2 2 ・2 0 2 ・2 0 0
4 2
What is the output of the following program? # 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 ・2 2 ・2 4 ・4 4
lower case z
What is the output of the following statement? char c = 'Z'; c = tolower(toupper(c)); cout << c << endl; ・a lower case z followed by an upper case Z ・lower case z ・upper case Z ・a compiler error ・None of these
false
What will be the output of the following code segment after the user enters 0 at the keyboard? int x = -1; cout << "Enter a 0 or a 1 from the keyboard: "; cin >> x; if (x) cout << "true" << endl; else cout << "false" << endl; ・Nothing will be displayed. ・x ・true ・false
You passed the test!
What will the following segment of code output? You can assume the user enters a grade of 90 from the keyboard. cout << "Enter a test score: "; cin >> test_score; if (test_score < 60) cout << "You failed the test!" << endl; if (test_score > 60) cout << "You passed the test!" << endl; else cout << "You need to study for the next test!"; ・You passed the test! ・You failed the test! ・You failed the test! You passed the test! ・You failed the test! You did poorly on the test! ・None of these
the address of the first variable comes before the address of the second variable in the computer's memory
When the less than ( < ) operator is used between two pointer variables, the expression is testing whether: ・the value pointed to by the first is less than the value pointed to by the second ・the value pointed to by the first is greater than the value pointed to by the second ・the first variable was declared before the second variable ・the address of the first variable comes before the address of the second variable in the computer's memory ・None of these
the actual value of the variable whose address is stored in the pointer variable
When you work with a dereferenced pointer, you are actually working with: ・a variable whose memory has been deallocated ・the actual value of the variable whose address is stored in the pointer variable ・a copy of the value pointed to by the pointer variable ・All of these ・None of these
char
Which data type typically requires only one byte of storage? ・short ・char ・float ・double ・int
\n
Which escape sequence causes the cursor to move to the beginning of the next line? ・\b ・\r ・\n ・\t
foo(2, ';');
Which line in the following is NOT a valid call to the function with the following prototype: void foo(string buff, int s = 1, char term = '\n'); ・foo("Alex", 5, ','); ・foo("Alex", 3); ・foo(2, ';'); ・foo("Hellen");
15
Which line in the following program contains the header for the showDub function? 1 #include <iostream> 2 using namespace std; 3 4 void showDub(int); 5 6 int main( ) 7 { 8 int x = 2; 9 10 showDub(x); 11 cout << x << endl; 12 return 0; 13 } 14 15 void showDub(int num) 16 { 17 cout << (num * 2) << endl; 18 } ・4 ・10 ・6 ・15
4
Which line in the following program contains the prototype for the showDub function? 1 # include <iostream> 2 using namespace std; 3 4 void showDub(int); 5 6 int main( ) 7 { 8 int x = 2; 9 10 showDub(x); 11 cout << x << endl; 12 return 0; 13 } 14 15 void showDub(int num) 16 { 17 cout << (num * 2) << endl; 18 } ・6 ・15 ・4 ・10
All of these are invalid.
Which of the following statements is not valid C++ code? ・int ptr = &num1; ・float num1 = &ptr2; ・int ptr = int *num1; ・All of these are valid. ・All of these are invalid.
vector<int> v;
Which statement correctly defines a vector object for holding integers? ・int<vector> v; ・vector<int> v; ・int vector v; ・vector v<int>;
cout << &num1;
Which statement displays the address of the variable num1? ・cin >> &num1; ・cout << *num1; ・cout << &num1; ・cout << num1; ・None of these