-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcomplex0.cpp
More file actions
executable file
·52 lines (51 loc) · 1.12 KB
/
complex0.cpp
File metadata and controls
executable file
·52 lines (51 loc) · 1.12 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
#include <iostream>
#include "complex0.h"
using namespace std;
//using namespace linClass;
Complex::Complex()
{
real=0.0;
imaginary=0.0;
}
Complex::Complex(double r,double i)
{
real=r;
imaginary=i;
}
Complex Complex::operator+(const Complex & c) const
{
return Complex(real + c.real,imaginary + c.imaginary);
}
Complex Complex::operator-(const Complex & c) const
{
return Complex(real - c.real,imaginary - c.imaginary);
}
Complex Complex::operator*(const Complex & c) const
{
return Complex(real*c.real - imaginary*c.imaginary,real*c.imaginary + imaginary*c.real);
}
Complex Complex::operator*(const double d) const
{
return Complex(real*d,imaginary*d);
}
Complex Complex::operator~() const
{
return Complex(real,-imaginary);
}
Complex operator*(const double d,const Complex & c)
{
return c*d;
}
ostream & operator<<(ostream & os,const Complex & c)
{
os<<'('<<c.real<<','<<c.imaginary<<"i)";
return os;
}
bool operator>>(istream & is,Complex & c)
{
cout<<"real:";
if (!(is>>c.real)) return false;
cout<<"imaginary:";
if (!(is>>c.imaginary)) return false;
return true;
}