/// @file /// @brief task A: Class Vector #pragma once #include // std::function #include // std::cout, std::endl #include // std::vector /// @todo implement a class 'Vector' according to the following specification: /// - use a *private* member variable of type std::vector /// - provide 3 constructors: /// 1. passing a std::vector /// - the values will be copied over to the private member /// 2. passing a count 'N' and an interval specified by a 'start', and 'end' value /// - fill the private member with 'N' equidistant samples from the interval /// 3. passing a count 'N' and a generator function in form of a callable std::function /// - fill the private member with 'N' samples obtained from the generator/callable /// - member function print(): /// - prints all elements in the private member to the console class Vector { std::vector data_; public: Vector(std::vector data) : data_(data) {} Vector(double start, double end, unsigned int N) { double step = (end - start) / (N - 1); for (unsigned int i = 0; i < N; ++i) { data_.push_back(start + i * step); } } Vector(unsigned int N, std::function generator) { for (unsigned int i = 0; i < N; ++i) { data_.push_back(generator()); } } void print() { std::cout << "["; for (unsigned int i = 0; i < data_.size(); ++i) { std::cout << data_[i]; if (i < data_.size() - 1) { std::cout << ", "; } } std::cout << "]" << std::endl; } };