-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcomplex.cpp
More file actions
107 lines (93 loc) · 2.56 KB
/
complex.cpp
File metadata and controls
107 lines (93 loc) · 2.56 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
#include "stdafx.h"
#include "complex.h"
using namespace std;
/////////////////////////////////////////////////////////////////////////
void print_error()
{
cout << "Error, this symbol is not supported" << endl;
}
void print_menu(char select)
{
cout << "Enter operation" << endl;
cout << "------------------------" << endl;
cout << "'+' Sum" << endl;
cout << "'-' Substraction" << endl;
cout << "'*' Division" << endl;
cout << "'/' Multiplication" << endl;
cout << "'M' or 'm' Modulo of complex number" << endl;
cout << "------------------------" << endl;
}
void entercomplex()
{
setlocale(LC_ALL, "ru");
cout << "Enter 1st and 2nd complex numbers, real imag: ";
}
ComplexMain::ComplexMain(double real, double imag)
{
this->real = real;
this->imag = imag;
}
ComplexMain::~ComplexMain() // Деструктор класса Complex
{
}
// Перегрузка операторов
Complex Complex::operator =(const Complex & other)
{
this->real = other.real;
this->imag = other.imag;
return other;
}
Complex Complex::operator + ( Complex &other)
{
Complex temp;
temp.real = this->real + other.real;
temp.imag = this->imag + other.imag;
return temp;
}
Complex Complex::operator - (Complex & other)
{
Complex temp;
temp.real = this->real - other.real;
temp.imag = this->imag - other.imag;
return temp;
}
Complex Complex::operator * (Complex & other)
{
Complex temp;
temp.real = (this->real * other.real - this->imag * other.imag);
temp.imag = (this->real * other.imag + other.real * this->imag);
return temp;
}
Complex Complex::operator / (Complex & other)
{
Complex temp;
temp.real = ( (this->real*other.real + this->imag*other.imag) / (other.real*other.real + other.imag*other.imag) );
temp.imag = ( (this->imag*other.real - this->real*other.imag) / (other.real*other.real + other.imag*other.imag) );
return temp;
}
ostream& operator <<(ostream & os, Complex &other)
{
os << "Real: " << other.real << endl;
os << "Imagine: " << other.imag << endl;
os << "Complex number is: (" << other.real << ';' << other.imag << "i)" << endl;
return os;
}
istream & operator >> (istream & os, Complex & other)
{
os >> other.real >> other.imag;
return os;
}
// Определение методов производного класса ComplexNew
ComplexNew::ComplexNew()
{
this->mod = 0.0;
}
ComplexNew::~ComplexNew()
{
}
double ComplexNew::complexModulo(ComplexNew a)
{
mod = sqrt(pow(a.real, 2) + pow(a.imag, 2));
cout << "Modulo is: " << mod << endl;
return mod;
}