Question: You are asked to implement map, filter and reduce using C++. When we use programming to solve tasks, often, we need to deal with lists
You are asked to implement map, filter and reduce using C++. When we use programming to solve tasks, often, we need to deal with lists of stuffs. For example, databases are essentially lists of data entries and strings are basically lists of characters. map, filter and reduce allow convenient modification and aggregation of lists.




Firstly, let just look at the concept of "map". Mathematically, given a list L- [T1, T2,...,] and a function f, by mapping f onto L, we get map(f, L)f(),(2f() "map" can be applied whenever we want to apply operations to every element of the list For example, to convert a list of characters to upper cases, we just map toUpper function onto the list, where toUpper converts lower cases to upper cases. Given a list of books, if we want the corresponding list of authors, we just map getAuthor function onto the list, where getAuthor (book) returns the correct author. Given a list of game units, if we want to heal them all (e.g., a Mage casted an area of effect (AOE) healing ability), then we just map heal onto the list of game units Now let us get back to C++. For simplicity, for this assignment, we only consider lists where the elements are integers, and we only consider functions that map integers to in Your implementation should at the very least provide the following functionalities every value tripled Given a list of integers, the resulting list has That is, [x1, x2, ^n becomes 3r1,3r2, ...3 Given a list of integers, the resulting list has every value raised to the power of 2 That is, [x1,T2, ,Tn] becomes [13.13. Given a list of integers, the resulting list has every member become the absolute value. That is, ri, r2.n] becomes [il, r2, n In your implementation, you are required to use C++ standard vector for storing the lists. One possi ible way to implement the above functionalities is as follows We can create a base class with name MapGeneric, which has a private method int f(int) that specifies the operation we want to map onto a list. This method is overridden later in the derived classes to deliver specific map operations. The function f can be declared to be pure virtual (which means that you will not include a definition for this function in the base class, and the base class can not be instantiated) The MapGeneric class also has a public method vector
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
