diff --git a/exercice_2/src/compute_arithmetic.cc b/exercice_2/src/compute_arithmetic.cc index 6615fde..a2d1c24 100644 --- a/exercice_2/src/compute_arithmetic.cc +++ b/exercice_2/src/compute_arithmetic.cc @@ -1,12 +1,12 @@ #include "compute_arithmetic.hh" /* -------------------------------------------------------------------------- */ double ComputeArithmetic::compute(unsigned int N) { - double sum_value = 0; - for (int k = 0; k < N; ++k) + double sum_value = 0.; + for (int k = 1; k <= N; ++k) sum_value += k; return sum_value; } ComputeArithmetic::~ComputeArithmetic() = default; diff --git a/exercice_2/src/compute_pi.cc b/exercice_2/src/compute_pi.cc index 7fcf297..8194113 100644 --- a/exercice_2/src/compute_pi.cc +++ b/exercice_2/src/compute_pi.cc @@ -1,12 +1,12 @@ #include "compute_pi.hh" #include double ComputePi::compute(unsigned int N) { - double inner_root = 0; - for (int k = 0; k < N; ++k) + double inner_root = 0.; + for (int k = 1; k <= N; ++k) inner_root += 1 / pow(k, 2); return sqrt(6. * inner_root); } ComputePi::~ComputePi() = default; diff --git a/exercice_2/src/compute_pi.hh b/exercice_2/src/compute_pi.hh index 226d744..536cffa 100644 --- a/exercice_2/src/compute_pi.hh +++ b/exercice_2/src/compute_pi.hh @@ -1,15 +1,15 @@ #ifndef COMPUTE_PI_HH #define COMPUTE_PI_HH #include "series.hh" class ComputePi : public Series { public: // ComputePi(); virtual ~ComputePi(); public: - double compute(unsigned int N); + double compute(unsigned int N) override; }; #endif diff --git a/exercice_2/src/main.cc b/exercice_2/src/main.cc index 36f2b3b..0870608 100644 --- a/exercice_2/src/main.cc +++ b/exercice_2/src/main.cc @@ -1,49 +1,51 @@ /* created by Marti Bosch and Marc Schwaerzel*/ /* -------------------------------------------------------------------------- */ #include #include #include #include "compute_arithmetic.hh" #include "compute_pi.hh" #include "print_series.hh" #include "series.hh" /* -------------------------------------------------------------------------- */ int main(int argc, char **argv) { std::cout << "exercice 2" << std::endl; - std::cout << "please enter the following arguments: frequence, maxiter, " + /* std::cout << "please enter the following arguments: frequence, maxiter, " "serie_type= #" << std::endl; const char *series_type; int maxiter; int ferquency; if (argc != 3) { std::cout << "retry with arg: frequence, maxiter, serie_type=pi/arithmetic" << std::endl; return EXIT_FAILURE; } Series *input_series_type; - /* if (series_type == "arithmetic"){ + if (series_type == "arithmetic"){ input_series_type = new ComputeArithmetic(); } else if (series_type == "pi"){ input_series_type = new ComputePi(); } else{std::cout << "input error"<< std::endl; }*/ - ComputeArithmetic comparith; + ComputePi comp; + std::cout<