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.
- function is_even:
bool is_even(int i) {
if (i % 2 == 0) return true;
}
- 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.