Advertisement
liza271099l

Untitled

Jun 14th, 2018
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.43 KB | None | 0 0
  1. #include <iostream>
  2. #include <vector>
  3. #include "TComplex.h"
  4. #include "TComplexProcessor.h"
  5. using namespace std;
  6. int main()
  7. {
  8.     TComplexProcessor proc();
  9.     TComplexProcessor obg;
  10.     int n = 0;
  11.     cin >> n;
  12.     obg._input();
  13.     obg._plus();
  14.     system("pause");
  15.     return 0;
  16. }
  17. #pragma once
  18. #ifndef _TCOMPLEXPROCESSOR_
  19. #define _TCOMPLEXPROCESSOR_
  20. #include <vector>
  21. #include "TComplex.h"
  22. using namespace std;
  23. class TComplexProcessor
  24. {
  25. private:
  26.     vector<TComplex> v1;
  27.     vector<TComplex> v2;
  28. public:
  29.     TComplexProcessor();
  30.     void _input();
  31.     vector<TComplex> _plus();
  32.     ~TComplexProcessor();
  33. };
  34.  
  35. #endif
  36. #include <vector>
  37. #include <iostream>
  38. #include <iomanip>
  39. #include "TComplexProcessor.h"
  40. #include "TComplex.h"
  41. using namespace std;
  42. TComplexProcessor::TComplexProcessor()
  43. {
  44.     v1.resize(2);
  45.     v2.resize(2);
  46. }
  47. void TComplexProcessor::_input()
  48. {
  49.     for (int i = 0; i<v1.size(); i++)
  50.     {
  51.         v1[i].set_vvod();
  52.         v2[i].set_vvod();
  53.     }
  54. }
  55. vector<TComplex> TComplexProcessor::_plus()
  56. {
  57.     vector<TComplex> v3;
  58.     for (int i = 0; i<v1.size(); i++)
  59.     {
  60.         v3[i] = v1[i] + v2[i];
  61.     }
  62.     for (int i = 0; i<v1.size(); i++)
  63.     {
  64.         cout << v1[i] << " ;" << v2[i] << " ;" << v3[i];
  65.     }
  66.     return v3;
  67. }
  68.  
  69. TComplexProcessor::~TComplexProcessor()
  70. {
  71. }
  72. #pragma once
  73. #ifndef _TCOMPLEX_
  74. #define _TCOMPLEX_
  75. #include <iostream>
  76. class TComplex
  77. {
  78. private:
  79.     double re, im;
  80. public:
  81.     TComplex();
  82.     void set_vvod();
  83.     TComplex operator +(TComplex t);
  84.     TComplex operator -(TComplex p);
  85.     TComplex operator *(TComplex f);
  86.     TComplex operator / (TComplex g);
  87.     friend std::ostream &operator <<(std::ostream &out, const TComplex &obg)
  88.     {
  89.         out << obg.im << "+" << obg.re << "*i";
  90.         return out;
  91.     }
  92.     ~TComplex();
  93. };
  94.  
  95. #endif
  96. #include "TComplex.h"
  97. #include <iostream>
  98. using namespace std;
  99. TComplex::TComplex()
  100. {
  101.     re = 0.0;
  102.     im = 0.0;
  103. }
  104. void TComplex::set_vvod()
  105. {
  106.     cin >> re >> im;
  107. }
  108. TComplex TComplex::operator +(TComplex t)
  109. {
  110.     TComplex c;
  111.         c.re = re + t.re;
  112.         c.im = im + t.im;
  113.         return c;
  114. }
  115. TComplex TComplex::operator -(TComplex t)
  116. {
  117.     TComplex o;
  118.     o.re = re - t.re;
  119.     o.im = im - t.im;
  120.     return o;
  121. }
  122. TComplex TComplex::operator *(TComplex t)
  123. {
  124.     TComplex d;
  125.     d.re = (re*t.re) - (im*t.im);
  126.     d.im = (re*t.re) + (im*t.im);
  127.     return d;
  128. }
  129. TComplex TComplex::operator / (TComplex t)
  130. {
  131.     TComplex h;
  132.     h.re = (re*t.re + im * t.im) / (t.re*t.re + t.im*t.im);
  133.     h.im = (t.re*im - re * t.im) / (t.re*t.re + t.im*t.im);
  134.     return h;
  135. }
  136.  
  137. TComplex::~TComplex()
  138. {
  139. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement