First draft of complex number

main
mickenordin 9 years ago
commit 271d186d27

@ -0,0 +1,9 @@
#include <iostream>
#include "cnumber.hpp"
int main() {
cnumber z(1, -7);
cout << z << endl;
}

@ -0,0 +1,29 @@
#include <iostream>
using namespace std;
class cnumber {
private:
int r, i;
bool signr, signi;
bool get_sign(int i) {
return (i >= 0);
}
public:
cnumber(int a, int b) {
r = a;
i = b;
signr = get_sign(r);
signi = get_sign(i);
}
friend ostream &operator<<( ostream &os, const cnumber &z ) {
os << z.r << (z.signi ? '+' : '-') << 'i' << (z.signi ? z.i : z.i * -1);
return os;
}
};
Loading…
Cancel
Save