diff --git a/exercice_2/src/compute_arithmetic.cc b/exercice_2/src/compute_arithmetic.cc index 51f4c7b..491931e 100644 --- a/exercice_2/src/compute_arithmetic.cc +++ b/exercice_2/src/compute_arithmetic.cc @@ -1,4 +1,12 @@ #include "compute_arithmetic.hh" /* -------------------------------------------------------------------------- */ double ComputeArithmetic::computeTerm(unsigned int k) { return 1. * k; } + +double ComputeArithmetic::compute(unsigned int N) { + int s = 0; + for (int i = 0; i < N; ++i) + s += this->computeTerm(i); + + return s; +} diff --git a/exercice_2/src/compute_arithmetic.hh b/exercice_2/src/compute_arithmetic.hh index 45869dd..8f031c6 100644 --- a/exercice_2/src/compute_arithmetic.hh +++ b/exercice_2/src/compute_arithmetic.hh @@ -1,16 +1,17 @@ #ifndef COMPUTE_ARITHMETIC_HH #define COMPUTE_ARITHMETIC_HH #include "series.hh" class ComputeArithmetic : public Series { public: ComputeArithmetic(); virtual ~ComputeArithmetic(); public: double computeTerm(unsigned int k) override; + double compute(unsigned int N) override; }; #endif diff --git a/exercice_2/src/series.cc b/exercice_2/src/series.cc index 2d77f4b..07ca44d 100644 --- a/exercice_2/src/series.cc +++ b/exercice_2/src/series.cc @@ -1,25 +1,24 @@ #include "series.hh" -Series::Series() { - current_term = 0; - current_value = 0; -} +// Series::Series() { +// current_term = 0; +// current_value = 0; +// } -double Series::compute(unsigned int N) { - if (this->current_term <= N) { - N -= this->current_term; - } else { - this->current_term = 0; - this->current_value = 0.0; - } - for (int k = 0; k < N; ++k) { - addTerm(); - return this->current_value; - } -} +// double Series::compute(unsigned int N) { +// if (this->current_term <= N) { +// N -= this->current_term; +// } else { +// this->current_term = 0; +// this->current_value = 0.0; +// } +// for (int k = 0; k < N; ++k) { +// addTerm(); +// return this->current_value; +// } +// } -void Series::addTerm() { - - this->current_term += 1; - this->current_value += this->computeTerm(this->current_term); -} +// void Series::addTerm() { +// this->current_term += 1; +// this->current_value += this->computeTerm(this->current_term); +// }