diff --git a/Makefile b/Makefile index 68c7a04..8058fac 100644 --- a/Makefile +++ b/Makefile @@ -11,6 +11,11 @@ sheet01: chmod +x build/sheet01 build/sheet01 +sheet02: + g++ src/sheet02.cpp -o ./build/sheet02 + chmod +x build/sheet02 + build/sheet02 + pizza: g++ src/pizza.cpp -o ./build/pizza chmod +x build/pizza diff --git a/src/sheet02.cpp b/src/sheet02.cpp index 449fa77..f05cb33 100644 --- a/src/sheet02.cpp +++ b/src/sheet02.cpp @@ -1,17 +1,71 @@ #include -#include +//#include #include +#include + +double euclidean_length(const std::vector &v); +double scalar_product(const std::vector &v, const std::vector &w); +std::vector normalize(const std::vector &v); +double euclidean_distance(const std::vector &v, const std::vector &w); + +void print_dvector(const std::vector &v); + int main() { - int selection; - std::cout << ""; - std::cout << "Please select an Exercise: "; - std::cin >> selection; + std::vector a = {1, 2, 3}; + std::vector b = {4, 5, 6}; + std::cout << "length of 'a': " << euclidean_length(a) << '\n'; + std::cout << "scalar product of 'a' and 'b': " << scalar_product(a, b) << '\n'; + print_dvector(normalize(a)); + std::cout << "distance between 'a' and 'b': " << euclidean_distance(a, b) << '\n'; +} - switch(selection) - { - case 1: - break; +void print_dvector(const std::vector &v) { + for (const double &d : v) { + std::cout << d << '\n'; } + std::cout << '\n'; +} +double euclidean_length(const std::vector &v) +{ + double sum = 0; + for(int i=0; i &v, const std::vector &w) +{ + double product = 0; + if(v.size()!=w.size()) { return std::nan(""); } + for(int i=0; i normalize(const std::vector &v) +{ + double length = euclidean_length(v); + std::vector norm; + for(int i=0; i &v, const std::vector &w) +{ + if(v.size()!=w.size()) { return std::nan(""); } + double distance = 0; + for(int i=0; i