diff --git a/Homework2/src/compute_arithmetic.cc b/Homework2/src/compute_arithmetic.cc index 04d20bf..82db929 100644 --- a/Homework2/src/compute_arithmetic.cc +++ b/Homework2/src/compute_arithmetic.cc @@ -1,21 +1,11 @@ #include "compute_arithmetic.hh" -compute_arithmetic::compute_arithmetic() -{ - // std::cout<<"compute_arithmetic object constructed!"<<std::endl; -} - -compute_arithmetic::~compute_arithmetic() -{ - // std::cout<<"compute_arithmetic object destructed!"<<std::endl; -} - double compute_arithmetic::expression(unsigned int N) { return double(N); } double compute_arithmetic::compute(unsigned int N) { return SUM(N); } \ No newline at end of file diff --git a/Homework2/src/compute_arithmetic.hh b/Homework2/src/compute_arithmetic.hh index a911cc9..61aca8a 100644 --- a/Homework2/src/compute_arithmetic.hh +++ b/Homework2/src/compute_arithmetic.hh @@ -1,18 +1,14 @@ #ifndef COMPUTE_ARITHMETIC_HH #define COMPUTE_ARITHMETIC_HH #include "series.hh" class compute_arithmetic: public Series { public: - // Constructor - Destructor - compute_arithmetic(); - ~compute_arithmetic(); - // Functions double expression(unsigned int N); // Expression appeared in the Sigma for arithmetic double compute(unsigned int N); // The target function }; #endif \ No newline at end of file diff --git a/Homework2/src/compute_pi.cc b/Homework2/src/compute_pi.cc index 6686a4c..4b093c6 100644 --- a/Homework2/src/compute_pi.cc +++ b/Homework2/src/compute_pi.cc @@ -1,34 +1,24 @@ #include "compute_pi.hh" -compute_pi::compute_pi() -{ - // std::cout<<"compute_pi object constructed!"<<std::endl; -} - -compute_pi::~compute_pi() -{ - // std::cout<<"compute_pi object destructed!"<<std::endl; -} - double compute_pi::expression(unsigned int N) { return 1.0/pow(double(N),2); } double compute_pi::compute(unsigned int N) { return sqrt(6.0*SUM(N)); } double compute_pi::getAnalyticPrediction() { return M_PI; } diff --git a/Homework2/src/compute_pi.hh b/Homework2/src/compute_pi.hh index 4bccc05..6e018a1 100644 --- a/Homework2/src/compute_pi.hh +++ b/Homework2/src/compute_pi.hh @@ -1,19 +1,15 @@ #ifndef COMPUTE_PI_HH #define COMPUTE_PI_HH #include "series.hh" class compute_pi: public Series { public: - // Constructor - Destructor - compute_pi(); - ~compute_pi(); - // Functions double expression(unsigned int N); // Expression appeared in the Sigma for arithmetic double compute(unsigned int N); // The target function double getAnalyticPrediction(); // Analytical expected value: pi number }; #endif \ No newline at end of file diff --git a/Homework2/src/series.cc b/Homework2/src/series.cc index 0960de4..9833169 100644 --- a/Homework2/src/series.cc +++ b/Homework2/src/series.cc @@ -1,36 +1,24 @@ #include "series.hh" -Series::Series() -{ - //std::cout<<"Series object constructed!"<<std::endl; - current_index = 0; - current_value = 0.0; -} - -Series::~Series() -{ - //std::cout<<"Series object destructed!"<<std::endl; -} - double Series::SUM(unsigned int N) { while (current_index != N) { if (N>current_index) { current_index += 1; current_value += expression(current_index); } else { current_value -= expression(current_index); current_index -= 1; } } return current_value; } double Series::getAnalyticPrediction() { return std::nan(""); } \ No newline at end of file diff --git a/Homework2/src/series.hh b/Homework2/src/series.hh index c53b192..97e54e4 100644 --- a/Homework2/src/series.hh +++ b/Homework2/src/series.hh @@ -1,26 +1,26 @@ #ifndef SERIES_HH #define SERIES_HH #include <iostream> #include <cmath> class Series { public: // Constructor - Destructor - Series(); - virtual ~Series(); + Series(): current_index(0), current_value(0.0){} + virtual ~Series(){}; // Functions virtual double expression(unsigned int N) = 0; // The expression appeared in Sigma virtual double compute(unsigned int N) = 0; // Computes the solution as a function of summation virtual double getAnalyticPrediction(); // Returns analytical asymptotic solution of compute (NaN by default) double SUM(unsigned int N); // Sums expression from 1 to N // Members unsigned int current_index; // Upper bound of the last summation double current_value; // Value of the last summation }; #endif \ No newline at end of file