Also multiplication

main
mickenordin 9 years ago
parent 0f2a7c7536
commit b2b1733fec

@ -3,8 +3,9 @@
int main() { int main() {
cnumber a(-1, 4); cnumber a(1, -3);
cnumber b(4, -7); 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 << " b = " << b << " a * b = " << a * b << endl;
} }

@ -22,6 +22,10 @@ class cnumber {
cnumber z(that.r + this->r, that.i + this->i); cnumber z(that.r + this->r, that.i + this->i);
return z; return z;
} }
cnumber operator*(const cnumber &that) {
cnumber z( (that.r * this->r ) - (that.i * this->i) , (that.r * this->i) + (this->r * that.i) );
return z;
}
friend ostream &operator<<( ostream &os, const cnumber &z ) { friend ostream &operator<<( ostream &os, const cnumber &z ) {
os << z.r << (z.signi ? '+' : '\0' ) << z.i << 'i'; os << z.r << (z.signi ? '+' : '\0' ) << z.i << 'i';

Loading…
Cancel
Save