diff --git a/cnumber.cpp b/cnumber.cpp index 868dfdf..068e724 100644 --- a/cnumber.cpp +++ b/cnumber.cpp @@ -6,6 +6,12 @@ int main() { cnumber a(1, -3); cnumber b(2, 5); - cout << "a = " << a << " b = " << b << " a + b = " << a + b << endl; - cout << "a = " << a << " b = " << b << " a * b = " << a * b << endl; + cout << "a = " << a << endl; + cout << "a* = " << a.conjugate() << endl; + cout << "b = " << b << endl; + cout << "b* = " << b.conjugate() << endl; + cout << "a + b = " << a + b << endl; + cout << "(a + b)* = " << (a + b).conjugate() << endl; + cout << "a * b = " << a * b << endl; + cout << "(a * b)* = " << (a * b).conjugate() << endl; } diff --git a/cnumber.hpp b/cnumber.hpp index d2ed41c..0b76a83 100644 --- a/cnumber.hpp +++ b/cnumber.hpp @@ -11,6 +11,7 @@ class cnumber { } public: + // Constructor cnumber(int a, int b) { r = a; i = b; @@ -18,6 +19,14 @@ class cnumber { signi = get_sign(i); } + // Member functions + cnumber conjugate() { + cnumber z(this->r, this->i * -1); + return z; + } + + + // Operators cnumber operator+(const cnumber &that) { cnumber z(that.r + this->r, that.i + this->i); return z; @@ -31,7 +40,12 @@ class cnumber { os << z.r << (z.signi ? '+' : '\0' ) << z.i << 'i'; return os; } - + void operator=(const cnumber &z ) { + r = z.r; + i = z.i; + signr = z.signr; + signi = z.signi; + } };