Question: 1.(Maximum and minimum ) Implement the following functions that find the maximum and minimum elements in a first-class container: template ElementType maxElement(ContainerType& container){ } template
1.(Maximum and minimum ) Implement the following functions that find the maximum and
minimum elements in a first-class container:
template
ElementType maxElement(ContainerType& container){
}
template
ElementType minElement(ContainerType& container){
}
2. (Occurrence of a value ) Implement the following function that finds the number of occurrences of
a specified value in a first-class container:
template
int countElement(ContainerType& container, const ElementType& value){
}
3. Implement the reverse and reverse_copy functions.
template
void reverse(BidirectionalIterator beg,BidirectionalIterator end){
}
template
OutputIterator reverse_copy(BidirectionalIterator beg,BidirectionalIterator end, OutputIterator targetPosition){
}
4. Implement the replace and replace_if functions.
template
void replace(ForwardIterator beg, ForwardIterator end,const T& oldValue, const T& newValue){
}
template
void replace_if(ForwardIterator beg, ForwardIterator end,boolFunction f, const T& newValue){
}
please test your code with this test code to see if it works:
put all the above functions into a header file and name it STLconcepts.h once you have completed them so thats what you wil be including into the test code below where in says "#include "STLconcepts.h"
------------------------------------------------------------------------------------------------------------------
#include
#include "STLconcepts.h"
using namespace std;
int main()
{
// data for testing, should handle ANY data type
int list1[] = { 3, 5, 8, 0, 2, 8, 7, 6 };
double values[] = { 143, 2, 3, 55, 41, 4, 777 };
// Exercise 22_01
vector
cout << "The maximum value is " << (maxElement
cout << "The minimum value is " << (minElement
// Exercise 22_03
cout << "The number of 8's is: " << (countElement
// Exercise 23_10
cout << "Initial contents, values: ";
for (unsigned i = 0; i < 7; i++)
cout << values[i] << " ";
cout << endl;
cout << " ";
reverse(values, values + 7);
cout << " After reverse, values: ";
for (unsigned i = 0; i < 7; i++)
cout << values[i] << " ";
cout << endl;
vector
reverse_copy(values, values + 7, doubleVector.begin());
cout << " After reverse_copy, vector v is: ";
for (unsigned i = 0; i < 7; i++)
cout << doubleVector[i] << " ";
cout << endl;
// Exercise 23_11
replace(values, values + 7, 3, 555);
cout << " After the replace function, values: ";
for (unsigned i = 0; i < 7; i++)
cout << values[i] << " ";
cout << endl;
replace_if(values, values + 7, greaterThan4, 555);
cout << " After the replace_if function, values: ";
for (unsigned i = 0; i < 7; i++)
cout << values[i] << " ";
cout << endl;
system("pause");
return 0;
}
Thanks
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
