Advertisement
Misipuk

LB2_1

Dec 18th, 2018
112
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.21 KB | None | 0 0
  1. #include <iostream>
  2. #include <vector>
  3. #include <math.h>
  4. #include <numeric>
  5.  
  6. using namespace std;
  7.  
  8.  
  9. class Pol{
  10.     int n;
  11.     vector<double> cfs;
  12.     vector<double> xExp;
  13.  
  14.     public:
  15.  
  16.         Pol(){}
  17.  
  18.         Pol(int c, vector<double> cs){
  19.             n = c;
  20.             cfs = cs;
  21.             vector<double> xExp(n+1,0);
  22.         }
  23.  
  24.         double polX(double x){
  25.             xExp.clear();
  26.             for (int i=0; i<=n; i++){
  27.                 xExp.push_back(pow(x, i));
  28.                 cout << pow(x,i)<<endl;
  29.             }
  30.             return inner_product(cfs.begin(), cfs.end(), xExp.begin(), 0);
  31.         }
  32.  
  33.         vector <double>& makeV(vector<double> args){
  34.             vector<double> thrdV;
  35.             cout << "Your vector:" << endl;
  36.             for (int i=0; i<n; i++){
  37.                 thrdV.push_back((polX(args[i])));
  38.                 cout << thrdV[i] << " ";
  39.             }
  40.             return thrdV;
  41.         }
  42. };
  43.  
  44. int main()
  45. {
  46.     vector<double> cfs(4,3);
  47.     vector<double> args(3,0);
  48.     args[0] = 3;
  49.     args[1] = 4;
  50.     args[2] = 5;
  51.     Pol* p = new Pol(3, cfs);
  52.     double a = p->polX(5);
  53.     cout << "PolX = " << a << endl << endl;
  54.     p->makeV(args);
  55.     return 0;
  56. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement