|home |print view |recent changes |changed April 18, 2017 | |You are 18.104.22.168 <- set your identity!
In many of the exercises in the CPlusPlus module you had to process input line by line. It would have been convenient to have a line iterator in order to use standard algorithms instead of the
while loops used:
You can use boost to simplify your solution.
In this first exercise you will implement a simple iterator similar to the iterator for integers from the lecture.
Instead of just counting your iterator will iterate through the Fibonacci numbers (https://en.wikipedia.org/wiki/Fibonacci_number). The given test cases expect your Fibonacci sequence to start with the value
0 for the zeroth number,
1 for the first number,
1 for the second number, and so on.
You need to implement the following members of the Fibonacci iterator:
nth element (default is
operator*for accessing the current element (Fibonacci number) of the iterator.
operator==to see whether two iterators have the same current element.
operator!=the inverse of the
operator++prefix and postfix increment.
We suggest you store the index (
ith number) and not the Fibonacci value itself.
Here are the test cases: https:files/Test.cpp
You shall implement two versions of this iterator:
Note: Don't worry about efficiency in this exercise.
Note: The task of this exercise will be part of Testat 2 (next week). Last week you have implemented a dynamic version of the bounded buffer. Finish that exercise first if you have not already completed it.
In this exercise you have to implement
end for your dynamic bounded buffer. This requires your own iterator type, which can cope with the non-consecutive nature of the elements in your heap memory. The implementation of your iterator must be robust, i.e. accesses outside the range specified by
begin (inclusive) and
end (exclusive) have to throw exceptions. It is not allowed to increment/decrement your iterator beyond these points (
Here are some test cases as suggestion to verify the functionality of your iterators. Note: It is just the suite for iterators, which you need to register in the
Test.cpp file first:
If you struggle to get it all up and running at once, try to satisfy one test case after another. Comment out all test contents first. Add the contents of the first test (start at the top of the tests), make it compile, make it green, repeat with the next tests.
Create a version of the bounded buffer that supports non-const iterators. Don’t just copy-waste your const iterator implementation! Try to find a smart way to reuse the parts of your implementation and let the compiler do the work of duplicating your code.
Due date: Thursday 13. April 2017 23:59 (CET)
Adapt your dynamic bounded buffer to allow non-default-constructible types as element type. Use the approach you have seen in the lecture last week (allocating a
char array and move the elements to the corresponding location).
|home |print view |recent changes |changed April 18, 2017 |
|You are 22.214.171.124
<- set your identity!