Advertisement
Guest User

Untitled

a guest
Dec 8th, 2019
105
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.49 KB | None | 0 0
  1. #include <iostream>
  2. using namespace std;
  3. #include<cmath>
  4. #include<cstdlib>
  5. #include<ctime>
  6.  
  7. namespace Patrik
  8. {
  9. class Complex{
  10. private:
  11. int x,y;
  12. public:
  13. Complex():x(1),y(1){}
  14. Complex(int a,int b):x(a),y(b){}
  15. int get_x(){
  16. return x;
  17. }
  18. int get_y(){
  19. return y;
  20. }
  21. void set_x(int a){
  22. x = a;
  23. }
  24. void set_y(int a){
  25. y = a;
  26. }
  27. float modul(){
  28. return sqrt(x*x+y*y);
  29. }
  30. friend bool operator==( Complex& I, Complex& II){
  31. return I.modul() == II.modul();
  32. }
  33. friend bool operator!=(Complex& I, Complex& II){
  34. return I.modul() != II.modul();
  35. }
  36. friend bool operator<=(Complex& I, Complex& II){
  37. return I.modul() <= II.modul();
  38. }
  39. friend bool operator>=(Complex& I, Complex& II){
  40. return I.modul() >= II.modul();
  41. }
  42. friend bool operator<(Complex& I, Complex& II){
  43. return I.modul() < II.modul();
  44. }
  45. friend bool operator>(Complex& I, Complex& II){
  46. return I.modul() > II.modul();
  47. }
  48. Complex& operator=(const Complex& ref){
  49. x = ref.x;
  50. y = ref.y;
  51. return *this;
  52. }
  53. friend ostream& operator<<(ostream& out,Complex& II){
  54. out << II.get_x() << " + " <<II.get_y() << "i"<<endl;
  55. return out;
  56. }
  57.  
  58.  
  59. };
  60. }
  61. namespace Juzbasic
  62. {
  63. class Complex{
  64. private:
  65. int x,y;
  66. public:
  67. Complex():x(1),y(1){}
  68. Complex(int a,int b):x(a),y(b){}
  69. int get_x(){
  70. return x;
  71. }
  72. int get_y(){
  73. return y;
  74. }
  75. void set_x(int a){
  76. x = a;
  77. }
  78. void set_y(int a){
  79. y = a;
  80. }
  81. friend bool operator==( Complex& I, Complex& II){
  82. return I.x == II.x && I.y == II.y;
  83. }
  84. friend bool operator!=(Complex& I, Complex& II){
  85. return !(I.x == II.x && I.y == II.y);
  86. }
  87. friend bool operator<=(Complex& I, Complex& II){
  88. return (I.x == II.x && I.y == II.y) || (I.x < II.x && I.y < II.y) ;
  89. }
  90. friend bool operator>=(Complex& I, Complex& II){
  91. return (I.x == II.x && I.y == II.y) || (I.x > II.x && I.y > II.y) ;
  92. }
  93. friend bool operator<(Complex& I, Complex& II){
  94. return (I.x < II.x && I.y < II.y);
  95. }
  96. friend bool operator>(Complex& I, Complex& II){
  97. return (I.x > II.x && I.y > II.y);
  98. }
  99. Complex& operator=(const Complex& ref){
  100. x = ref.x;
  101. y = ref.y;
  102. return *this;
  103. }
  104. friend ostream& operator<<(ostream& out,Complex& II){
  105. out << II.get_x() << " + " <<II.get_y() << "i"<<endl;
  106. return out;
  107. }
  108. float modul(){
  109. return sqrt(x*x+y*y);
  110. }
  111.  
  112. };
  113. }
  114.  
  115. void sort(Patrik::Complex A[]){
  116. for(int i=0;i<9;i++){
  117. for(int j=0;j<10-1-i;j++){
  118. if(A[j] > A[j+1]){
  119. Patrik::Complex temp =A[j];
  120. A[j] = A[j+1];
  121. A[j+1] = temp;
  122. }
  123. }
  124.  
  125. }
  126. }
  127.  
  128.  
  129. void sort(Juzbasic::Complex A[]){
  130. for(int i=0;i<9;i++){
  131. for(int j=0;j<10-1-i;j++){
  132. if(A[j] > A[j+1]){
  133. Juzbasic::Complex temp =A[j];
  134. A[j] = A[j+1];
  135. A[j+1] = temp;
  136. }
  137. }
  138.  
  139. }
  140. }
  141.  
  142.  
  143.  
  144.  
  145.  
  146.  
  147. int main(){
  148. srand((unsigned)time(NULL));
  149. Patrik::Complex a[10];
  150. Juzbasic::Complex b[10];
  151. for(int i=0;i<10;i++){
  152. int X =1+ rand()/(RAND_MAX/100);
  153. int Y =1+ rand()/(RAND_MAX/100);
  154. b[i].set_x(X);
  155. b[i].set_y(Y);
  156. a[i].set_x(X);
  157. a[i].set_y(Y);
  158. }
  159. for(int i =0;i<10;i++){
  160. cout <<a[i];
  161. }
  162. sort(a);
  163. cout<<endl;
  164. cout<<endl;
  165. cout<<endl;
  166. for(int i =0;i<10;i++){
  167. cout <<a[i];
  168. }
  169. cout<<endl;
  170.  
  171. for(int i =0;i<10;i++){
  172. cout <<b[i];
  173. }
  174. sort(b);
  175. cout<<endl;
  176. cout<<endl;
  177. cout<<endl;
  178. for(int i =0;i<10;i++){
  179. cout <<b[i];
  180. }
  181.  
  182.  
  183. return 0;
  184. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement