go to start Ex W1
|home |print view |recent changes |changed February 25, 2018 |
exact
|You are 54.92.160.119 <- set your identity!

Sections: Set up your environment | Compiler | Ctylechecker & Constificator & update Cevelop to 1.9 | Easy C++ Repetition Tasks | Fraction Type | =[dynArray]= Repetition (Optional) |

Set up your environment ^

If you don't already have a development environment with Cevelop and a recent compiler (at least GCC 7.2.x) take care of this first. Here is a guide from CPl on how to do it: https://wiki.ifs.hsr.ch/CPlusPlus/ExW1

It might be likely that need newer (gcc 7.3/clang 5) compilers later on in the module. Details about the specific version will be supplied then.

Compiler ^

Ctylechecker & Constificator & update Cevelop to 1.9 ^

You need to update your Cevelop installation for the 1.9 release and If you don't have already done that install the Ctylechecker plug-in into your Cevelop IDE.

Again, it might be that we ask you to update Cevelop or install an additional beta-plug-in(-version) during the semester for specific exercises.

Import one of your exercise solutions from the C++ module and check it for problems reported by Ctylechecker or Constificator. Are the reports reasonable?

If you find any errors in the plug-ins let me know. We might be able to fix them!

Easy C++ Repetition Tasks ^

For the following tasks write test cases first!

  1. Create a function that takes an int as parameter and returns the next value (increment).
  2. Add an overload of increment that modifies the parameter as side-effect. Do you encounter any problems when calling increment in the presence of both overloads? Stick with the side-effect version for the following exercises.
  3. For signed integers overflow is undefined behavior in C++. Make your function safe. If such an overflow would happen throw an exception instead of incrementing the value (std::overflow_error).
  4. Change your increment to accept parameters of arbitrary type and increments them - given they support the prefix increment operator and std::numeric_limits provides a corresponding maximum value. Start your test cases with double.
  5. Overflow for unsigned is well defined. Add an overload for this case that does not throw. Does it need to be a template specialization?
  6. Several overloads are required to cover all cases of unsigned type (i.e. unsigned, unsigned long) because the template has an exact match for the overload resolution unless you provide an overload for the specific type. Example: If you provide the overload for unsigned long long and call increment with an unsigned variable as argument the template will be chosen instead of the unsigned long long overload. Therefore, try an alternative approach to tackle overflows. Create a predicate (as template) allow_overload that returns false by default but can and should be specialized for unsigned types to be true. You can implement the predicate as variable, class or function template for that matter.
  7. With all the template specializations for the different unsigned types there is still much code, at least it avoids duplication in the logic. As usual, the standard library can help. Have a look at std::numeric_limits::is_integer and the is_unsigned type trait. Can you implement your predicate with those?
  8. Can you also pass an iterator to your increment function? You might experience different outcomes depending on your compiler. It might not be happy if you want to get numeric_limits for your iterator. Adapt your increment function to also have the capability to take a second parameter to have a user-provided limit. Your previous tests should still remain working. Therefore, add a default argument to that parameter. You probably used comparisons and a - 1 operation to your limit. Does this restrict the iterators you can use with increment?

Fraction Type ^

Implement your own Fraction type that can represent fraction numbers more precisely than the double type.

dynArray Repetition (Optional) ^

At the end of the C++ module you had an assignment in the exercises to create a vector-like container that features the capabilities to access its elements with negative indices (https://wiki.ifs.hsr.ch/CPlusPlus/ExW12). In the C++ Advanced module we will have an in-depth look at the implementation of bounded buffer container. We will expect that you are familiar and can easily implement containers like the dynArray example. Revisit the implementation of this task, implement it again or study the code carefully, in order to be properly prepared for the upcomming testat assignments.


|home |print view |recent changes |changed February 25, 2018 |
exact
|You are 54.92.160.119 <- set your identity!

Ex W1
go to start