Commit 575314b6 authored by Praetorius, Simon's avatar Praetorius, Simon
Browse files

Presentation updated and dates removed in exercises

parent 0dbc2649
# Exercise sheet 1 - 2019/10/16
# Exercise sheet 1
## Exercise 0 (Introduction to Linux command line)
This exercise serves as introduction to the Linux command line. If your are not yet familiar with
......@@ -86,16 +86,16 @@ and "Todos" tabs, and the "Wiki" tab. If and how you use these features is up to
- [Git reference](https://www.git-scm.com/docs)
- [cheat sheet](https://github.github.com/training-kit/downloads/github-git-cheat-sheet.pdf)
## Exercise 2 (Compiling code) :pencil2:
## Exercise 2 (Compiling code)
In the directory [material/sheet1/](/exercises/material/sheet1) you can find
an initial C++ example in the files `linear_algebra.cc`, `linear_algebra.h`, and `exercise2.cc`. Download the files and compile the code:
```bash
g++-7 -std=c++14 -Wall -O2 -c linear_algebra.cc
g++-7 -std=c++14 -Wall -O2 -c exercise2.cc
g++-7 -o exercise2 linear_algebra.o exercise2.o
c++ -std=c++14 -Wall -O2 -c linear_algebra.cc
c++ -std=c++14 -Wall -O2 -c exercise2.cc
c++ -o exercise2 linear_algebra.o exercise2.o
```
This creates a new file `exercise2` in the current directory. You can now run the example by
......@@ -111,14 +111,12 @@ What is the effect? What is the minimal necessary set of options to pass?
Document the output, results, and findings, write it into a file `solution.txt` or `solution.md` and commit into your repository. Follow the
instructions given in the [README.md](/README.md) of this repository.
**>> Submit solution until 2019/10/30 ... (5 Points)**
### Resources
You can find a documentation of the compiler arguments on
- [GCC manual](https://gcc.gnu.org/onlinedocs/gcc-7.2.0/gcc/)
## Exercise 3 (Basic debugging) :pencil2:
## Exercise 3 (Basic debugging)
In the [material/sheet1/](/exercises/material/sheet1) directory, you can
find a second exercise code for this exercise sheet, i.e. the file `exercise3.cc`.
......@@ -150,8 +148,6 @@ or the current instance of the class (e.g. `*this`).
Use GDB to locate, find, and correct the bugs in the provided source code. Document
which bugs you have found and how.
**>> Submit solution until 2019/10/30 ... (5 Points)**
### Resources
- [GDB Documentation](https://www.gnu.org/software/gdb/documentation/)
- Cheat Sheets: [darkdust.net](https://darkdust.net/files/GDB%20Cheat%20Sheet.pdf),
......
# Exercise sheet 10 - 2020/01/08
# Exercise sheet 10
## Exercise 1 (Standard Containers)
The C++ standard library provides implementations of several common data-structures: vector, list, deques, queues,...
......@@ -135,7 +135,7 @@ int main()
```
## Exercise 4 (External Libraries):pencil2:
## Exercise 4 (External Libraries)
We have implemented our own matrix and vector classes in the last exercises. For most of the
data-structures there is an efficient implementation already available. Especially for linear
algebra containers and algorithms there exist a large variety of libraries, all with a different focus
......@@ -157,5 +157,3 @@ We want to explore some of the external libraries in this exercise. The task is
- [Eigen3](http://eigen.tuxfamily.org)
- [Blaze](https://bitbucket.org/blaze-lib/blaze)
- [Armadillo](http://arma.sourceforge.net)
**>> Submit solution until 2020/01/22 ... (10 Points)**
# Exercise sheet 11 - 2020/01/15
# Exercise sheet 11
## Exercise 1 (Function templates)
1. Write a function template `minmax(a,b)` to calculate minimum and maximum of two values `a` and
......@@ -82,7 +82,7 @@ again! What is the output of the program and why? Use the tools `nm` or `objdump
and expected symbols in the files.
## Exercise 3 (Class Templates) :pencil2:
## Exercise 3 (Class Templates)
Choose one of the three classes from the last exercises (`Rational`, `Matrix`, or `Polynomial`) and transform it into a
class template, i.e.
```c++
......@@ -116,10 +116,6 @@ class Rational
`Matrix<Rational>` a matrix with rational coefficients, or `Polynomial<double,Matrix>` a matrix polynomial. What
functionality is missing in the template types and can you easily correct/extend it? Run the test suite on those types!
**>> Submit solution until 2020/01/29 ... (10 Points)**
#### Note
- The full correction/extension in step 3 might be a complicated task. This is optional!
Just identity the missing functions, maybe implement it with a placeholder function or an error message so that at least the code
......
# Exercise sheet 12 - 2020/01/22
# Exercise sheet 12
## Exercise 1 (Functors)
Write a functor `Scale` that multiplies an assigned value with a constant factor. This constant factor
......
# Exercise sheet 13 - 2020/01/28
# Exercise sheet 13
## Exercise 1 (Iterators)
Given the following for statement:
......
# Exercise sheet 14 - 2020/02/05
# Exercise sheet 14
There is no new exercise sheet. Please discuss and solve unfinished exercises from the older sheets.
# Exercise sheet 2 - 2019/10/23
# Exercise sheet 2
## Exercise 1 (Floating-point numbers)
......@@ -92,7 +92,7 @@ while a positive integer is read from the keyboard. Use the standard stream oper
- [std::cout](https://en.cppreference.com/w/cpp/io/cout), [std::cin](https://en.cppreference.com/w/cpp/io/cin)
## Exercise 4 (Kahan Summation Formula) :pencil2:
## Exercise 4 (Kahan Summation Formula)
Calculate the sum $`\sum_{j=0}^{N-1} x_j`$ for a given set of values $`\{x_j\}`$ using the following algorithm:
```
S = x_0
......@@ -132,9 +132,6 @@ std::srand(12345); // fixed initial seed
std::random_shuffle(x.begin(), x.end(), [](int n) { return std::rand() % n; });
```
**>> Submit solution until 2019/11/06 ... (10 Points)**
### Note
For a comparison of the computations, print the value with maximal precision to `std::cout`, i.e.
```c++
......
# Exercise sheet 3 - 2019/10/30
# Exercise sheet 3
## Exercise 1 (Literals)
What is the type of the following literals
......@@ -58,7 +58,7 @@ First, try to evaluate by hand, then check your results by implementing the expr
## Exercise 4 (Recursion) :pencil2:
## Exercise 4 (Recursion)
To calculate the square-root of a real number $`a > 0`$ you can use the Newton-method, by getting the root (zero-point) of the function $`f(x)`$,
defined by:
```math
......@@ -89,8 +89,6 @@ Try your code with a recursion depth of $`N=5, 10, 100`$ for $`a=10`$ and initia
How to check the error you have made? How to choose the initial value `x0` and the iteration count `N`? How would you design your implementation
`double sqrt(double a)` of a square-root function and which version of the implementation above would you choose?
**>> Submit solution until 2019/11/13 ... (10 Points)**
### Notes and additional questions:
- You can use the `std::sqrt` function from `<cmath>` as a comparison.
- (optional) Measure the time of your implementation and compare it against the time of the `std::sqrt` implementation. Therefore, either use the `Timer`
......
# Exercise sheet 4 - 2019/11/06
# Exercise sheet 4
## Exercise 1 (Work with references and constants)
*References* are aliases to existing objects or functions. In contrast to pointers, references are
......@@ -74,7 +74,7 @@ In `material/sheet4/exercise3.cc` you can find a horribly complicated unreadable
## Exercise 4 (Rational numbers) :pencil2:
## Exercise 4 (Rational numbers)
Write a class for rational numbers. The number should always be represented as *fully reduced fraction* of the form
```math
\frac{\text{numerator}}{\text{denominator}}
......@@ -106,8 +106,6 @@ with $`\text{denominator} > 0`$.
\frac{13}{12},\; -\frac{1}{3},\; \frac{16}{3},\; \frac{19}{3},\; -\frac{3}{1},\; -\frac{3}{2},\; -\frac{3}{16}.
```
**>> Submit solution until 2019/11/27 ... (10 Points)**
### Resources
- [GCD](https://en.wikipedia.org/wiki/Greatest_common_divisor)
......
# Exercise sheet 5 - 2019/11/13
# Exercise sheet 5
## Exercise 1
What is the error (if any) in the following function definitions?
......
# Exercise sheet 6 - 2019/11/27
# Exercise sheet 6
## Exercise 1
In the following there are various overloads of `foo(.)` and `bar(.,.)` provided. Which of the function is called in the
......@@ -72,7 +72,7 @@ class Pair {
```
## Exercise 3 :pencil2:
## Exercise 3
For a better structuring of your code, it is recommended to separate declaration and definition. Apply this
splitting to the code from exercise 2 or 3 of exercise sheet 5 (the `Matrix` class). Therefore, move the function
declarations and class definition to a header file (file ending `.hh` or `.hpp`) and the definition / implementation
......@@ -136,8 +136,6 @@ next test? In your `main()` call each test and throw an error if the test failed
Look up in the web how to throw and handle exceptions and replace assertions by proper throw statements. Now,
you can even test that a function produces the right error in case of wrong input. So, test the error handling!
**>> Submit solution until 2019/12/11 ... (10 Points)**
## Exercise 4 (GotW-1: Variable initialization -- or is it?)
See [GotW #1](https://herbsutter.com/2013/05/09/gotw-1-solution/).
......
# Exercise sheet 7 - 2019/12/04
# Exercise sheet 7
## Exercise 1 (Pointers)
Let `i` have the type `int`, and `p` the type `int *`.
......@@ -39,7 +39,7 @@ int main()
```
## Exercise 3 (Polynomials) :pencil2:
## Exercise 3 (Polynomials)
This exercise is about a user-defined type representing polynomials
```math
P(x) = a_0 + a_1 x + a_2 x^2 + \ldots + a_n x^n\quad (n \geq 0)
......@@ -72,8 +72,6 @@ Test your polynomial arithmetic on some reference polynomials:
- Polynomials with just one coefficient unequal to zero
- All coefficients = 1
**>> Submit solution until 2019/12/18 ... (10 Points)**
### Hint:
- Implement an overload for the function `operator<<` for your type:
```c++
......
# Exercise sheet 8 - 2019/12/11
# Exercise sheet 8
## Exercise 1 (Valgrind)
1. Create a small program that creates arrays on the heap (using dynamic allocation). Therefore, write a function `int allocate(int n)`
......@@ -128,8 +128,6 @@ get a compiler error.Read the code and understand the requirements on the types.
[Makefile cheatsheet](https://devhints.io/makefile),
[Makefile conventions and guidelines](https://eigenstate.org/notes/makefiles)
**>> Submit solution until 2020/01/08 ... (20 Points)**
## Exercise 4 (GotW-89: Smart Pointers)
See [GotW #89](https://herbsutter.com/2013/05/29/gotw-89-solution-smart-pointers).
......
# Exercise sheet 9 - 2019/12/17
# Exercise sheet 9
## Exercise 1 (Vector class)
In the following vector class and main function there are more than 25 programming
......
......@@ -561,15 +561,20 @@ The placeholder `auto` may be accompanied by modifiers, such as `const` or `&`,
```c++
auto x = 3+4; // deduce the type from the expression: x <-- int <-- 3+4
auto y = long{3+4}; // explicitly committing to a type: y <-- long
auto z{3+4}; // same as variable x: z <-- int [C++17]
auto const z2 = 3+4; // type of x3 is 'int const'
auto z{3+4}; // same as variable x: z <-- int [C++17]
auto z1 = {3.4}; // ATTENTION: This gives 'std::initializer_list<int>' [C++17]
auto const z2 = 3+4; // type of z2 is 'int const'
decltype(auto) x2 = x; // type of x2 is 'int&'
decltype(x) x3 = x; // extract the type from the expression 'x'
auto& x4 = x; // type of x3 is 'int&'
auto& x4 = x; // type of x4 is 'int&'
```
> .h3[Almost-Always-Auto:] Preferring auto variables is motivated primarily by *correctness*,
> *performance*, *maintainability*, and *robustness* - and only lastly about typing convenience.
> (Herb Sutter, [GotW #94](https://herbsutter.com/2013/08/12/gotw-94-solution-aaa-style-almost-always-auto/))
---
# Variables and Datatypes
......@@ -581,7 +586,7 @@ usage *requirements* and not explicit datatypes. Requires **C++20**.
<type-constraint> decltype(auto) <variable name> = <expression>;
```
### Example:
### Examples:
```c++
std::integral auto x{3+4}; // Ok, deduces the type from expr 3+4 -> int,
// must be integral type
......
#include <concepts>
#include <vector>
std::vector<double> foo() { return {1.0,2.0,3.0}; }
int main()
{
std::vector v = foo();
}
\ No newline at end of file
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment