diff --git a/Homework2/README.md b/Homework2/README.md index b1e1540..28afd78 100644 --- a/Homework2/README.md +++ b/Homework2/README.md @@ -1,39 +1,43 @@ # SP4E - Homework 2 ---- ## General Info This file provides a brief documentation and information related to the second Homework of the course "Scientific Programming for Engineers", fall 2019. This homework is done by **O. Ashtari** and **A. Sieber**. Last update: 10.30.2019 ---- ## Project Description +<<<<<<< HEAD The aim of this project is to implement of familly of objects intended to compute two type of series: an arithmetic serie and a serie to approximate the value of pi. The user can then decide how to dump the results by either printing them to the screen or writing them to a file. If the later option is chosen, a python file is available to plot the results stored in the file. +======= +The aim of this project is to implement of familly of objects intended to compute two type of series: an arithmetic serie and a serie to approximate the value of pi. The user can then decide how to dump the results by either printing them to the screen or writing them to a file. If the later option is chosen, a python file is available to plot the results stored in the file. +>>>>>>> 49b66f9f67540aa07ba5c208324e0ad638c5522f ---- ## Requirements ---- ## Installation ---- ## Running ---- ## Work separtion between the authors ---- diff --git a/Homework2/src/main.cc b/Homework2/src/main.cc index 5a965f8..540aaef 100644 --- a/Homework2/src/main.cc +++ b/Homework2/src/main.cc @@ -1,152 +1,155 @@ #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" 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); -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); - } -} int main(int argc, char ** argv) { /* // ========== TEST 1: Checking the function "compute(int N)" ========== compute_arithmetic my_arithmetic; // Object of type "compute_arithmetic" compute_pi my_pi; // Object of type "compute_pi" cout << my_arithmetic.compute(10) << endl; //Arithmetic series up to 10. Expected value: 55 cout << my_pi.compute(10) << endl; //Pi series up to 10. Expected value: 3.04936 */ /* // ========== TEST 2: Working with a Series pointer" ========== Series *SERIES1, *SERIES2; //Pointers of type Series SERIES1 = new compute_arithmetic(); //SERIES1 points to an object of type compute_arithmetic SERIES2 = new compute_pi(); //SERIES2 points to an object of type compute_pi cout << SERIES1->compute(10) << endl; //Arithmetic series up to 10. Expected value: 55 cout << SERIES2->compute(10) << endl; //Pi series up to 10. Expected value: 3.04936 delete SERIES1; //Free up memory delete SERIES2; //Free up memory */ int N_inputs = argc; std::stringstream inputs; - for (int i = 1; i < argc; ++i){ + 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 N; // max number of iteration entered as input + unsigned long freq; //frequency for dumper series unsigned int precision; inputs >> serie_type; inputs >> dump_type; inputs >> separator; inputs >> N; inputs >> freq; inputs >> precision; 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"); + 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(); /* // Dumper and writing if (dump_type == "print") { PrintSeries my_dump(*ptrSeries, N, freq, precision); my_dump.dump(); std::string file_name = "ostream_output.txt"; std::ofstream my_os_file; my_os_file.open(file_name, std::ios::out | std::ios::trunc); my_dump.dump(my_os_file); my_os_file.close(); } else if (dump_type == "write") { WriteSeries my_dump(*ptrSeries, N, separator, precision); my_dump.dump(); } else { std::cout << "Dump type does not exist" << std::endl; abort(); } */ 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); + } } \ No newline at end of file