Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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: image text in transcribed

--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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Oracle Solaris 11.2 System Administration (oracle Press)

Authors: Harry Foxwell

1st Edition

007184421X, 9780071844215

More Books

Students also viewed these Databases questions

Question

What was the total sales volume for Imperial Stout in January 2020?

Answered: 1 week ago

Question

LO32.2 Explain the factors that cause changes (shifts) in AD.

Answered: 1 week ago