-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcomplex.cpp
67 lines (50 loc) · 1.47 KB
/
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
#include<iostream>
using namespace std;
class Complex {
public:
double r;
double i;
Complex(){
this->r = 0;
this->i = 0;
}
Complex(double r, double i){
this->r = r;
this->i = i;
}
Complex operator +(const Complex &c){
return Complex(this->r+c.r, this->i + c.i);
}
Complex operator -(const Complex &c){
return Complex(this->r - c.r, this->i - c.i);
}
Complex operator *(const Complex &c){
return Complex((this-> r*c.r)-(this->i*c.i), (this->r*c.i)+(this->i*c.r));
}
Complex operator /(const Complex &c){
return Complex((this->r*c.r+this->i*c.i)/(c.r*c.r+c.i*c.i), (c.r*this->i)/(c.r*c.r+c.i*c.i));
}
private:
friend istream & operator>>(istream &s, Complex &c)
{
s >> c.r;
s >> c.i;
return s;
}
};
std::ostream & operator <<(std::ostream & s, const Complex &c){
return s << "(" << c.r << "," << c.i << "i)";
}
int main(){
Complex c1;
Complex c2;
cout<<"Wpisz współczynniki dwóch liczb zespolonych: ";
cin >> c1;
cin >> c2;
cout << "pierwsza liczba zespolona to: " << c1 << endl;
cout << "druga liczba zespolona to: " << c2 << endl;
cout << "wynik dodawania to: " << c1 + c2 << endl;
cout << "wynik odejmowania to: " << c1 - c2 << endl;
cout << "wynik mnożenia to: " << c1 * c2 << endl;
cout << "wynik dzielenia to: " << c1 / c2 << endl;
}