Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <vector>
- #include <algorithm>
- #define MIN_RANGE -10.5
- #define MAX_RANGE 10.5
- using namespace std;
- struct MyObject
- {
- float m_fPosX;
- float m_fPosY;
- float m_fMass;
- MyObject(){}
- MyObject(float first,float second,float third)
- {
- m_fPosX = first;
- m_fPosY = second;
- m_fMass = third;
- }
- };
- struct MyObject g()
- {
- float first = (float)rand()/ RAND_MAX * (MAX_RANGE - MIN_RANGE) - fabs(MIN_RANGE);
- float second = (float)rand()/ RAND_MAX * (MAX_RANGE - MIN_RANGE) - fabs(MIN_RANGE);
- float third = (float)rand()/ RAND_MAX * (MAX_RANGE - MIN_RANGE) - fabs(MIN_RANGE);
- return MyObject(first,second,third);
- };
- int main()
- {
- vector<MyObject> vecObjects(20);
- generate(vecObjects.begin(),vecObjects.end(),[]() -> MyObject{return g();});
- for(unsigned i = 0; i < 20; ++i)
- {
- cout << "vecObjects["<< i <<"].m_fPosX = "<<vecObjects[i].m_fPosX << endl;
- cout << "vecObjects["<< i <<"].m_fPosY = "<<vecObjects[i].m_fPosY << endl;
- cout << "vecObjects["<< i <<"].m_fMass = "<<vecObjects[i].m_fMass << endl;
- cout << endl<< endl;
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement