JirR02 8719f4c140 Exercise 5 & updated README
Added Exercise 5 and translated README and added signature as well as
disclaimer
2025-03-22 13:19:34 +01:00
..
2025-03-21 23:35:38 +01:00
2025-03-22 13:19:34 +01:00

This task is a text based task. You do not need to write any program/C++ file: the answer should be written in main.md (and might include code fragments if questions ask for them).

Task:

What are the problems (if any) with the following functions? Fix them and find appropriate pre- and postconditions.

  1. function is_even:

bool is_even(int i) {
    if (i % 2 == 0) return true;
}
  1. function invert:
double invert(int x) {
    double result;
    if (x != 0) {
        result = 1.0 / x;
    }
    return result;
}

Hint: The C++ compiler does not protect you from certain types of errors. Therefore, even if you run a program in Code Expert, it is not guaranteed that the behaviour you observe is the “real” one. We have prepared a program tracing handout that shows how to execute a program with a pen and paper and which conditions indicate bugs in the executed program not caught by the C++ compiler.