fork download
  1. #include <random>
  2. #include <iostream>
  3.  
  4. struct cSystem
  5. {
  6. cSystem();
  7.  
  8. double sPositionX;
  9. double sPositionY;
  10. double sMass;
  11.  
  12. static std::uniform_real_distribution<double> unif;
  13. static std::default_random_engine re;
  14. };
  15.  
  16. std::uniform_real_distribution<double> cSystem::unif(-100, 100);
  17. std::default_random_engine cSystem::re;
  18.  
  19. //Constructor
  20. cSystem::cSystem()
  21. {
  22. /*Initialization of data members*/
  23. sMass=1.0014;
  24. sPositionX= unif(re);
  25. sPositionY= unif(re);
  26. }
  27.  
  28. void getPositions(cSystem* systems)
  29. {
  30. for (unsigned i = 0; i < 3; ++i )
  31. {
  32. std::cout << systems[i].sPositionX << " " << systems[i].sPositionY << std::endl;
  33. }
  34. }
  35.  
  36. int main (void)
  37. {
  38. cSystem systems[3];
  39.  
  40. getPositions(systems);
  41.  
  42. return 0;
  43. }
  44.  
Success #stdin #stdout 0s 4436KB
stdin
Standard input is empty
stdout
-73.6924 -8.26997
-56.2082 35.7729
86.9386 3.88327