go to start Ex W11
|home |print view |recent changes |changed December 1, 2017 |
exact
|You are 54.158.15.97 <- set your identity!

Sections: Function Templates | Filling a vector with squares with standard functors | Function template median() | function template rotate3arguments() | Function readln(std::istream&,...) |

Function Templates ^

Filling a vector with squares with standard functors ^

Use standard functors and the std::transform algorithm to fill an std::vector consisting of 10 ones with the 10 squares 1, 4, ..100. Do not use a loop. Do not use std::iota(). Do not use a lambda. Start with the following vector:

    std::vector<unsigned> v(10,1);

Function template median() ^

Write a template function median(a,b,c) taking three arguments of the same type and returning the one in the middle, i.e., neither min/max.

Provide useful unit tests for your function.

You can implement the function in a header file within your CUTE test project.

function template rotate3arguments() ^

Write a template function rotate3arguments taking three variables of the same type as arguments and exchanging the values, so that a obtains the value of b, b of c, and c of a.

Provide useful unit tests for your function.

You can implement the function in a header file within your CUTE test project.

Function readln(std::istream&,...) ^

Write a variadic function template readln(std::istream&,...) that takes a variable number of reference arguments and uses operator>> to read in successive values from a line read from the std::istream.

Tip: you might need to create a second function that takes an std::istream and reads all values from it, whereas readln just reads a line and passes that line as an std::istringstream to the second function.

Create useful unit tests for your function(s).


|home |print view |recent changes |changed December 1, 2017 |
exact
|You are 54.158.15.97 <- set your identity!

Ex W11
go to start