Page MenuHomec4science

main.cc
No OneTemporary

File Metadata

Created
Thu, Jun 6, 05:01
#include <cstdlib>
#include <cmath>
#include <iostream>
#include <iomanip>
#include <memory>
#include "arithmetic.hh"
#include "pi.hh"
#include "series.hh"
#include "print.hh"
#include "write.hh"
#include "dumper.hh"
/* -------------------------------------------------------------------------- */
int main(int argc, char ** argv) {
// Parse method type
std::string method = "ar"; // default value
if (argc > 1) {
method = argv[1];
}
// Parse number of iterations
unsigned int N = 10; // default value
if (argc > 2) {
N = atoi(argv[2]);
}
// Parse frequency
unsigned int freq = 1; // default value
if (argc > 3) {
freq= atoi(argv[3]);
}
// Instanciate appropriate series object
std::unique_ptr<Series> series; // doesn't point to anything yet
if (method == "ar") {
series.reset(new ComputeArithmetic);
} else if (method == "pi") {
series.reset(new ComputePi);
}
// Compute series
std::cout << series->getName() << "(" << N << ") = " << series->compute(N) << std::endl;
// Print series values from 1 to N onto screen (with specific frequency)
PrintSeries printer(*series,N,freq);
printer.dump();
// Dump series values from 1 to N into file
WriteSeries writer(*series, N, ",");
writer.dump();
return EXIT_SUCCESS;
}

Event Timeline