Advertisement
pieniakoskar

Odcinek

Mar 19th, 2018
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.05 KB | None | 0 0
  1. #include "stdafx.h"
  2.  
  3. #include <string>
  4. #include <iostream>
  5. #include <math.h>
  6.  
  7. using namespace std;
  8.  
  9. class CLinia
  10. {
  11. int x1, y1, x2, y2;
  12.  
  13. public:
  14. CLinia(const int X1=0, const int Y1=0, const int X2=0, const int Y2=0);
  15. CLinia(const CLinia & l);
  16.  
  17. CLinia & operator += (const int d);
  18. CLinia & operator -= (const int d);
  19.  
  20. operator double();
  21. operator string();
  22. friend ostream & operator << (ostream &o, CLinia &l);
  23.  
  24. bool operator == (const CLinia &l);
  25. bool operator != (const CLinia &l);
  26.  
  27. bool operator < (const CLinia &l);
  28. bool operator > (const CLinia &l);
  29. bool operator <= (const CLinia &l);
  30. bool operator >= (const CLinia &l);
  31. };
  32.  
  33. CLinia::CLinia(const int X1, const int Y1, const int X2, const int Y2):
  34. x1(X1), y1(Y1), x2(X2), y2(Y2) {}
  35.  
  36. CLinia::CLinia(const CLinia & l):
  37. x1(l.x1), y1(l.y1), x2(l.x2), y2(l.y2) {}
  38.  
  39. CLinia & CLinia::operator += (const int d)
  40. {
  41. x2+=d;
  42. y2+=d;
  43. return *this;
  44. }
  45. CLinia & CLinia::operator -= (const int d)
  46. {
  47. x2-=d;
  48. y2-=d;
  49. return *this;
  50. }
  51.  
  52. CLinia::operator double()
  53. {
  54. double kw = ((x2-x1)*(x2-x1)) + ((y2-y1)*(y2-y1));
  55. return sqrt(kw);
  56. }
  57. CLinia::operator string()
  58. {
  59. char buf[32];
  60. sprintf(buf, "Operator string: (%d,%d) - (%d,%d)",x1, y1, x2, y2);
  61. return buf;
  62. }
  63. ostream & operator << (ostream &o, CLinia &l)
  64. {
  65. return o << "Operator <<: (" << l.x1 << "," << l.y1 << ") - (" << l.x2 << "," << l.y2 << ")";
  66. }
  67.  
  68. bool CLinia::operator == (const CLinia &l)
  69. {
  70. if( x1==l.x1 && x2==l.x2 && y1==l.y1 && y2==l.y2 ) return 1;
  71. return 0;
  72. }
  73. bool CLinia::operator != (const CLinia &l)
  74. {
  75. if( x1!=l.x1 || x2!=l.x2 || y1!=l.y1 || y2!=l.y2 ) return 1;
  76. return 0;
  77. }
  78.  
  79. bool CLinia::operator < (const CLinia &l)
  80. {
  81. double kw1 = ((x2-x1)*(x2-x1)) + ((y2-y1)*(y2-y1));
  82. double kw2 = ((l.x2-l.x1)*(l.x2-l.x1)) + ((l.y2-l.y1)*(l.y2-l.y1));
  83. double d1 = sqrt(kw1);
  84. double d2 = sqrt(kw2);
  85. return d1<d2;
  86. }
  87. bool CLinia::operator > (const CLinia &l)
  88. {
  89. double kw1 = ((x2-x1)*(x2-x1)) + ((y2-y1)*(y2-y1));
  90. double kw2 = ((l.x2-l.x1)*(l.x2-l.x1)) + ((l.y2-l.y1)*(l.y2-l.y1));
  91. double d1 = sqrt(kw1);
  92. double d2 = sqrt(kw2);
  93. return d1>d2;
  94. }
  95. bool CLinia::operator <= (const CLinia &l)
  96. {
  97. double kw1 = ((x2-x1)*(x2-x1)) + ((y2-y1)*(y2-y1));
  98. double kw2 = ((l.x2-l.x1)*(l.x2-l.x1)) + ((l.y2-l.y1)*(l.y2-l.y1));
  99. double d1 = sqrt(kw1);
  100. double d2 = sqrt(kw2);
  101. return d1<=d2;
  102. }
  103. bool CLinia::operator >= (const CLinia &l)
  104. {
  105. double kw1 = ((x2-x1)*(x2-x1)) + ((y2-y1)*(y2-y1));
  106. double kw2 = ((l.x2-l.x1)*(l.x2-l.x1)) + ((l.y2-l.y1)*(l.y2-l.y1));
  107. double d1 = sqrt(kw1);
  108. double d2 = sqrt(kw2);
  109. return d1>=d2;
  110. }
  111.  
  112. int _tmain(int argc, _TCHAR* argv[])
  113. {
  114. CLinia a(1,2,3,4);
  115. cout << a << "\n";
  116. cout << (string)a << "\n";
  117.  
  118. CLinia b(a);
  119. if(a==b) cout << "a rowne b\n";
  120. else cout << "a rozne od b\n\n";
  121.  
  122. b+=3;
  123. if(a==b) cout << "a rowne b\n";
  124. else cout << "a rozne od b\n\n";
  125.  
  126. b-=3;
  127. if(a==b) cout << "a rowne b\n";
  128. else cout << "a rozne od b\n\n";
  129.  
  130. //a+=1;
  131. if(a>b) cout << "a wieksze od b\n";
  132. else cout << "a mniejsze od b";
  133.  
  134. cin.get();
  135. return 0;
  136. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement