-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathEuler_Number.h
More file actions
86 lines (69 loc) · 1.94 KB
/
Euler_Number.h
File metadata and controls
86 lines (69 loc) · 1.94 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
#pragma once
#include <iostream>
#include <cmath>
class Euler_Number {
private:
float real = 0;
float imaginary = 0;
public:
void set_real_number(float r) { real = r; }
void set_imaginary_number(float i) { imaginary = i; }
const float get_real_number() { return real; }
const float get_imaginary_number() { return imaginary; }
Euler_Number operator+(const Euler_Number& F_input)
{
Euler_Number F;
F.set_real_number(real + F_input.real);
F.set_imaginary_number(imaginary + F_input.imaginary);
return F;
}
Euler_Number& operator=(double d_input)
{
this->set_real_number(d_input);
this->set_imaginary_number(0);
return *this;
}
Euler_Number operator*(const Euler_Number& F_input)
{
Euler_Number F;
F.set_real_number(real * F_input.real - imaginary * F_input.imaginary);
F.set_imaginary_number(real * F_input.imaginary + imaginary * F_input.real);
return F;
}
friend Euler_Number operator*(Euler_Number& F_input, double d_input);
friend Euler_Number operator*(double d_input, Euler_Number F_input);
friend std::ostream& operator<<(std::ostream& os, const Euler_Number& F_input);
};
Euler_Number operator*(Euler_Number& F_input, double d_input)
{
Euler_Number F;
F.set_imaginary_number(F_input.imaginary * d_input);
F.set_real_number(F_input.real * d_input);
return F;
}
Euler_Number operator*(double d_input, Euler_Number F_input)
{
Euler_Number F;
F.set_imaginary_number(F_input.imaginary * d_input);
F.set_real_number(F_input.real * d_input);
return F;
}
std::ostream& operator<<(std::ostream& os, const Euler_Number& F_input)
{
os << "(";
if (F_input.real != 0)
os << F_input.real;
if (F_input.imaginary != 0)
{
if (F_input.real != 0)
os << ", ";
if (F_input.imaginary == 1)
os << "i";
else
os << F_input.imaginary << "i";
}
if (F_input.real == 0 && F_input.imaginary == 0)
os << "0";
os << ")";
return os;
}