Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

use the following pieces of code and write the function printVector that will di

ID: 3601642 • Letter: U

Question

use the following pieces of code and write the function printVector that will display the vector by using a function template, and using a const_iterator for outputting vector elements. (Consider using auto in your iterator's declaration)

// prototype for function template printVector

template <tyename T> void printVector(const vector <T>& integers2);

.....

vecctor <int> integers;

//function push_back is in vectors

integers.push_back(2);

integers.push_back(3);

integers.push_back(4);

cout << " Output vector using iterator notation: ";

printVector(integers);

// Your code here......

Explanation / Answer

Please find my implementation.

// prototype for function template printVector
template <tyename T> void printVector(const vector <T>& integers2) {

for (auto it = integers2.begin() ; it != integers2.end(); ++it)
cout << " " << *it;
}