Advertisement
avr39ripe

BV024structExample

Jan 28th, 2021
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.20 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. struct Test
  4. {
  5.     int id;
  6.     bool flag;
  7. };
  8.  
  9. struct Point
  10. {
  11.     int x;
  12.     int y;
  13. };
  14.  
  15. //printPoint(pOne);
  16. void printPoint(const Point& pnt)
  17. {
  18.     std::cout << "(" << pnt.x << "," << pnt.y << ")" << '\n';
  19. }
  20.  
  21. void printPoint(const Point& pntOne, const Point& pntTwo)
  22. {
  23.     std::cout << "(" << pntOne.x << "," << pntOne.y << ")" << '\t';
  24.     std::cout << "(" << pntTwo.x << "," << pntTwo.y << ")" << '\n';
  25. }
  26.  
  27.  
  28. Point generatePoint()
  29. {
  30.     Point pnt;
  31.     pnt.x = rand() % 100;
  32.     pnt.y = rand() % 100;
  33.  
  34.     return pnt;
  35. }
  36.  
  37.  
  38. int main()
  39. {
  40.     int a{ 3 };
  41.     int b{ a };
  42.  
  43.     Point pOne{ 1,2}; // pOne.x = 1 pOne.y = 2
  44.  
  45.     Point pTwo{ pOne }; // pTwo.x = 1 pTwo.y = 2
  46.     pTwo.x = 555;
  47.  
  48.  
  49.     Point* ptrPoint{nullptr};
  50.  
  51.     ptrPoint = new Point[2]{ {11,22},{33,44} };
  52.  
  53.  
  54.     Point& refPoint{ pOne };
  55.  
  56.     refPoint.x = 333;
  57.  
  58.     //std::cout << "pOne.x = " << pOne.x << " pOne.y = " << pOne.y << '\n';
  59.     printPoint(pOne);
  60.     // ??? :)
  61.     printPoint(pOne);
  62.  
  63.     Point pntTree{ generatePoint() };
  64.  
  65.     printPoint(pntTree);
  66.  
  67.     printPoint(pOne, pntTree);
  68.  
  69.     std::cout << "ptrPoint->x = " << ptrPoint[1].x << " ptrPoint->y = " << ptrPoint[1].y << '\n';
  70.     /*pOne.x = 10;
  71.     pOne.y = 10;*/
  72.  
  73.     delete[] ptrPoint;
  74.  
  75.     return 0;
  76. }
  77.  
  78.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement