diff --git a/work/week6/series/homework2/src/main.cc b/work/week6/series/homework2/src/main.cc index 1f69766..5ef1abe 100644 --- a/work/week6/series/homework2/src/main.cc +++ b/work/week6/series/homework2/src/main.cc @@ -1,28 +1,42 @@ -#include -#include "arithmetic.hh" - -#include "pi.hh" - #include #include #include #include +#include + +#include "arithmetic.hh" +#include "pi.hh" +#include "series.hh" + /* -------------------------------------------------------------------------- */ int main(int argc, char ** argv) { - // Parse number of iterations - unsigned int N = 10; + // Parse method type + std::string method = "ar"; // default value if (argc > 1) { - N = atoi(argv[1]); + method = argv[1]; } - // Instanciate series object and compute series - ComputeArithmetic ar; - std::cout << "ComputeArithmetic(" << N << ") = " << ar.compute(N) << std::endl; + // Parse number of iterations + unsigned int N = 10; // default value + if (argc > 2) { + N = atoi(argv[2]); + } + + // Instanciate appropriate series object + std::string method_label; + std::unique_ptr series; // doesn't point to anything yet + if (method == "ar") { + series.reset(new ComputeArithmetic); + method_label = "ComputeArithmetic"; + } else if (method == "pi") { + series.reset(new ComputePi); + method_label = "ComputePi"; + } - ComputePi pi; - std::cout << "ComputePi(" << N << ") = " << pi.compute(N) << std::endl; + // Compute series + std::cout << method_label << "(" << N << ") = " << series->compute(N) << std::endl; return EXIT_SUCCESS; }