diff --git a/homework2/src/dumper_series.h b/homework2/src/dumper_series.h index 3d1c198..a2bcefa 100644 --- a/homework2/src/dumper_series.h +++ b/homework2/src/dumper_series.h @@ -1,19 +1,27 @@ #ifndef DUMPER_SERIES #define DUMPER_SERIES #include "Series.hh" #include class DumperSeries{ public: - DumperSeries(Series & series): - series(series){} + DumperSeries(Series & series):series(series) + { + } + virtual void dump(std::ostream & os) = 0; + + virtual void setPrecision(unsigned int precision) + { + this->precision = precision; + } protected: Series & series; + unsigned int precision = 8; }; #endif diff --git a/homework2/src/main.cc b/homework2/src/main.cc index 54a8fea..f0dc8bb 100644 --- a/homework2/src/main.cc +++ b/homework2/src/main.cc @@ -1,74 +1,75 @@ //main #include "ComputeArithmetic.hh" #include "ComputePi.hh" #include "print_series.h" #include "write_series.h" #include #include #include #include using namespace std; int main(int argc, char ** argv){ //command line arguments: Type of series and N of terms. stringstream sstr; for (int i = 1 ; i < argc ; ++i){ sstr << argv[i] << " "; } string which_series; string which_dumper; int frequency; int maxiter; sstr >> which_series; sstr >> which_dumper; sstr >> frequency; sstr >> maxiter; Series * my_series = NULL; DumperSeries * my_dumper = NULL; if (which_series == "pi") my_series = new ComputePi(); else if (which_series == "arithmetic") my_series = new ComputeArithmetic(); else { cout<<"insert one of the two available options:" "\n\t arithmetic (to compute arithmetic series)" "\n\t pi (to compute Pi series)"<> separator; my_dumper = new WriteSeries(*my_series, frequency, maxiter, separator); }else { cout<<"insert one of the two available options:" "\n\t print (to print on screen)" "\n\t write (to write in file)"<setPrecision(12); my_dumper->dump(*os); - + file.close(); //double tmpi = my_series->compute(N); //cout<<"Result for the "<frequency = frequency; this->maxiter = maxiter; } void PrintSeries::dump(std::ostream & os){ + os.precision(precision); for(int i=frequency; i