diff --git a/ComplexNumber.cpp b/ComplexNumber.cpp new file mode 100644 index 0000000..9221175 --- /dev/null +++ b/ComplexNumber.cpp @@ -0,0 +1,20 @@ +// +// Created by benmo on 9/30/2020. +// + +#include "ComplexNumber.h" + +ComplexNumber::ComplexNumber(int a, int b) { + this->a = a; + this->b = b; +} + +ostream& operator<<(ostream& os, const ComplexNumber& cn) { + os << cn.a << "+" << cn.b << "i"; + + return os; +} + +ComplexNumber operator+(const ComplexNumber& cna, const ComplexNumber& cnb) { + return ComplexNumber(cna.a + cnb.a, cna.b + cnb.b); +} \ No newline at end of file diff --git a/ComplexNumber.h b/ComplexNumber.h new file mode 100644 index 0000000..13a9b4e --- /dev/null +++ b/ComplexNumber.h @@ -0,0 +1,24 @@ +// +// Created by benmo on 9/30/2020. +// + +#ifndef UNTITLED6_COMPLEXNUMBER_H +#define UNTITLED6_COMPLEXNUMBER_H + +#include + +using namespace std; + +class ComplexNumber { +public: + ComplexNumber(int a, int b); + + int a, b; +}; + +ostream& operator<<(ostream& os, const ComplexNumber& cn); + +ComplexNumber operator+(const ComplexNumber& cna, const ComplexNumber& cnb); + + +#endif //UNTITLED6_COMPLEXNUMBER_H diff --git a/main.cpp b/main.cpp new file mode 100644 index 0000000..dec8e68 --- /dev/null +++ b/main.cpp @@ -0,0 +1,13 @@ +#include +#include +#include "ComplexNumber.h" + +using namespace std; + +int main() { + ComplexNumber num(3, 5); + ComplexNumber num2(6, -3); + + cout << num << " + " << num2 << " = " << num + num2 << endl; + return 0; +}