|home |print view |recent changes |changed April 11, 2018 | |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.
Due date: Tuesday 1. May 2018 23:59 (CEST)
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 (
Create constant and non-constant iterators. Const iterators provide read-only access to the elements, while the non-const iterators allow changing the elements through the iterator. 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.
const_iteratorand one for non-const
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.
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
std::byte[size] array and use placement new to move/copy the elements to the corresponding location).
Make sure that elements in the buffer get destructed exactly once (no undestroyed elements and no double deletes)!
Since you do not allocate arrays of the element type anymore the test cases for
delete change, i.e. those operators of the element type are not used anymore. The
bounded_buffer_heap_memory_suite has been adapted accordingly.
Here are the test cases: https:files/NonDefaultConstructibleTypeTests.zip
std::unique_ptr). For accessing the elements in the memory, it is convenient to have a means for converting this
std::bytepointer to a pointer to element type, e.g., by taking the address of the front() element.
|home |print view |recent changes |changed April 11, 2018 |
|You are 22.214.171.124
<- set your identity!