Page MenuHomec4science

main.cc
No OneTemporary

File Metadata

Created
Mon, Jun 3, 19:39
/* created by Marti Bosch and Marc Schwaerzel*/
/* -------------------------------------------------------------------------- */
#include <cstdlib>
#include <cstring>
#include <fstream>
#include <iostream>
#include <sstream>
#include "compute_arithmetic.hh"
#include "compute_pi.hh"
#include "print_series.hh"
#include "series.hh"
#include "write_series.hh"
using namespace std;
/* -------------------------------------------------------------------------- */
int main(int argc, char **argv) {
if (argc != 5) {
cout << "Arguments: frequency, maxiter, series_type (arithmetic, pi), "
"dump_type (print, write)"
<< endl;
return EXIT_FAILURE;
}
std::stringstream sstr;
for (int i = 1; i < argc; ++i)
sstr << argv[i] << " ";
int frequency;
int maxiter;
string series_type;
string dump_type;
sstr >> frequency;
sstr >> maxiter;
sstr >> series_type;
sstr >> dump_type;
Series *series;
if (series_type == "arithmetic")
series = new ComputeArithmetic();
else if (series_type == "pi")
series = new ComputePi();
else {
std::cout << "input error" << std::endl;
return EXIT_FAILURE;
}
std::ofstream of("output.txt");
if (dump_type == "print") {
PrintSeries printseries(*series, maxiter, frequency);
printseries.dump();
} else if (dump_type == "write") {
WriteSeries writeseries(*series, maxiter, frequency);
writeseries.dump(of);
}
delete series;
}

Event Timeline