Advertisement
Art_Uspen

Untitled

Feb 21st, 2021
162
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.40 KB | None | 0 0
  1. #include <algorithm>
  2. #include <iostream>
  3. #include <fstream>
  4. #include <cmath>
  5. #include <tuple>
  6. #include <set>
  7. #include <unordered_map>
  8. #include <vector>
  9. #include <string>
  10.  
  11. class Complex {
  12. private:
  13.     double re;
  14.     double im;
  15. public:
  16.     explicit Complex(double re_ = 0., double im_ = 0.) : re(re_), im(im_) {
  17.         std::cout << re<<".....";
  18.         std::cout << im;
  19.     }
  20.  
  21.     double get_re() const {
  22.         return re;
  23.     }
  24.  
  25.     double get_im() const {
  26.         return im;
  27.     }
  28.  
  29.     double &Re() {
  30.         return re;
  31.     }
  32.  
  33.     double &Im() {
  34.         return im;
  35.     }
  36.  
  37.     Complex operator-() const;
  38.  
  39.     Complex operator+() const;
  40.  
  41. };
  42.  
  43. Complex operator+(const Complex &first, const Complex &second) {
  44.     return Complex(first.get_re() + second.get_re(), first.get_im() + second.get_im());
  45. }
  46.  
  47. Complex operator-(const Complex &first, const Complex &second) {
  48.     return Complex(first.get_re() - second.get_re(), first.get_im() - second.get_im());
  49. }
  50.  
  51. Complex operator*(const Complex &first, const Complex &second) {
  52.     auto a1 = first.get_re();
  53.     auto a2 = second.get_re();
  54.     auto b1 = first.get_im();
  55.     auto b2 = second.get_im();
  56.     return Complex(a1 * a2 - b1 * b2, a1 * b2 + b1 * a2);
  57. }
  58.  
  59. Complex operator/(const Complex &first, const Complex &second) {
  60.     auto a1 = first.get_re();
  61.     auto a2 = second.get_re();
  62.     auto b1 = first.get_im();
  63.     auto b2 = second.get_im();
  64.     auto _ = (a2 * b1 - a1 * b2) / (std::pow(a2, 2) + std::pow(b2, 2));
  65.     (void) _;
  66.     return Complex((a1 * a2 + b1 * b2) / (std::pow(a2, 2) + std::pow(b2, 2)),
  67.                    (a2 * b1 - a1 * b2) / (std::pow(a2, 2) + std::pow(b2, 2)));
  68. }
  69.  
  70. Complex Complex::operator-() const {
  71.     return Complex(-re, -im);
  72. }
  73.  
  74. Complex Complex::operator+() const {
  75.     return Complex(re, im);
  76. }
  77.  
  78. double Abs(const Complex &curr) {
  79.     return std::pow(curr.get_re(), 2) + std::pow(curr.get_im(), 2);
  80. }
  81.  
  82. bool operator==(const Complex &first, const Complex &second) {
  83.     return (first.get_re() == second.get_re() && first.get_im() == second.get_im());
  84. }
  85.  
  86. bool operator!=(const Complex &first, const Complex &second) {
  87.     return (first.get_re() != second.get_re() || first.get_im() != second.get_im());
  88. }
  89.  
  90. int main() {
  91.     std::fstream fout("output.txt");
  92.     Complex first(10,0);
  93.     Complex second(5,0);
  94.  
  95.     fout << (first / second).get_im() << "......" << (first/second).get_re();
  96. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement