Exercise 5 draft

Added Exercise 5 but incomplete
This commit is contained in:
2025-03-21 23:35:38 +01:00
parent d1c3fcd614
commit 4655cd3477
4 changed files with 226 additions and 0 deletions

View File

@@ -0,0 +1,35 @@
Please write your solution here.
For your convenience we have added a template for your answers below.
Note: Remember to also describe the problem of the function.
# Function `c++|is_even`:
The problem with this function is that it does not return a bool if the number `i` is uneven.
```c++
// PRE: n/a
// POST: returns true if i is even. If not it returns false.
bool is_even(int i) {
if (i % 2 == 0) return true;
else return false;
}
```
# Function `c++|invert`:
The problem with this function is
```c++
// PRE: x is positive or negative but not zero.
// POST: returns inverse with respect to multiplication of x.
double invert(int x) {
// TODO: Fix code below.
if (x != 0) {
return 1.0 / x;
}
else
std::cout << "0 has no inverse!";
}
```