-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcomplex.cpp
More file actions
108 lines (83 loc) · 2.51 KB
/
complex.cpp
File metadata and controls
108 lines (83 loc) · 2.51 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
108
#include "stdafx.h"
#include "complex.h"
#include <math.h>
#include <iostream>
using namespace std;
Complex::Complex() // ����������� ������
{
setlocale(LC_ALL, "ru");
this->real = 0.0;
this->imag = 0.0;
this->mod = 0.0;
}
Complex::~Complex() // ���������� ������.
{
setlocale(LC_ALL, "ru");
}
// ��������� ������� ���������.
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 << "'*' Multiplication" << endl;
cout << "'/' Division" << endl;
cout << "'M' or 'm' Modulo of complex number" << endl;
cout << "------------------------" << endl;
}
Complex Complex::printComplex(Complex *a, Complex *b)
{
cout << "Real part is: " << a->real << endl;
cout << "Imagine part is: " << b->imag << endl;
cout << "Complex number is: (" << a->real << ';' << b->imag << "i)" << endl;
return *a, *b;
}
Complex Complex::EnterComplex(Complex *a)
{
cout << "Enter complex number: real/imag" << endl;
cin >> a->real >> a->imag;
return *a;
}
Complex Complex::EnterComplex(Complex *a, Complex *b)
{
cout << "Enter the first complex number: real/imag" << endl;
cin >> a->real >> a->imag;
cout << "Enter the second complex number: real/imag" << endl;
cin >> b->real >> b->imag;
return *a, *b;
}
Complex Complex::complexSum(Complex *a, Complex *b)
{
a->real = a->real + b->real;
b->imag = a->imag + b->imag;
return printComplex(a,b);
}
Complex Complex::complexSubstraction(Complex *a, Complex *b)
{
a->real = a->real - b->real;
b->imag = a->imag - b->imag;
return printComplex(a,b);
}
Complex Complex::complexMultiply(Complex *a, Complex *b)
{
a->real = (a->real * b->real - a->imag * b->imag);
b->imag = (a->real * b->imag + b->real * a->imag);
return printComplex(a,b);
}
Complex Complex::complexDivision(Complex *a, Complex *b)
{
a->real = ((a->real * b->real + a->imag * b->imag)/(b->real*b->real + b->imag*b->imag));
b->imag = ((b->real * a->imag - a->real * b->imag) / (b->real*b->real + b->imag*b->imag));
return printComplex(a,b);
}
double Complex::complexModulo(Complex *a)
{
mod = sqrt(pow(a->real, 2) + pow(a->imag, 2));
cout << "Modulo is = " << mod << endl;
return mod;
}