CS3: PROGRAMMING PATTERNS EXAM #1 name: first ________________ last _____________________ The number of points for each question is given in square brackets. 1. [10] Explain what default parameter values are. Describe "function overloading" and "function call resolution". Simplify the following code using default parameter values. int *setUpArray(int size, int value){ int *a = new int[size]; for (int i=0; i < size; ++i) a[i] = value; return a; } int *setUpArray(int size){ int *a = new int[size]; for (int i=0; i < size; ++i) a[i] = 0; return a; } int *setUpArray(){ int *a = new int[100]; for (int i=; i < 100; ++i) a[i] = 0; return a; } 2. [10] Describe "member initialization list". Simplify the following code using member initialization list. MyClass::MyClass(int x, char y, string z){ x_ = x; y_ = y; z_ = z; } 3. [10] splice() is a specialized method that inserts one list into another in constant time but destroys the first list. Explain why this may be implemented for the list but not for any other sequential container. Give an example usage of splice() 4. [10] Explain why inserting an element into map with insert() is considered "safe" while inserting with indexing operator is considered "unsafe" with respect to an existing element. Give example code which demonstrates the safety of element insert with insert() 5. [10] Explain the difference between a map and a multimap. Explain what upper_bound() and lower_bound() return for the two containers. Give an example usage for the two functions. 6. [15] Define a callback. Name three types of callbacks used in STL algorithms. Given an container that contains integers. myCont Use count_if() algorithm and a lambda function as a callback to count the number of integers that are even. Explain the operation of your code. 7.[10] Provided that c1, c2 and c3 are of appropriate ranges. Use transform() algorithm so that it copies the larger of the corresponding elements from c1 and c2 to c3. That is, if c1 = {1, 2, 3, 4, 5} and c2 = {5, 4, 3, 2, 1} then c3 should become c3={5, 4, 3, 4, 5} 8. [10] Explain what insert_iterator and inserter() function is. Given the following data structures: vector v1 = {1, 2, 3, 4, 5}; vector v2; Explain the problem with the below code and fix it with inserter() function. copy(v1.begin(), v1.end(), v2.begin()); 9. [15] In the course, we studied two hashmap implementations. The simple and and more complex called finalHashmap. Explain what the advantages of the more complex implementation were. Give an example client code that uses the complex implementation of the finalHashmap that will not use for the simple implementation.