Advertisement
Guest User

Untitled

a guest
Jan 23rd, 2018
52
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.48 KB | None | 0 0
  1. #include <iostream>
  2. #include <vector>
  3. #include <algorithm>
  4. #include <ctime>
  5. #include <numeric>
  6.  
  7. using namespace std;
  8.  
  9. class wypisanie
  10. {
  11. int help;
  12. public:
  13. wypisanie() : help(0) {};
  14. void operator()(const double x)
  15. {
  16. cout << ++help << " = " << x << endl;
  17. return;
  18. }
  19. };
  20.  
  21. class sumowanie
  22. {
  23. public:
  24. vector<double> operator()(vector<double> a, vector<double> b)
  25. {
  26. vector<double> zwrot;
  27. for (vector<double>::iterator aa = a.begin(), bb = b.begin(); aa != a.end(); ++aa, ++bb)
  28. {
  29. int cc = *aa + *bb;
  30. zwrot.push_back(cc);
  31.  
  32. }
  33. return zwrot;
  34. }
  35. };
  36.  
  37. int main()
  38. {
  39. srand(time(NULL));
  40. vector<double> A(3), B(3);
  41. vector<vector<double>> AB(10), BA(10);
  42.  
  43. for (int i = 0; i < 10; ++i)
  44. {
  45. for_each(A.begin(), A.end(), [](double &a) {a = rand() % 10; });
  46. AB.push_back(A);
  47. for_each(B.begin(), B.end(), [](double &a) {a = rand() % 10; });
  48. BA.push_back(B);
  49. }
  50.  
  51. //cout << "Pierwsza chmura: " << endl;
  52. //for_each(AB.begin(), AB.end(), [](vector<double> xx) {for_each(xx.begin(), xx.end(), wypisanie());});
  53.  
  54. //cout << "Druga chmura: " << endl;
  55. //for_each(BA.begin(), BA.end(), [](vector<double> xx) {for_each(xx.begin(), xx.end(), wypisanie());});
  56.  
  57. vector<double> centroidA(3), centroidB(3);
  58. centroidA = accumulate(AB.begin(), AB.end(), centroidA, sumowanie());
  59. centroidB = accumulate(BA.begin(), BA.end(), centroidB, sumowanie());
  60.  
  61. cout << endl << endl;
  62. for_each(centroidA.begin(), centroidA.end(), wypisanie());
  63.  
  64. return 0;
  65. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement