Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <vector>
- #include <math.h>
- #include <numeric>
- using namespace std;
- class Pol{
- int n;
- vector<double> cfs;
- vector<double> xExp;
- public:
- Pol(){}
- Pol(int c, vector<double> cs){
- n = c;
- cfs = cs;
- vector<double> xExp(n+1,0);
- }
- double polX(double x){
- xExp.clear();
- for (int i=0; i<=n; i++){
- xExp.push_back(pow(x, i));
- cout << pow(x,i)<<endl;
- }
- return inner_product(cfs.begin(), cfs.end(), xExp.begin(), 0);
- }
- vector <double>& makeV(vector<double> args){
- vector<double> thrdV;
- cout << "Your vector:" << endl;
- for (int i=0; i<n; i++){
- thrdV.push_back((polX(args[i])));
- cout << thrdV[i] << " ";
- }
- return thrdV;
- }
- };
- int main()
- {
- vector<double> cfs(4,3);
- vector<double> args(3,0);
- args[0] = 3;
- args[1] = 4;
- args[2] = 5;
- Pol* p = new Pol(3, cfs);
- double a = p->polX(5);
- cout << "PolX = " << a << endl << endl;
- p->makeV(args);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement