Leeen

с этим можно работать

Apr 25th, 2020
319
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.53 KB | None | 0 0
  1. #include<iostream>
  2. #include<vector>
  3. #include<unistd.h>
  4. #include<string.h>
  5.  
  6. using namespace std;
  7.  
  8. void help(){
  9.   cout << "Chebeshev function\nn - number of iteration\nx - argument of function\nPlease, enter thevalue of n  and x.\n Use Enter for it\n";
  10. }
  11.  
  12. double chebeshev(int n, double x)
  13. {
  14.    if (n == 0)
  15.            {
  16.                  return 1;
  17.            }
  18.            else if (n == 1)
  19.            {
  20.                  return x;
  21.            }
  22.            else
  23.            {
  24.                  double polinom;
  25.                  polinom = 2 * x * chebeshev(n - 1, x) - chebeshev(n - 2, x);
  26.                  return polinom;
  27.            }
  28.     }
  29. int main(int argc, char ** argv){
  30. if ((argc == 2) && (!strcmp("help", argv[1])))
  31.     {
  32.         help();
  33.         exit(0);
  34.     }
  35. int pid;
  36. int c[2];
  37. int s[2];
  38. pipe(c);
  39. pipe(s);
  40. if((pid = fork()) == -1)
  41.            {
  42.                    perror("fork");
  43.                    exit(1);
  44.            }
  45.         if((pid = fork()) == 0)
  46.            {
  47.    
  48.                 int n;
  49.                 cin >> n;
  50.                 write(c[1], &n, sizeof(n));
  51.                 double x;
  52.                 cin >> x;
  53.                 write(c[1], &x, sizeof(x));
  54.                 close(c[1]);
  55.                
  56.         double result1;
  57.                 read(s[0], &result1, sizeof(result1));
  58.                 close(s[1]);
  59.                 cout << "Result = " << result1 << endl;
  60.  
  61.            }
  62.            else
  63.            {
  64.                 int n1;
  65.  
  66.                 read(c[0], &n1, sizeof(n1));
  67.                 double x1;
  68.                 read(c[0], &x1, sizeof(x1));
  69.                 close(c[0]);
  70.  
  71.                 double result =  chebeshev(n1, x1);
  72.                 write(s[1], &result, sizeof(result));
  73.                 close(s[1]);
  74.  
  75.            }
  76.     return 0;
  77. }
Add Comment
Please, Sign In to add comment