Advertisement
Guest User

Untitled

a guest
Oct 1st, 2016
55
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.71 KB | None | 0 0
  1. #include <math.h>
  2. #include <iostream>
  3. #include <stdio.h>
  4. #include <fstream>
  5.  
  6. using namespace std;
  7.  
  8.  
  9. class Complex
  10. {
  11. double Re;
  12. double Im;
  13. public: //конструкторы
  14. Complex() {};
  15.  
  16. Complex(double r) // конструктор по умолчанию 1
  17. {
  18. Re = r;
  19. Im = 0;
  20. }
  21.  
  22. Complex(double r, double i) // конструктор по умолчанию 2
  23. {
  24. Re = r;
  25. Im = i;
  26. }
  27.  
  28. double first() const {
  29. return Re;
  30. }
  31. double second() const {
  32. return Im;
  33. }
  34.  
  35. Complex(const Complex &sec) // конструктор копирования
  36. {
  37. Re = sec.Re;
  38. Im = sec.Im;
  39. }
  40.  
  41. ~Complex() {}
  42.  
  43. double abs() // Модуль комплексного числа
  44. {
  45. return sqrt(Re * Re + Im * Im);
  46. }
  47.  
  48. Complex& operator = (Complex &sec) // перегрузка оператора присваивания
  49. {
  50. Re = sec.Re;
  51. Im = sec.Im;
  52. return (*this);
  53. }
  54.  
  55. Complex operator + (const Complex &sec) // перегрузка оператора сложения
  56. {
  57. Complex result(Re + sec.Re, Im + sec.Im);
  58. return result;
  59. }
  60.  
  61. Complex operator - (const Complex &sec) // перегрузка оператора вычитания
  62. {
  63. Complex result(Re - sec.Re, Im - sec.Im);
  64. return result;
  65. }
  66.  
  67. Complex operator * (const Complex &sec) // оператор умножения
  68. {
  69. Complex result(Re * sec.Re - Im * sec.Im, Re * sec.Im + Im * sec.Re);
  70. return result;
  71. }
  72.  
  73. Complex operator / (Complex &sec) // перегрузка оператора деления
  74. {
  75. Complex result;
  76.  
  77. double r = sec.Re * sec.Re + sec.Im * sec.Im;
  78. result.Re = (Re * sec.Re + Im * sec.Im) / r;
  79. result.Re = (Im * sec.Re - Re * sec.Im) / r;
  80.  
  81. return result;
  82. }
  83.  
  84. bool operator == (Complex & sec)
  85. {
  86. if ((this->Re == sec.Re) && (this->Im == sec.Im))
  87. {
  88. return true;
  89. }
  90. return false;
  91. }
  92.  
  93. bool operator != (Complex & sec)
  94. {
  95. if ((this->Re == sec.Re) && (this->Im == sec.Im))
  96. {
  97. return false;
  98. }
  99. return true;
  100. }
  101.  
  102. };
  103.  
  104. int main() {
  105. Complex i(0, 1);
  106. ifstream input("input.txt");
  107. double k = 0;
  108. double l = 0;
  109.  
  110. input >> k;
  111. input >> l;
  112.  
  113. Complex a(k, l);
  114. double x = a.first; // Re
  115. double y = a.second; //Im
  116.  
  117. input >> k;
  118. input >> l;
  119.  
  120. Complex b(k, l);
  121. double x = b.first; // Re
  122. double y = b.second; //Im
  123.  
  124. input >> k;
  125. input >> l;
  126.  
  127. Complex c(k, l);
  128. double x = c.first; // Re
  129. double y = c.second; //Im
  130.  
  131. input >> k;
  132. input >> l;
  133.  
  134. Complex d(k, l);
  135. double x = d.first; // Re
  136. double y = d.second; //Im
  137.  
  138. input.close();
  139. Complex p;
  140. p = (a*b - c*d) + (a.abs()*a.abs() + i*d.abs()*d.abs()) + c*(b.abs()*b.abs() + i);
  141. ofstream output("output.txt");
  142. output << p.Re << " " << p.Im;
  143. output.close();
  144. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement