go to start Ex W5
|home |print view |recent changes |changed October 18, 2017 |
exact
|You are 54.81.139.56 <- set your identity!

Sections: 0 Catch Up | 1 A value class for Words (This will be required for next Testat!) | 1.1 =[Word]= value class | 1.2 =[wlist]= revisited using =[Word]= | Extra Exercises (Optional) | Class Design for Retro-Calculator |

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 white-space, digit or punctuation characters.

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"

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?

Hint: Here are some ideas for tests (not necessarily complete): https:files/word_tests

1.2 wlist revisited using Word ^

Based on this class Word, implement the exercise wlist from last week ExW4 with this class. 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 October 18, 2017 |
exact
|You are 54.81.139.56 <- set your identity!

Ex W5
go to start