Advertisement
Guest User

Untitled

a guest
Nov 21st, 2017
62
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.18 KB | None | 0 0
  1. #include <iostream>
  2. #include <vector>
  3. #include <algorithm>
  4.  
  5. #define MIN_RANGE -10.5
  6. #define MAX_RANGE 10.5
  7.  
  8. using namespace std;
  9.  
  10. struct MyObject
  11. {
  12.     float m_fPosX;
  13.     float m_fPosY;
  14.     float m_fMass;
  15.     MyObject(){}
  16.     MyObject(float first,float second,float third)
  17.     {
  18.         m_fPosX = first;
  19.         m_fPosY = second;
  20.         m_fMass = third;
  21.     }
  22. };
  23.  
  24. struct MyObject g()
  25. {
  26.     float first = (float)rand()/ RAND_MAX * (MAX_RANGE - MIN_RANGE) - fabs(MIN_RANGE);
  27.     float second = (float)rand()/ RAND_MAX * (MAX_RANGE - MIN_RANGE) - fabs(MIN_RANGE);
  28.     float third = (float)rand()/ RAND_MAX * (MAX_RANGE - MIN_RANGE) - fabs(MIN_RANGE);
  29.     return MyObject(first,second,third);
  30. };
  31.  
  32. int main()
  33. {
  34.     vector<MyObject> vecObjects(20);
  35.     generate(vecObjects.begin(),vecObjects.end(),[]() -> MyObject{return g();});
  36.     for(unsigned i = 0; i < 20; ++i)
  37.     {
  38.         cout << "vecObjects["<< i <<"].m_fPosX = "<<vecObjects[i].m_fPosX << endl;
  39.         cout << "vecObjects["<< i <<"].m_fPosY = "<<vecObjects[i].m_fPosY << endl;
  40.         cout << "vecObjects["<< i <<"].m_fMass = "<<vecObjects[i].m_fMass << endl;
  41.         cout << endl<< endl;
  42.     }
  43.     return 0;
  44. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement