go to start Ex W10
|home |print view |recent changes |changed September 15, 2017 |
exact
|You are 54.81.88.93 <- set your identity!

Sections: Algorithm Exercises | wseventh - count words and print out 7th most frequent | woccurrence - cross reference with line numbers | Function Templates | Filling a vector with squares with standard functors | Function template median() | function template rotate3arguments() | Function readln(std::istream&,...) |

Algorithm Exercises ^

wseventh - count words and print out 7th most frequent ^

Similar to the wfavorite program from last week, only print the 7th most frequent word.

Do not reuse exact code of wfavorite, but again use the most optimal data structure and algorithms for this problem.

woccurrence - cross reference with line numbers ^

Read a text from standard input line by line. While reading count the line numbers. Create a data structure that keeps each word (use your word class) together with all line numbers it occurs upon. Print out a sorted list of words (one word per line), each followed by a list of the line numbers it occurs upon.

Example input:

Hello
Hello again
Song by who?
output:
again 2 
by 3 
Hello 1 2 
Song 3 
who 3 

Function Templates ^

Filling a vector with squares with standard functors ^

Use standard functors and the transform algorithm to fill a vector consisting of 10 ones with the 10 squares 1..100. Do not use a loop. Do not use 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 istream and reads all values from it, whereas readln just reads a line and passes that line as an istringstream to the second function.

Create useful unit tests for your function(s).


|home |print view |recent changes |changed September 15, 2017 |
exact
|You are 54.81.88.93 <- set your identity!

Ex W10
go to start