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

Sections: Line Iterator | Fibonacci Iterator | Iterator for Dynamic Bounded Buffer | Extra – Non-const Iterator for Dynamic Bounded Buffer: | Extra – Non-Default-Constructible Elements ('''Testat 2''' specific exercise description (and maybe unit tests) will follow next week): |

Line Iterator ^

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.

Fibonacci Iterator ^

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:

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:

  1. Implement all operators yourself.
  2. Use the facilities of boost iterators (i.e. based on a counting iterator).

Note: Don't worry about efficiency in this exercise.

Iterator for Dynamic Bounded Buffer ^

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 begin and 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 (begin/end).

Hints:

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:

https:files/ConstIteratorForBoundedBuffer.zip

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.

Extra – Non-const Iterator for Dynamic Bounded Buffer: ^

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.

Extra – Non-Default-Constructible Elements (Testat 2 specific exercise description (and maybe unit tests) will follow next week): ^

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 |
exact
|You are 54.81.139.56 <- set your identity!

Ex W6
go to start