Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <math.h>
- #include <iostream>
- #include <stdio.h>
- #include <fstream>
- using namespace std;
- class Complex
- {
- double Re;
- double Im;
- public: //конструкторы
- Complex() {};
- Complex(double r) // конструктор по умолчанию 1
- {
- Re = r;
- Im = 0;
- }
- Complex(double r, double i) // конструктор по умолчанию 2
- {
- Re = r;
- Im = i;
- }
- double first() const {
- return Re;
- }
- double second() const {
- return Im;
- }
- Complex(const Complex &sec) // конструктор копирования
- {
- Re = sec.Re;
- Im = sec.Im;
- }
- ~Complex() {}
- double abs() // Модуль комплексного числа
- {
- return sqrt(Re * Re + Im * Im);
- }
- Complex& operator = (Complex &sec) // перегрузка оператора присваивания
- {
- Re = sec.Re;
- Im = sec.Im;
- return (*this);
- }
- Complex operator + (const Complex &sec) // перегрузка оператора сложения
- {
- Complex result(Re + sec.Re, Im + sec.Im);
- return result;
- }
- Complex operator - (const Complex &sec) // перегрузка оператора вычитания
- {
- Complex result(Re - sec.Re, Im - sec.Im);
- return result;
- }
- Complex operator * (const Complex &sec) // оператор умножения
- {
- Complex result(Re * sec.Re - Im * sec.Im, Re * sec.Im + Im * sec.Re);
- return result;
- }
- Complex operator / (Complex &sec) // перегрузка оператора деления
- {
- Complex result;
- double r = sec.Re * sec.Re + sec.Im * sec.Im;
- result.Re = (Re * sec.Re + Im * sec.Im) / r;
- result.Re = (Im * sec.Re - Re * sec.Im) / r;
- return result;
- }
- bool operator == (Complex & sec)
- {
- if ((this->Re == sec.Re) && (this->Im == sec.Im))
- {
- return true;
- }
- return false;
- }
- bool operator != (Complex & sec)
- {
- if ((this->Re == sec.Re) && (this->Im == sec.Im))
- {
- return false;
- }
- return true;
- }
- };
- int main() {
- Complex i(0, 1);
- ifstream input("input.txt");
- double k = 0;
- double l = 0;
- input >> k;
- input >> l;
- Complex a(k, l);
- double x = a.first; // Re
- double y = a.second; //Im
- input >> k;
- input >> l;
- Complex b(k, l);
- double x = b.first; // Re
- double y = b.second; //Im
- input >> k;
- input >> l;
- Complex c(k, l);
- double x = c.first; // Re
- double y = c.second; //Im
- input >> k;
- input >> l;
- Complex d(k, l);
- double x = d.first; // Re
- double y = d.second; //Im
- input.close();
- Complex p;
- p = (a*b - c*d) + (a.abs()*a.abs() + i*d.abs()*d.abs()) + c*(b.abs()*b.abs() + i);
- ofstream output("output.txt");
- output << p.Re << " " << p.Im;
- output.close();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement