commit 271d186d27e1faddead3f135ad6cb44c20a4261c Author: mickenordin Date: Sat Jun 18 19:15:56 2016 +0200 First draft of complex number diff --git a/cnumber.cpp b/cnumber.cpp new file mode 100644 index 0000000..738e42e --- /dev/null +++ b/cnumber.cpp @@ -0,0 +1,9 @@ +#include +#include "cnumber.hpp" + + +int main() { + cnumber z(1, -7); + + cout << z << endl; +} diff --git a/cnumber.hpp b/cnumber.hpp new file mode 100644 index 0000000..33ceb3b --- /dev/null +++ b/cnumber.hpp @@ -0,0 +1,29 @@ +#include + +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; + } + + +}; +