From f2a04aba27a2a26d6216868b1c8a1f4589dc8dc5 Mon Sep 17 00:00:00 2001 From: Isabell Pflug Date: Thu, 11 May 2023 22:30:37 +0200 Subject: [PATCH] :sparkles: Finished assignment 4.1 --- assignments/04/04_1.cpp | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 assignments/04/04_1.cpp diff --git a/assignments/04/04_1.cpp b/assignments/04/04_1.cpp new file mode 100644 index 0000000..197959e --- /dev/null +++ b/assignments/04/04_1.cpp @@ -0,0 +1,37 @@ +#include +#include +#include "ExtendedVector.hpp" + +using namespace std; + +const vector vec1 = {1, 2, 3, 4, 5}; +const vector vec2 = {5, 4, 3, 2, 1}; + +// pretty vector printing +ostream& operator<<(ostream& os, + const vector& v) { + os << "< "; + for (auto it = v.begin(); it != v.end()-1; ++it) { + os << *it << ", "; + } + os << *v.end() << " > "; + return os; +} + +int main() { + cout << "Max vec1: " << ExtendedVector::max(vec1) << endl; + cout << "Max vec2: " << ExtendedVector::max(vec2) << endl; + + cout << "Beide Vektoren sind jeweils ausschließlich positiven Werten gefüllt: " << (ExtendedVector::allPositive(vec1) && ExtendedVector::allPositive(vec2)) << endl; + + cout << "Skalarprodukt vec1 x vec2: " << ExtendedVector::product(vec1, vec2) << endl; + cout << "vec1 * 5: " << ExtendedVector::product(vec1, 5) << endl; + cout << "Norm von vec1: " << ExtendedVector::norm(vec1) << endl; + + vector vec_copy; + copy(vec1.begin(), vec1.end(), back_inserter(vec_copy)); + ExtendedVector::normalise(vec_copy); + + cout << "Normalisierung von vec1: " << vec_copy << endl; + return 0; +}