Day 5 code

This commit is contained in:
Ben Morgan 2020-09-30 20:27:30 -06:00 committed by GitHub
parent 95f09146de
commit 75120f935f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 57 additions and 0 deletions

20
ComplexNumber.cpp Normal file
View file

@ -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);
}

24
ComplexNumber.h Normal file
View file

@ -0,0 +1,24 @@
//
// Created by benmo on 9/30/2020.
//
#ifndef UNTITLED6_COMPLEXNUMBER_H
#define UNTITLED6_COMPLEXNUMBER_H
#include <fstream>
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

13
main.cpp Normal file
View file

@ -0,0 +1,13 @@
#include <iostream>
#include <sstream>
#include "ComplexNumber.h"
using namespace std;
int main() {
ComplexNumber num(3, 5);
ComplexNumber num2(6, -3);
cout << num << " + " << num2 << " = " << num + num2 << endl;
return 0;
}