-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathExp 7
36 lines (27 loc) · 843 Bytes
/
Exp 7
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
#include <iostream>
class Complex {
private:
double real;
double imaginary;
public:
Complex(double real, double imaginary) : real(real), imaginary(imaginary) {}
Complex operator+(const Complex& other) const {
return Complex(real + other.real, imaginary + other.imaginary);
}
Complex operator-(const Complex& other) const {
return Complex(real - other.real, imaginary - other.imaginary);
}
friend std::ostream& operator<<(std::ostream& os, const Complex& complex) {
os << complex.real << " + " << complex.imaginary << "i";
return os;
}
};
int main() {
Complex c1(3, 4);
Complex c2(1, 2);
Complex sum = c1 + c2;
Complex diff = c1 - c2;
std::cout << "Sum: " << sum << std::endl;
std::cout << "Difference: " << diff << std::endl;
return 0;
}