Commit 1b5df869 authored by Manon Eugénie Voisin--Leprince's avatar Manon Eugénie Voisin--Leprince
Browse files

HW2

parent bfcbc6f5
/* -------------------------------------------------------------------------- */
#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <fstream>
#include <iostream>
#include <map>
#include <math.h>
#include <sstream>
#include <vector>
#include <math.h>
#include <cmath>
/* -------------------------------------------------------------------------- */
#include "compute_arithmetic.hh"
#include "compute_pi.hh"
#include "riemann_integral.hh"
#include "main.hh"
#include "print_series.hh"
#include "riemann_integral.hh"
#include "write_series.hh"
/* -------------------------------------------------------------------------- */
......@@ -28,7 +28,8 @@ ArgMap defaults{{"series_type", "pi"}, {"dumper_type", "print"},
{"maxiter", "1000"}, {"precision", "5"},
{"delimiter", " "}};
ArgMap options{{"series_type", "pi/arithmetic/integral_cube/integral_cos/integral_sin"},
ArgMap options{{"series_type", "pi/arithmetic/integral"},
{"function", "cube/cos/sin"},
{"integral_bound_inf", "bound inf of integral"},
{"integral_bound_sup", "bound sup of integral"},
{"dumper_type", "print/write"},
......@@ -52,49 +53,47 @@ int main(int argc, char **argv) {
auto params = parseArgv(argc, argv);
auto series_type = params["series_type"];
auto function = params["function"];
auto dumper_type = params["dumper_type"];
auto max_iter = atoi(params["maxiter"].c_str());
auto precision = atoi(params["precision"].c_str());
auto delimiter = params["delimiter"];
auto freq = atoi(params["freq"].c_str());
auto output = params["output"];
auto bound_inf = atof(params["integral_bound_inf"].c_str());
auto bound_sup = atof(params["integral_bound_sup"].c_str());
if (params["integral_bound_inf"] == "pi")
auto bound_inf = atof(params["integral_bound_inf"].c_str());
auto bound_sup = atof(params["integral_bound_sup"].c_str());
if (params["integral_bound_inf"] == "pi")
bound_inf = M_PI;
if (params["integral_bound_inf"] == "pi/2")
bound_inf = M_PI/2;
if (params["integral_bound_sup"] == "pi")
bound_inf = M_PI / 2;
if (params["integral_bound_sup"] == "pi")
bound_sup = M_PI;
if (params["integral_bound_sup"] == "pi/2")
bound_sup = M_PI/2;
bound_sup = M_PI / 2;
//********************************
// Series object creation
//********************************
std::unique_ptr<Series> series = nullptr;
if (series_type == "pi")
series = std::make_unique<ComputePi>();
else if (series_type == "arithmetic")
series = std::make_unique<ComputeArithmetic>();
else if (series_type == "integral_cube"){
std::function<double(double)> func = [](double i) { return i * i * i; };
series = std::make_unique<RiemannIntegral>(func, bound_inf, bound_sup);
}
else if (series_type == "integral_cos"){
std::function<double(double)> func = [](double i) { return cos(i); };
series = std::make_unique<RiemannIntegral>(func, bound_inf, bound_sup);
else if (series_type == "integral") {
std::function<double(double)> func;
if (function == "cube") {
func = [](double i) { return i * i * i; };
} else if (function == "cos") {
func = [](double i) { return cos(i); };
} else if (series_type == "sin") {
func = [](double i) { return sin(i); };
}
else if (series_type == "integral_sin"){
std::function<double(double)> func = [](double i) { return sin(i); };
series = std::make_unique<RiemannIntegral>(func, bound_inf, bound_sup);
}
else
} else
printUsage(argv[0]);
// Dumper object creation
......@@ -102,12 +101,12 @@ int main(int argc, char **argv) {
std::unique_ptr<DumperSeries> dumper = nullptr;
if (dumper_type == "print")
dumper = std::make_unique<PrintSeries>(*series, freq);
dumper = std::make_unique<PrintSeries>(*series, freq);
else if (dumper_type == "write")
dumper = std::make_unique<WriteSeries>(*series, delimiter);
dumper = std::make_unique<WriteSeries>(*series, delimiter);
else
printUsage(argv[0]);
//********************************
// File object creation
//********************************
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment