Advertisement
Guest User

Untitled

a guest
Dec 8th, 2019
110
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.48 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==II);
  86. }
  87. friend bool operator<(Complex& I, Complex& II){
  88. if(I.x == II.x){
  89. return I.y < II.y;
  90. }
  91. else
  92. return I.x < II.x;
  93. }
  94. friend bool operator>(Complex& I, Complex& II){
  95. if(I.x == II.x){
  96. return I.y > II.y;
  97. }
  98. else
  99. return I.x > II.x;
  100. }
  101. friend bool operator<=(Complex& I, Complex& II){
  102. return (I == II) || (I<II);
  103. }
  104. friend bool operator>=(Complex& I, Complex& II){
  105. return (I == II) || (I>II) ;
  106. }
  107.  
  108. Complex& operator=(const Complex& ref){
  109. x = ref.x;
  110. y = ref.y;
  111. return *this;
  112. }
  113. friend ostream& operator<<(ostream& out,Complex& II){
  114. out << II.get_x() << " + " <<II.get_y() << "i"<<endl;
  115. return out;
  116. }
  117. float modul(){
  118. return sqrt(x*x+y*y);
  119. }
  120.  
  121. };
  122. }
  123.  
  124. void sort(Patrik::Complex A[]){
  125. for(int i=0;i<9;i++){
  126. for(int j=0;j<10-1-i;j++){
  127. if(A[j] > A[j+1]){
  128. Patrik::Complex temp =A[j];
  129. A[j] = A[j+1];
  130. A[j+1] = temp;
  131. }
  132. }
  133.  
  134. }
  135. }
  136.  
  137.  
  138. void sort(Juzbasic::Complex A[]){
  139. for(int i=0;i<9;i++){
  140. for(int j=0;j<10-1-i;j++){
  141. if(A[j] > A[j+1]){
  142. Juzbasic::Complex temp =A[j];
  143. A[j] = A[j+1];
  144. A[j+1] = temp;
  145. }
  146. }
  147.  
  148. }
  149. }
  150.  
  151.  
  152.  
  153.  
  154.  
  155.  
  156. int main(){
  157. srand((unsigned)time(NULL));
  158. Patrik::Complex a[10];
  159. Juzbasic::Complex b[10];
  160. for(int i=0;i<10;i++){
  161. int X =1+ rand()/(RAND_MAX/100);
  162. int Y =1+ rand()/(RAND_MAX/100);
  163. b[i].set_x(X);
  164. b[i].set_y(Y);
  165. a[i].set_x(X);
  166. a[i].set_y(Y);
  167. }
  168. for(int i =0;i<10;i++){
  169. cout <<a[i];
  170. }
  171. sort(a);
  172. cout<<endl;
  173. cout<<endl;
  174. cout<<endl;
  175. for(int i =0;i<10;i++){
  176. cout <<a[i];
  177. }
  178. cout<<endl;
  179.  
  180. for(int i =0;i<10;i++){
  181. cout <<b[i];
  182. }
  183. sort(b);
  184. cout<<endl;
  185. cout<<endl;
  186. cout<<endl;
  187. for(int i =0;i<10;i++){
  188. cout <<b[i];
  189. }
  190.  
  191.  
  192. return 0;
  193. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement