CS 2134 Homework Assignment 3A solved

Original price was: $35.00.Current price is: $30.00.



5/5 - (5 votes)

Programming Part:
1. Add the method erase( Vector::iterator vItr) to the Vector class. The signature of your method should be:iterator erase( iterator vItr)2. Write a generic function template called print if that:• takes three parameters: two iterators start, end, and a functor predstart and end have the capabilities of a forward iterator, and refer to a range[start,end) in a containerpred is a functor that takes an element in the range [start,end) as an arguementand returns a bool• prints1 all items in the range [start,end) which evaluates to true• runs in O(n) time where n is the number of items in the range [start,end)The signature of your generic function template is:template< class Itr, class UnaryPred >void print_if( Itr start, Itr end, UnaryPred pred )∗A bonus of %10 percent will be given if you turn in this homework assignment by Mon. Feb 15 at 11:00 p.m.1Print each item on its own line13. Create a functor called GPA in range where:• the class has two private member variables of type double: low and high• the constructor has two parameters of type double: l and h which it uses to initializethe private member variables low and high• the overloaded operator() takes a single argument of type student and returns trueif the student’s gpa is in the range [low, high]. Otherwise the overloaded operator()returns false4. Test your answer to programming questions 3 and 2 by creating a vector of type student. Useyour code from questions 3 and 2 to print out all the students in your vector whose GPA iswithin [3, 4]. Turn in your testing code.2Written Part1. For the vector class, and for the following code2snippet:vector c { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12 };vector::iterator itr1 = c.begin()+2;vector::iterator itr2 = c.begin()+4;vector::iterator itr3 = c.begin()+8;cout << *(c.begin( ) + ( c.end( ) – c.begin( ) )/2 ) << endl;c.erase(itr2);cout << *itr1 << endl;cout << *itr2 << endl;cout << *itr3 << endl;cout << *(c.begin( ) + ( c.end( ) – c.begin( ) )/2 ) << endl;What is printed? Explain your answer.32. In written question 1, which of the iterators were valid after the erase method was called.We will say an iterator is still “valid” if it refers to the same item as before the method wascalled.3. Using big-Oh notation, give the worst case run time for the method erase, which you implemented programming problem 1.4. Finish writing the following function that subtracts one from every item in the range [start,end).template< class Itr >void subtractOne( Itr start, Itr end ){// Fill in the code here}For example, the following code snippet:vector< int > a = { 144, 524, 230, 8 };subtractOne( a.begin( ), a.end( ) );results in the vector a now containing 143, 523, 229, 7.2Remember c.end() – c.begin() returns the number of items in the range [ c.begin(), c.end() )3Hint: think of how you implemented the erase method in the Vector class.35. For the Vector class we discussed in class, if we removed the word explicit in front of theconstructor, i.e.template class Vector{public:Vector( int initSize = 0 ) :theSize( initSize ), theCapacity( initSize + SPARE_CAPACITY ){ objects = new Object[ theCapacity ]; }// … rest of class the same as before}What would be printed by the following code snippet?Vector v(3);v = 110;cout << v.capacity();4