Advertisement
rootuss

pole ograniczone

Feb 20th, 2017
349
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.71 KB | None | 0 0
  1. #include <iostream>
  2. #include <cstdlib>
  3. #include <cmath>
  4. using namespace std;
  5.  
  6.  
  7.  
  8. void F (int stopien1, double fx[])
  9. {
  10.     for(int i=stopien1; i>=0; i--)
  11.     {
  12.         if(i!=0)
  13.         {
  14.  
  15.         cout<<"Podaj wspolczynnik "<<i<<" wyrazu:"<<endl;
  16.         cin>>fx[i];
  17.         }
  18.         else
  19.         {
  20.          cout<<"Podaj wyraz wolny:"<<endl;
  21.         cin>>fx[i];
  22.         }
  23.     }
  24.  
  25.  
  26. }
  27.  
  28. void sprawdz (int stopien2, double fx2[])
  29. {
  30.  
  31.      for(int i=stopien2; i>=0; i--)
  32.     {
  33.  
  34.         if(i!=0)
  35.         {
  36.             cout<<"("<<fx2[i]<<"x^"<<i<<") + ";
  37.         }
  38.         else
  39.         {
  40.             cout<<"("<<fx2[i]<<")";
  41.         }
  42.     }
  43.  
  44. }
  45.  
  46. double oblicz(double fx3[], int stopien3, double x3)
  47. {
  48.     double wynik =0;
  49.     for(int i=0; i<=stopien3; i++)
  50.     {
  51.         wynik=wynik+(fx3[i]*pow(x3,i));
  52.     }
  53.     return wynik;
  54. }
  55.  
  56. int main()
  57. {
  58.     int n;
  59.     int stopien;
  60.     double p,q;
  61.     cout<< "Podaj na ile fragmentow chcesz podzielic obliczane pole"<<endl;
  62.     cin>>n;
  63.     cout<<"Podaj ktorego stopnia funkcje chcesz otrzymac"<<endl;
  64.     cin>>stopien;
  65.     double Funkcja[stopien];
  66.     F(stopien, Funkcja);
  67.     sprawdz(stopien, Funkcja);
  68.     cout<<endl;
  69.     cout<<"Podaj p:"<<endl;
  70.     cin>>p;
  71.     cout<<"Podaj q:"<<endl;
  72.     cin>>q;
  73.     double dlp=(q-p)/n, sp=0;
  74.      for (int i=0; i<n;i++)
  75.     {
  76.         sp=sp+abs(oblicz(Funkcja, stopien, (p+dlp*i+dlp/2)));
  77.     }
  78.     cout<<"Pole pod funkcja wynosi:"<<dlp*sp<<"cm"<<endl;;
  79.     double dlt = (q-p)/n, st=0;
  80.     for (int i=1;i<n;i++)
  81.     {
  82.         st=st+abs(oblicz(Funkcja, stopien, (p+i*dlt/2)));
  83.     }
  84.     cout<<"Pole pod funkcja wynosi:"<<dlt/2*((abs(oblicz(Funkcja, stopien,p))+abs(oblicz(Funkcja, stopien,q)))+2*st)<<"cm";
  85. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement