Page MenuHomec4science

main.cc
No OneTemporary

File Metadata

Created
Tue, Jun 4, 00:16
#include <iostream>
#include <string>
#include <sstream>
#include <fstream>
#include "series.hh"
#include "compute_arithmetic.hh"
#include "compute_pi.hh"
#include "dumper_series.hh"
#include "print_series.hh"
#include "write_series.hh"
#include <cmath>
using namespace std;
// Functions declaration
void decide_series(Series *&new_series, string type);
void decide_dumper(DumperSeries *&new_dumper, Series *&ptrSeries, string type, int Nmbr, int frqncy, string sprtr, int prcsn);
int main(int argc, char ** argv)
{
int N_inputs = argc;
std::stringstream inputs;
for (int i = 1; i < argc; ++i)
{
inputs << argv[i] << " ";
}
std::string serie_type;
std::string dump_type;
std::string separator;
unsigned long N; // max number of iteration entered as input
unsigned long freq; //frequency for dumper series
unsigned long precision;
inputs >> serie_type;
inputs >> dump_type;
inputs >> separator;
inputs >> N;
inputs >> freq;
inputs >> precision;
if (N<1)
{
std::cout<<"ERROR: Invalid input. N must be a positive integer (N>0)"<<std::endl;
exit(0);
}
printf("###### User Inputs ###### \n");
std::cout << "Serie type: " << serie_type << std::endl;
std::cout << "Dump type: " << dump_type << std::endl;
std::cout << "Separator type: " << separator << std::endl;
std::cout << "Max iterations: " << N << std::endl;
std::cout << "Dump frequency: " << freq << std::endl;
std::cout << "Precision: " << precision << std::endl;
printf("######################### \n");
// Pointers
Series *ptrSeries = nullptr; // Pointer to Series
DumperSeries *ptrDumper = nullptr; // Pointer to Dumper
// Choose series to be implemented
decide_series(ptrSeries, serie_type);
decide_dumper(ptrDumper, ptrSeries, dump_type, N, freq, separator, precision);
ptrDumper -> dump();
if (dump_type == "print")
{
std::ofstream my_os_file("ostream_output.txt", std::ios::out | std::ios::trunc);
ptrDumper -> dump(my_os_file);
my_os_file.close();
}
delete ptrSeries;
delete ptrDumper;
return 0;
}
void decide_series(Series *&new_series, string type)
{
if (type == "arithmetic")
{
new_series = new compute_arithmetic();
}
else if (type == "pi")
{
new_series = new compute_pi();
}
else
{
cout<<"ERROR: Invalid series type. Please enter 'arithmetic' or 'pi'."<<endl;
exit(0);
}
}
void decide_dumper(DumperSeries *&new_dumper, Series *&ptrSeries, string type, int Nmbr, int frqncy, string sprtr, int prcsn)
{
if (type == "print")
{
new_dumper = new PrintSeries(*ptrSeries, Nmbr, frqncy, prcsn);
}
else if (type == "write")
{
new_dumper = new WriteSeries(*ptrSeries, Nmbr, sprtr, prcsn);
}
else
{
cout<<"ERROR: Invalid dumbper type. Please enter 'print' or 'write'."<<endl;
exit(0);
}
}

Event Timeline