Question: I trying to run this code But I am getting this error: --mycode-- --main.cpp-- #include algorithm_utils.h #include #include #include #include #include using namespace std; int

I trying to run this code

But I am getting this error: I trying to run this code But I am getting this error:

--mycode--

--main.cpp--

#include "algorithm_utils.h" #include #include #include #include #include

using namespace std;

int main () { std::vector vectorOfInts;

// set some values: for (int i=1; i

// TODO: use replace_if to replace all even numbers with 0 std::replace_if (vectorOfInts.begin(), vectorOfInts.end(), IsEven, 0);

std::cout ::iterator it=vectorOfInts.begin(); it!=vectorOfInts.end(); ++it) std::cout

std::vector vectorOfInts2; for (int i=1; i

// TODO: use replace_if to replace all even numbers with 0 using a function object or functor // The functor needs to do the output of each replaced element.

std::for_each(vectorOfInts2.begin(), vectorOfInts2.end(), ReplaceEvenAndOutput());

std::cout ::iterator it=vectorOfInts2.begin(); it!=vectorOfInts2.end(); ++it) std::cout

--algorithm_utils.h--

#ifndef LESSON_9_STL_ALGORITHM_REPLACE_IF_ALGORITHM_UTILS_H #define LESSON_9_STL_ALGORITHM_REPLACE_IF_ALGORITHM_UTILS_H

#include

// TODO: put the prototype of the function to test for even here

bool IsEven (int i);

// TODO: put the declaration of the functor class that tests for even values here

class ReplaceEvenAndOutput{ public: void operator()(int& elem); };

#endif

--algorithm_utils.cpp--

#include "algorithm_utils.h"

// TODO: put the definition of the function to test for even here bool IsEven (int i){ return ((i%2)==0);

}

// TODO: put the definitions for the functor here class ReplaceEvenAndOutput{ public: void operator()(int& elem) { if (elem % 2 == 0) { std::cout algorithm_utils.cpp:10:7: error: redefinition of 'class ReplaceEvenAndoutput' 10 I class ReplaceEvenAndOutput \{ In file included from algorithm_utils.cpp:1: algorithm-utils.h:11:7: note: previous definition of 'class ReplaceEvenAndoutput' 11 I class ReplaceEvenAndoutput \{

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!