Advertisement
Guest User

Untitled

a guest
Mar 19th, 2019
57
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.29 KB | None | 0 0
  1. /******************************************************************************
  2.  
  3. Online C++ Compiler.
  4. Code, Compile, Run and Debug C++ program online.
  5. Write your code in this editor and press "Run" button to compile and execute it.
  6.  
  7. *******************************************************************************/
  8.  
  9. #include <iostream>
  10. #include <cmath>
  11. #include<vector>
  12. #include<algorithm>
  13.  
  14. using namespace std;
  15.  
  16. struct PositionVector {
  17.  
  18. double x, y;
  19. PositionVector(){x=0;y=0;};
  20.  
  21. PositionVector(double a, double b)
  22. {
  23. x=a;
  24. y=b;
  25. };
  26.  
  27. PositionVector(const PositionVector& v1)
  28. {
  29. x=v1.x;
  30. y=v1.y;
  31. };
  32.  
  33. double norm() const
  34. {
  35. return sqrt(x*x+y*y);
  36. };
  37.  
  38. void print() const
  39. {
  40. cout<<"koordinate: "<<x<<","<<y<<endl;
  41. cout<<"norma: "<<norm()<<endl;
  42. };
  43.  
  44.  
  45. };
  46.  
  47. bool sort1(PositionVector v1, PositionVector v2)
  48. {
  49. if(v1.norm()>v2.norm())
  50. {return true;}
  51. else
  52. {
  53. return false;
  54. }
  55. }
  56.  
  57.  
  58. int main()
  59. {
  60.  
  61. PositionVector v[5];
  62. v[0]=PositionVector (2.5, 3.6);
  63. v[1]=PositionVector (5.5, 3.6);
  64. v[2]=PositionVector (4.4, 4.4);
  65. v[3]=PositionVector (10.0, 0.1);
  66. v[4]=PositionVector (0.0, 0.0);
  67. for(PositionVector i:v)
  68. i.print();
  69.  
  70. sort(v,v+5,sort1);
  71. for(PositionVector i:v)
  72. i.print();
  73. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement