Docsity

Test 4 Spring 2001 - Computer Programming II | COP 3337, Exams of Computer Science

Toggle sidebar
bg1
COP 3337 TEST 4 NAME__________________
Irvine, Spring 2001
1. (30 points) Write a function named display that displays all values in a vector of strings. Use an
appropriate type of vector iterator. The function has been started for you:
void DisplayVector( const vector<string> & names )
{
}
2. (40 points) Code a binary search function for the vector of strings. The function returns the
integer position where it finds a match for searchVal. If it does not find a match, the function
returns โ€“1. The function has been started for you:
int SearchVector(const vector<string> & names, int first, int last,
const string & searchVal )
{
}
pf2

Partial preview of the text

Download Test 4 Spring 2001 - Computer Programming II | COP 3337 and more Exams Computer Science in PDF only on Docsity!

COP 3337 TEST 4 NAME__________________

Irvine, Spring 2001

  1. (30 points) Write a function named display that displays all values in a vector of strings. Use an appropriate type of vector iterator. The function has been started for you:

void DisplayVector( const vector & names ) {

}

  1. (40 points) Code a binary search function for the vector of strings. The function returns the integer position where it finds a match for searchVal. If it does not find a match, the function returns โ€“1. The function has been started for you:

int SearchVector(const vector & names, int first, int last, const string & searchVal ) {

}

  1. (10 points) Assume that a selection sort has O( n^2 ). Suppose we found that sorting a vector of size 1000 requires 5 seconds. Then how many seconds should it take to sort a vector of size 100,000?

Answer: _________ seconds.

  1. (10 points) Assume that a merge sort has O( n * log (n) ). Suppose we found that sorting a vector of size 1000 requires 5 seconds. Then how many seconds should it take to sort a vector of size 100,000?

Answer: _________ seconds.

  1. (10 points) Write statements in C++ that declare an array of 20 pointers to Employees. Use a loop to dynamically allocate twenty Employee objects and assign their addresses to the pointers in the array.

5 points extra: Write C++ statements that deallocate all the Employees you created in the previous question.