|home |print view |recent changes |changed November 22, 2016 | |You are 126.96.36.199 <- set your identity!
if you haven't done so by now!
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
Create a class Word that represents a single word. It can be input with >> and output with <<. When input, a word will only consist of letters (std::isalpha(c)) and ignore all white-space, digit or punctuation characters. All the latter terminate a word. Thus, 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::stringbut guarantee the invariant that it only consists of alphabetical characters. Subsequently, if that constructor is called with an
std::stringcontaining invalid characters, prevent the Word object from being constructed.
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?
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)?
The class Date from the lecture examples (chose one you like to start with) is confusing to use, because we specify day, month and year as numbers. Change/implement a Date class that uses an enum type for month consistently, so that one can not specify a wrong date as easily.
Implement a member function day_of_week() for your date class that calculates if a given date is Monday, Tuesday etc. Define a corresponding enum type within the Date class.
Consult wikipedia to figure out how to calculate the day of the week with your calendar. Note, that we only support Gregorian dates.
Maybe another internal representation than 3 numbers for day-month-year, like the number of days since the start of your calendar makes it easier to implement this feature. Even though this might require change to other member functions, but your test cases should help you keep those working. Try also to implement this more compact date representation.
To exercise an enum type with hidden values we implement a class Switch. The Switch simulates three states: off, on, blinking. It comes with a single button simulated with the member function pressButton() that switches from off to on to blinking and then to off again. Do not expose the enum values in your Switch.h file.
Optional: If you have implemented the ANSI Terminal from ExW4 you can use it implement a visualization. To put the output of the Switch's effects on the screen of a terminal, place a cursor top-left and output the status in white on black for off, black on white for on and blinking for blinking using the corresponding ANSI escape sequences.
As we are going to use Boost in the upcoming exercises, it is now time to install it if you do not have it.
$ sudo apt-get install libboost-all-dev
$ brew install boost
|home |print view |recent changes |changed November 22, 2016 |
|You are 188.8.131.52
<- set your identity!