Page MenuHomec4science

main.cc
No OneTemporary

File Metadata

Created
Thu, May 30, 03:35
/* MAIN FILE */
#include "print_series.hh"
#include "compute_pi.hh"
#include "compute_arithmetic.hh"
using namespace std;
// TODO: Use stringstream for argv!
int main(int argc, char *argv[]) {
std::stringstream sstr;
for (int i = 1; i < argc; ++i) {
sstr << argv[i] << " ";
}
std::string in_type;
std::string in_print_or_write;
unsigned int in_precision;
std::string in_separator;
sstr >> in_type;
sstr >> in_print_or_write;
sstr >> in_precision;
sstr >> in_separator;
std::cout << "You chose the following options: " << std::endl;
std::cout << "Type: " << in_type << std::endl;
std::cout << "Output: " << in_print_or_write << std::endl;
std::cout << "Precision: " << in_precision << std::endl;
std::cout << "Separator: " << in_separator << std::endl;
if (in_print_or_write == "print")
std::cout << "Note: The separator is only used when writing to file!" << std::endl;
// Declare Variables
int N = 500;
int maxiter = 500;
int freq = 10;
// Instantiate an obj of a subclass from Series and Point its address
Series *ptrobj;
if (in_type.compare("arithmetic")==0) {
ComputeArithmetic obj;
ptrobj = &obj;
//auto ptrobj = std::make_unique<ComputeArithmetic>();
} else if (in_type.compare("pi")==0){
ComputePi obj;
ptrobj = &obj;
//auto ptrobj = std::make_unique<ComputePi>();
} else {
cout << "Wrong Input: Run aborted!" << endl;
return 0;
}
// Call the associated method
double MyResult = ptrobj->compute(N);
// Print the Result
cout << "The result is: " << MyResult << endl;
// Print to screen or Write to file
PrintSeries print_obj = PrintSeries(*ptrobj, maxiter, freq);
print_obj.setPrecision(in_precision);
if (in_print_or_write.compare("print")==0){
print_obj.dump();
}
else if (in_print_or_write.compare("write")==0){
std::string filename;
std::string separator;
if (in_separator.compare("comma")==0){
filename = "out.csv";
separator = ",";
}
else if (in_separator.compare("pipe")==0){
filename = "out.psv";
separator = "|";
}
else{ // default is txt file
std::cout << "Choosing default filename and separator" << std::endl;
filename = "out.txt";
separator = " ";
}
print_obj.setSeparator(separator);
std::ofstream outFile(filename);
print_obj.dump(outFile);
}
else{
cout << "Wrong Input: Run aborted!" << endl;
return 0;
}
return 0;
}

Event Timeline