go to start Ex W9
|home |print view |recent changes |changed November 15, 2018 |
exact
|You are 18.205.19.203 <- set your identity!

Sections: Algorithms Continued | Word Statistics | Functor Exercises | =[wlist]= AGAIN! | Filling a vector with squares with standard functors | Function Templates | Function template median() | function template rotate3arguments() | Function readln(std::istream&,...) | Optional | Prime Numbers | Containers | woccurrence - cross reference with line numbers | Wordle visual word cloud Statistics |

To speed-up your progress in the C++ exercises and to allow you working more focussed on the implementation instead of setting up Cevelop projects, we have preprared a github repository with scaffolding for this weeks exercises.

The following projects are available:

In order to get those projects you have to clone the following git repository, either within Cevelop (Git Perspective) or with your own git client: https://github.com/PeterSommerlad/CPlusPlusLecture/

The projects are located in the subdirectory exws09 and exws10 You can import them if you don't already have projects with the same name in your workspace:

Note: If you encounter the problem that an imported project cannot be compiled due to missing make...

Algorithms Continued ^

Word Statistics ^

Use your class word from ExW5 and use it to create the following simple programs that provide the following results. Remember: your word class ignores case when compared and also ignores punctuation and white space. Empty words are not allowed! Don't program your own loops. Use appropriate data structures but don't store data unnecessarily.

Functor Exercises ^

wlist AGAIN! ^

You have already implemented the wlist programm twice (once with std::string (Ex4) and once with your word (Ex5)). The implementation using word should be rather short, only a few lines. Until now your wlist output contained the words in ascending order, from a to z. Modify the existing behavior in the following ways and create two new versions of wlist:

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

Templates available in exws11.

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

Optional ^

Prime Numbers ^

Write a program primes that outputs prime numbers. Create a predicate function isPrime(int). Use that predicate to filter a vector filled with numbers from 1 to 100. Don't write your own loops but use the most fitting algorithms from the standard library (i.e., don't use for_each() with a lambda, when there exists a better algorithm.) Can there be a solution for where even isPrime() is not using a hand-written loop?

variants of your program:

Containers ^

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 

Wordle visual word cloud Statistics ^

Write a program wordle (or derive it from wfavorite) that reads a text from standard input and produces as its output the input for the advanced version of wordle ( http://www.wordle.net/advanced )

Can you suppress fill words like "and", "the", "a" or similar german words that do not add to the meaning of a text. Take a current newspaper article or something to like as input to your program and produce a wordle from it with your program. Compare your wordle to the wordle generated by wordle.net's basic version.

Stop words list
Files with a list of so called stop words for the english and german language, as provided by postgres (/usr/share/postgresql/tsearch_data), are attached below.

Hint
Convert the list to initializer list style using the following commands in the VM or unix:
cat german.stop | tr '\n' ' '| sed -r 's|([a-z]+)|"\1",|g'


|home |print view |recent changes |changed November 15, 2018 |
exact
|You are 18.205.19.203 <- set your identity!

Ex W9
go to start