From 694b3e5c680d70e7b75d0a5597b28971d55db014 Mon Sep 17 00:00:00 2001 From: Ignacio Labarca Figueroa Date: Wed, 30 Sep 2020 23:25:52 +0200 Subject: [PATCH] Feedback Ex.2 --- exercises/ex02/my_solutions2/arrays/arrays.cpp | 13 ++++++++++--- .../ex02/my_solutions2/simpson/integration.cpp | 7 ++++++- .../ex02/my_solutions2/simpson/integration.hpp | 6 +++++- 3 files changed, 21 insertions(+), 5 deletions(-) diff --git a/exercises/ex02/my_solutions2/arrays/arrays.cpp b/exercises/ex02/my_solutions2/arrays/arrays.cpp index c27926b..9388744 100644 --- a/exercises/ex02/my_solutions2/arrays/arrays.cpp +++ b/exercises/ex02/my_solutions2/arrays/arrays.cpp @@ -1,6 +1,13 @@ #include #include +/* Ignacio: + Looks good! Well done :) + + For the static approach: + Consider the case n > n_max +*/ + int main() { int n_max = 10; @@ -36,14 +43,14 @@ int main() { std::cout << "Dynamic approach\n"; std::vector vect; double result = 0; - + for(unsigned int i = 0; i < n; i++) { double value; std::cin >> value; vect.push_back(value); result += value; } - + // normalization for (unsigned int i = 0; i < n; i++) { vect[i] /= result; @@ -56,4 +63,4 @@ int main() { std::cout << "\n"; return 0; -} \ No newline at end of file +} diff --git a/exercises/ex02/my_solutions2/simpson/integration.cpp b/exercises/ex02/my_solutions2/simpson/integration.cpp index f727c81..b59e9fa 100644 --- a/exercises/ex02/my_solutions2/simpson/integration.cpp +++ b/exercises/ex02/my_solutions2/simpson/integration.cpp @@ -3,6 +3,12 @@ #include #define _USE_MATH_DEFINES +/* Ignacio: + Did you test your Simpson rule? + It seems that something is wrong when N is odd. +*/ + + double integration(double a, double b, int N, double (*my_func)(double x)) { assert(N>0); assert(b > a); @@ -20,4 +26,3 @@ double integration(double a, double b, int N, double (*my_func)(double x)) { result += my_func(b); return result*delta/3.0; } - diff --git a/exercises/ex02/my_solutions2/simpson/integration.hpp b/exercises/ex02/my_solutions2/simpson/integration.hpp index 3254cba..c2853a7 100644 --- a/exercises/ex02/my_solutions2/simpson/integration.hpp +++ b/exercises/ex02/my_solutions2/simpson/integration.hpp @@ -1,4 +1,8 @@ +/* Ignacio: + Use const when it is possible! + All of the arguments should be of this type +*/ double integration(double a, double b, int N, double (*my_func)(double x)); @@ -10,4 +14,4 @@ double integration(double a, double b, int N, double (*my_func)(double x)); Post-conditions - The result is the integral of the specified function in the interval [a,b] -*/ \ No newline at end of file +*/ -- GitLab