Computer Science Final Review
(T/F) you can display the contents of any array by sending its name to cout?
False only works with character arrays
(T/F) You cannot use sorting and search algorithms on vectors
False you can
Can you set two arrays equal to each other via the (=) operator?
No you need to assign element by element
(T/F) To define a function that takes an array parameter, use empty [] for array argument
True
(T/F) vals[i] = *(vals + i)
True
A selection sort and a binary search can be applied to STL Vectors as well as arrays
True
A while loop's body can contain multiple statements, as long as they are enclosed in braces
True
Arrays must be accessed via individual elements (T/F)
True
Assuming myValues is an array of int values and index is an int variable, both of the following statments do the same thing (T/F) cout << myValues[index] << endl; cout << *(myValues + index) << endl;
True
By being able to pass arrays as arguments, you can write your own functions for processing C-strings
True
On average an item is just as likely to be found near the beginning of an array as near the end (T/F)
True
The string class's front and back member functions were introduced in C++11
True
To use any of the smart pointers in C++11 you must use the following directive in the header file: #include <memory> (T/F)
True
When using the strcat function you must be careful not to overwrite the bounds of an array
True
You may use the <, >, <=, >=, ==, and != relational operators to compare string objects.
True
what would this function return? int * newNum();
a pointer
what does toupper do?
if char argument is lowercase letter, return uppercase equivalent, otherwise returns input unchanged
what doe tolower do?
if char argument is uppercase letter, return lowercase equivalent, otherwise return input unchanged
The statement: int grades[ ] = { 100, 90, 99, 80}; shows an example of
implicit array sizing
What will this program do? const int SIZE = 5; int id[SIZE]; double average[SIZE]; char grade[SIZE]; for (int i = 0; i < SIZE; i++) { cout << "Student ID: " << id[i] << " average: " << average[i] << " grade: " << grade[i] << endl;
it will cout the students id, average, and grade up to student 4
To return a pointer as a function the function must ________ in the function
not return a pointer to a local variable
A two dimensional array can have elements of _______ data types
one
This vector function removes an item from a vector
pop_back
Use ______ member function to remove last element from vector scores._______();
pop_back
After the code shown executes, which of the following statements is TRUE? int numbers[] = {0, 1, 2, 3, 4}; int *ptr = numbers; prt++; A) ptr will hold the address of numbers[0] B) ptr will hold the address of numbers[1] C) ptr will hold the address of the second byte within the element numbers[0] D) this code will not compile
ptr will hold the address if numbers[1]
Use _______ member function to add element to a full array or to an array that had no defined size scores._______(75);
push_back
Two dimensional arrays are initialized _________
row by row
Given the following declaration, where is 77 stored in the scores array? int scores[]={83, 62, 77, 97};
scores[2]
Which sort is this? - Locate smallest element in array. Exchange it with element in position 0 - Locate the next smallest element in array and exchange it with element in position 1 - Continue until all elements are arranged in order
selection sort
The _____ sort usually performs fewer exchanges than the ______ sort
selection, bubble
Use _______ member function to determine the size of a vector scores._______();
size
What is the disadvantage of bubble sorts?
slow for larger arrays
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
strlen
A library function that can find one C-string inside another is
strstr
By using the same ________ you can build relationships between data stored in two or more arrays.
subscript
point variables hold the _______ of the data it points to
the address
Dynamic memory allocation occurs
when a new variable is created at runtime
How do you pass an array to a function?
you use the arrays name
The ________ and ________ operators can be used to increment or decrement a pointer variable
++, --
What will the following code display? int numbers[4] = {99, 87}; cout << numbers[3] << endl;
0
What will the following code display? int numbers[] = {99, 87, 66, 55, 101}; cout << numbers[3] << endl;
55
What is the display for int vals [] = {4,7,11}, *valptr; valptr = vals; cout << *(valptr+1); cout << *(valptr+2)
7 11
A pointer variable is designed to store
A memory address
(T/F) Points cannot be intialized at definition time? int num, *numptr = # int val[3], *valptr = val;
False
Before you perform a bubble sort, the data must be stored in descending order
False
In C++ 11 you can pass a string object as an argument to a file stream object's open member function
False
The increment and decrement operators can be used in mathematical expressions however they cannot be used in relational expressions
False
The scope of a variable declared in a for loop's initialization expression always extends beyond the body of the scope
False
The strlen fucntion returns a C-string's length and adds one for \0 (T/F)
False
Must include _______ to use STL vectors in header
#include<vector>
_____ can define one array for multiple sets of data
2D Arrays
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;
5/25 = 0.2
How do you relate parrallel arrays?
A subscript is used to relate parallel arrays
What does the resize member function do? vel1.resize(5,0);
Add elements to a vector, optionally initializes them
What does this do? int *intptr; intptr = #
Assigns an address to a pointer variable
It is _____ to pass an argument to a function that contains an individual array element such as scores[3]
D
What is true about this statement sum += *array++; A) This statement will cause a complier error B)This statement is illegal in C++ C) This statement increments the dereferenced pointers value by one, then assigns that value D) This statement assigns the dereferenced pointer's value , then increments the pointer's address E) None of these
D
What does the following statement do? double *num2;
Declares a point
What does the swap member function do? vec1.swap(vec2);
Exchange the contents of two vectors
What displays the address of the variable numb?
I think cout << &numb;
Disadvantage of Linear Search
Inefficient(slow)
What does the following statement do? vector<int> v(10);
It creates a vector object with a staring size of 10
What does the capacity member function do? vel1.capacity();
Returns the maximum number of elements a vector can store without allocating more memory
What does the at member function do? cout << vec1.at(i);
Returns the value of the element at position i
What does the reverse member function do? vel1.reverse();
Reverse the order of the elements in a vector
What will the following statement output? cout << &num1;
The memory address of the variable named num1
What is the cout for this program? int main () { int x =25; int *ptr; ptr = &x; cout << "The value in x is " << x << endl; cout << "The address of x is " << ptr << endl; return 0; }
The value in x is 25 The address of x is 0x7e00
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
What does this do? vector<int> scores(30);
declares a vector with initial size of 30
is this valid ? int quizzes [3]; Y/N
Yes
is this valid? int quizzes [] = {12,13,15}; Y/N
Yes
What is the purpose of this? tests[i]++
adds 1 to the tests[i]
The _______, also known as the address operator, returns the memory address of a variable
ampersand &
What type of values can STL vector hold?
any value type
Which of the following converts the string "10" to the integer value 10?
atoi ("10");
The function that accepts a C-string as an argument and converts the string to a long integer is
atol
Binary Search requires array elements to _______
be in order
Subscript numbering in C++
begins with zero
Which sort is this? - Compares 1st two elements - Exchanges elements if needed - Passes through again and repeats until pass made with no exchanges
bubble Sort
what does isalnum do?
check if argument is a letter or number
what does isprint do?
check if argument is a printable character
what does ispunt do?
check if argument is a punctuation character
what does isspace do?
check if argument is a whitespace
what does isupper do?
check if argument is an uppercase letter
what does islower do?
check if argument is lowercase
what does isdigit do?
check if the argument is a digit between 0-9
what does isalpha do?
check is argument is a letter
To remove all content of a vector, use _______ member function scores._______();
clear
Use the delete operator on pointers that were
created with the new operator
What does this do? vector<int> finals(scores);
declare a vector initialized to size and contents of another vector
What does this do? vector<int> scores(30, 0);
declares a vector and initialize all elements to 0
What does this do? vector<int> scores;
declares a vector to hold int elements
use ____ to free dynamic memory
delete
Which of the following statements deletes memory that has been dynamically allocated for an array?
delete [] array;
What is the display? int vals[] = {4, 7, 11}; cout << *vals;
displays 4
What is the display? int vals[] = {4, 7, 11}; int *valptr = vals; cout << valptr[1];
displays 7
The individual values contained in an array are known as
elements
To determine if vector is empty, use ______ member function: while (!scores._____())
empty
What is the purpose of this? tests[i++];
increments i value
The ______ operator allows you to access the item that the pointer points to
indirection
How do you make an array with more than three elements?
intialized all but one element
What does this mean int *intptr;
intptr can hold the address of an int
To determine whether a character entered is a letter of the alphabet use the ____________
isalpha
To test whether a character is a printable character use the _______ function
isprint
Starting at the first element this algorithm steps through an array examining each element until it locates the value it is searching for
linear search
A binary search begins with the __________ element of an array
middle
Benefit of using a selection sort
more efficient than a bubble sort since there is fewer exchanges
_____ returns address of memory location
new
use ___ operator to allocate memory
new
When you pass a pointer as an argument to a function, you must
none of these
What happens when you use a subscript that is out of bounds in an array
the elements out of bounds dont exist
What does this loop do? int tnum; double average, sum = 0; for (tnum = 0; tnum < SIZE; tnum++) sum += tests[tnum];
the loop adds together all the array elements
The range based for loop in c++11 is designed to work with a built in variable known as
the range based variable
What happens when an array is initialized with fewer values than the size declarator
the remaining elements will be set to 0
An array can store a group of values, but the values must be
the same data type
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 function must use reference parameters