Advertisement
Misipuk

LB2

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