-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.cpp
78 lines (58 loc) · 2 KB
/
main.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
#include <iostream>
#include <vector>
#include <string>
#include <fstream>
#include <unistd.h>
#include "include/LagrangePolynomial.h"
#include "include/CodeGenerator.h"
using namespace std;
void generate_all_programs(vector<LagrangePolynomial::element> &result, string &path);
int main() {
int n;
cout << "Enter number of terms(n): ";
cin >> n ;
if(n<=0){ // If the user enters a character, it will still be 0
cout << "That's Invalid. Please don't mess around :-(" << endl;
return 0;
}
vector<int> data_y; // f(x)
vector<int> data_x; // x
cout << "Enter the first n terms of the series: ";
for(int i=0; i<n; i++){
int k;
cin >> k;
data_y.push_back(k);
data_x.push_back(i+1);
}
string path;
cout << "Enter destination for source files [Current folder if empty]:";
cin.ignore();
getline(cin,path);
if (path.empty()){
char pwd[256];
getcwd(pwd, 255);
path = pwd;
}
cout << "Using path: " << path << endl;
BasisPolynomial bp(data_x); // generating basis polynomials
vector<poly> basis_p = bp.get_all_basis_polynomials();
LagrangePolynomial lp; // generating the lagrange polynomial
vector<LagrangePolynomial::element> results = lp.get_lagrange_polynomial(data_y,basis_p);
generate_all_programs(results,path);
cout << "\nDone. May the force be with you :-)" << endl;
return 0;
}
void generate_all_programs(vector<LagrangePolynomial::element> &result,string &path){
CodeGenerator cg(result);
CodeGenerator::code_arr all_programs = cg.generate_all_lang_code();
ofstream outfile;
string file_path = path+"/program_hw.";
cout << "\n" ;
for(int i=0; i<6; i++){
outfile.open(file_path + all_programs.languages[i]);
cout << "Writing " << all_programs.languages[i]
<< " file to " << file_path + all_programs.languages[i] << endl;
outfile << all_programs.code[i] << endl;
outfile.close();
}
}