Page Menu
Home
c4science
Search
Configure Global Search
Log In
Files
F74437984
main.cc
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Subscribers
None
File Metadata
Details
File Info
Storage
Attached
Created
Sat, Jul 27, 20:18
Size
2 KB
Mime Type
text/x-c
Expires
Mon, Jul 29, 20:18 (1 d, 23 h)
Engine
blob
Format
Raw Data
Handle
19393703
Attached To
R9484 sp4e-homework-lars-bertil
main.cc
View Options
/* MAIN FILE */
#include "dumper_series.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 == "arithmetics") {
ComputeArithmetic obj;
ptrobj = &obj;
//auto ptrobj = std::make_unique<ComputeArithmetic>();
} else if (in_type == "pi"){
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 == "print"){
print_obj.dump();
}
else if (in_print_or_write == "write"){
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
Log In to Comment