fork download
  1. #include<iostream>
  2.  
  3. struct bottle
  4. {
  5. int x = 0 ;
  6. int y = 0 ;
  7. // ....
  8. };
  9.  
  10. std::ostream& operator<< ( std::ostream& stm, const bottle& b )
  11. { return stm << '(' << b.x << ',' << b.y << ')' ; }
  12.  
  13. // adjust the values of these as required
  14. constexpr int NROWS = 8 ;
  15. constexpr int NCOLS = 6 ;
  16. constexpr int start_x = 25 ;
  17. constexpr int start_y = 15 ;
  18. constexpr int delta_x = 8 ;
  19. constexpr int delta_y = 11 ;
  20.  
  21. using bottle_array_type = bottle[NROWS][NCOLS] ;
  22. // typedef bottle bottle_array_type[NROWS][NCOLS] ;
  23.  
  24. void initialize_bottle_array( bottle_array_type& bottle_array )
  25. {
  26. for( int row = 0 ; row < NROWS ; ++row )
  27. for( int col = 0 ; col < NCOLS ; ++col )
  28. {
  29. bottle_array[row][col].x = start_x + col * delta_x ;
  30. bottle_array[row][col].y = start_y + row * delta_y ;
  31. }
  32. }
  33.  
  34. int main()
  35. {
  36. bottle_array_type bottle_array ;
  37. initialize_bottle_array(bottle_array) ;
  38. for( const auto& row : bottle_array )
  39. {
  40. for( const bottle& b : row ) std::cout << b << ' ' ;
  41. std::cout << '\n' ;
  42. }
  43. }
  44.  
Success #stdin #stdout 0s 2852KB
stdin
Standard input is empty
stdout
(25,15) (33,15) (41,15) (49,15) (57,15) (65,15) 
(25,26) (33,26) (41,26) (49,26) (57,26) (65,26) 
(25,37) (33,37) (41,37) (49,37) (57,37) (65,37) 
(25,48) (33,48) (41,48) (49,48) (57,48) (65,48) 
(25,59) (33,59) (41,59) (49,59) (57,59) (65,59) 
(25,70) (33,70) (41,70) (49,70) (57,70) (65,70) 
(25,81) (33,81) (41,81) (49,81) (57,81) (65,81) 
(25,92) (33,92) (41,92) (49,92) (57,92) (65,92)