Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <vector>
- #include "TComplex.h"
- #include "TComplexProcessor.h"
- using namespace std;
- int main()
- {
- TComplexProcessor proc();
- TComplexProcessor obg;
- int n = 0;
- cin >> n;
- obg._input();
- obg._plus();
- system("pause");
- return 0;
- }
- #pragma once
- #ifndef _TCOMPLEXPROCESSOR_
- #define _TCOMPLEXPROCESSOR_
- #include <vector>
- #include "TComplex.h"
- using namespace std;
- class TComplexProcessor
- {
- private:
- vector<TComplex> v1;
- vector<TComplex> v2;
- public:
- TComplexProcessor();
- void _input();
- vector<TComplex> _plus();
- ~TComplexProcessor();
- };
- #endif
- #include <vector>
- #include <iostream>
- #include <iomanip>
- #include "TComplexProcessor.h"
- #include "TComplex.h"
- using namespace std;
- TComplexProcessor::TComplexProcessor()
- {
- v1.resize(2);
- v2.resize(2);
- }
- void TComplexProcessor::_input()
- {
- for (int i = 0; i<v1.size(); i++)
- {
- v1[i].set_vvod();
- v2[i].set_vvod();
- }
- }
- vector<TComplex> TComplexProcessor::_plus()
- {
- vector<TComplex> v3;
- for (int i = 0; i<v1.size(); i++)
- {
- v3[i] = v1[i] + v2[i];
- }
- for (int i = 0; i<v1.size(); i++)
- {
- cout << v1[i] << " ;" << v2[i] << " ;" << v3[i];
- }
- return v3;
- }
- TComplexProcessor::~TComplexProcessor()
- {
- }
- #pragma once
- #ifndef _TCOMPLEX_
- #define _TCOMPLEX_
- #include <iostream>
- class TComplex
- {
- private:
- double re, im;
- public:
- TComplex();
- void set_vvod();
- TComplex operator +(TComplex t);
- TComplex operator -(TComplex p);
- TComplex operator *(TComplex f);
- TComplex operator / (TComplex g);
- friend std::ostream &operator <<(std::ostream &out, const TComplex &obg)
- {
- out << obg.im << "+" << obg.re << "*i";
- return out;
- }
- ~TComplex();
- };
- #endif
- #include "TComplex.h"
- #include <iostream>
- using namespace std;
- TComplex::TComplex()
- {
- re = 0.0;
- im = 0.0;
- }
- void TComplex::set_vvod()
- {
- cin >> re >> im;
- }
- TComplex TComplex::operator +(TComplex t)
- {
- TComplex c;
- c.re = re + t.re;
- c.im = im + t.im;
- return c;
- }
- TComplex TComplex::operator -(TComplex t)
- {
- TComplex o;
- o.re = re - t.re;
- o.im = im - t.im;
- return o;
- }
- TComplex TComplex::operator *(TComplex t)
- {
- TComplex d;
- d.re = (re*t.re) - (im*t.im);
- d.im = (re*t.re) + (im*t.im);
- return d;
- }
- TComplex TComplex::operator / (TComplex t)
- {
- TComplex h;
- h.re = (re*t.re + im * t.im) / (t.re*t.re + t.im*t.im);
- h.im = (t.re*im - re * t.im) / (t.re*t.re + t.im*t.im);
- return h;
- }
- TComplex::~TComplex()
- {
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement