more operators

main
mickenordin 9 years ago
parent 271d186d27
commit 0f2a7c7536

@ -3,7 +3,8 @@
int main() { int main() {
cnumber z(1, -7); cnumber a(-1, 4);
cnumber b(4, -7);
cout << z << endl; cout << "a = " << a << " b = " << b << " a + b = " << a + b << endl;
} }

@ -18,9 +18,13 @@ class cnumber {
signi = get_sign(i); signi = get_sign(i);
} }
cnumber operator+(const cnumber& that) {
cnumber z(that.r + this->r, that.i + this->i);
return z;
}
friend ostream &operator<<( ostream &os, const cnumber &z ) { friend ostream &operator<<( ostream &os, const cnumber &z ) {
os << z.r << (z.signi ? '+' : '-') << 'i' << (z.signi ? z.i : z.i * -1); os << z.r << (z.signi ? '+' : '\0' ) << z.i << 'i';
return os; return os;
} }

Loading…
Cancel
Save