Exercise 5 & updated README
Added Exercise 5 and translated README and added signature as well as disclaimer
This commit is contained in:
28
Informatik_I/Exercise_5/Task_3/README.md
Normal file
28
Informatik_I/Exercise_5/Task_3/README.md
Normal file
@@ -0,0 +1,28 @@
|
||||
_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-](https://en.wikipedia.org/wiki/Precondition) and [postconditions](https://en.wikipedia.org/wiki/Postcondition).
|
||||
|
||||
1. function is_even:
|
||||
|
||||
```cpp
|
||||
|
||||
bool is_even(int i) {
|
||||
if (i % 2 == 0) return true;
|
||||
}
|
||||
```
|
||||
|
||||
1. function invert:
|
||||
|
||||
```cpp
|
||||
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](https://lec.inf.ethz.ch/ifmp/2023/guides/tracing/intro.html) 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.
|
Reference in New Issue
Block a user