-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcomplex.cpp
68 lines (60 loc) · 963 Bytes
/
complex.cpp
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
#include "complex.h"
complex::complex()
{
num.i=0;
num.r=0;
}
complex::complex(double i, double r)
{
num.i=i;
num.r=r;
}
complex::~complex()
{
}
complex complex::operator + (complex a)
{
complex b;
b.num.i=a.num.i+num.i;
b.num.r=a.num.r+num.r;
return b;
}
complex complex::operator * (complex a)
{
complex b;
b.num.i=this->num.i*a.num.r+this->num.r*a.num.i;
b.num.r=num.r*a.num.r-num.i*a.num.i;
return b;
}
complex complex::operator - (complex a)
{
complex b;
b.num.i=a.num.i-num.i;
b.num.r=a.num.r-num.r;
return b;
}
complex complex::operator / (complex a)
{
complex b;
b.num.i=this->num.i/a.num.r+this->num.r/a.num.i;
b.num.r=num.r/a.num.r-num.i/a.num.i;
return b;
}
//accessors
double complex::geti() const
{
return this->num.i;
}
double complex::getr() const
{
return this->num.r;
}
//mutators
void complex::seti(double number)
{
this->num.i=number;
}
void complex::setr(double number)
{
this->num.r=number;
}