Ex W5 |home |print view |recent changes |changed November 8, 2018 | exact |You are 3.237.186.116 <- set your identity!

## 0 Catch Up^

Chances are high that you haven't been able to solve all exercises from last week. So first complete the remaining non-extra exercises from ExW4

## 1 A value class for Words (This will be required for next Testat!)^

### 1.1 `Word` value class^

Create a class Word that represents a single word.

• It can be input with `>>` and output with `<<` (from `std::istream` and to `std::ostream`).
• When input, a word will only consist of letters (`std::isalpha(c)`). Any other character terminates the word. You have to ignore all leading non-alpha characters, like white-space, digit or punctuation.

Example: An `std::istream` containing the sequence `"compl33tely ~ weird !!?!! 4matted in_put"` would result in six Words ("compl", "tely", "weird", "matted", "in", "put"). Each call of the input operator reads one word.

```std::istringstream input{"compl33tely ~ weird !!?!! 4matted in_put"};
Word w{};
input >> w;
//Now word contains "compl"
input >> w;
//Now word contains "tely"
input >> w;
//Now word contains "weird"
input >> w;
//Now word contains "matted"
input >> w;
//Now word contains "in"
input >> w;
//Now word contains "put"
input >> w;
//Now the stream should be in fail state and w should still contain "put"
```

• You do not accept empty words, so you continue reading until a word has at least one alphabetical character.
• When constructing a word without an argument use some valid content as default.

• You can also construct words from `std::string` but guarantee the invariant that it only consists of alphabetical characters. Subsequently, if that constructor is called with an `std::string` containing invalid characters, prevent the Word object from being constructed.

• Words are to be stored in a dictionary later, so they compare with each other IGNORING letter case. Provide the corresponding infrastructure for ALL relational operators WITHOUT using `boost::operators` library. The order has to be lexicographical.

Write CUTE unit tests for all behavior your word class shows!

Write a test that checks what happens at the end of the input with the input stream. Will an empty word be created, even if it is forbidden?

Hints:

• Here are some ideas for tests (not necessarily complete): https:files/word_tests
• Constructors callable with a single argument should be `explicit`
• Implementing `operator==` using `operator<` is inefficient for word. Use an appropriate algorithm that does the job in a single pass.
• Avoid creating a caseless intermediate representation of the word content for comparison
• You will need some means to avoid reading over the end of the word on a stream (check the `peek()` member function of `std::istream`).
• Implement all non-operator member functions in the source-file.
• Do NOT create a `getter` or `setter`

#### 1.2 `wlist` revisited using `Word` (Will not be part of the testat)^

Based on this class Word, implement the exercise wlist from last week ExW4 with this class. How does the program become simpler with your library class instead of using `std::string` (it should)?

## Extra Exercises (Optional)^

### Class Design for Retro-Calculator^

Create classes for the different functional units of last weeks' exercises with 7-segment display and calculation. Can you implement the "accumulator" that keeps the displayed value around as first operand for further computations?

Where does it make sense to combine functions as member functions into a class, and where not? Document your judgement in SolW5.

 |home |print view |recent changes |changed November 8, 2018 | exact |You are 3.237.186.116 <- set your identity! Ex W5