Fix indentation

main
Micke Nordin 2 years ago
parent d291f7a330
commit ae46252c3e
Signed by: micke
GPG Key ID: 014B273D614BE877

@ -1,13 +1,14 @@
#include <iostream> #pragma once
#include "../fractions/fractions.hpp" #include "../fractions/fractions.hpp"
#include <iostream>
using namespace std; using namespace std;
class cnumber { class cnumber {
private: private:
fraction r,i; fraction r, i;
public: public:
// Constructor // Constructor
cnumber(const cnumber &z) { cnumber(const cnumber &z) {
r = z.r; r = z.r;
@ -29,7 +30,7 @@ class cnumber {
cnumber conjugate() const { cnumber conjugate() const {
fraction a(this->r.get_n(), this->r.get_d()); fraction a(this->r.get_n(), this->r.get_d());
fraction b(this->i.get_n(), this->i.get_d()); fraction b(this->i.get_n(), this->i.get_d());
cnumber z(a,b * -1); cnumber z(a, b * -1);
return z; return z;
} }
@ -43,21 +44,24 @@ class cnumber {
return z; return z;
} }
cnumber operator*(const cnumber &that) const { cnumber operator*(const cnumber &that) const {
cnumber z( (that.r * this->r ) - (that.i * this->i) , (that.r * this->i) + (this->r * that.i) ); cnumber z((that.r * this->r) - (that.i * this->i),
(that.r * this->i) + (this->r * that.i));
return z; return z;
} }
cnumber operator*(const fraction &q) const { cnumber operator*(const fraction &q) const {
cnumber that(q,fraction(0)); cnumber that(q, fraction(0));
return *this * that; return *this * that;
} }
cnumber operator/(const cnumber &that) const { cnumber operator/(const cnumber &that) const {
cnumber numerator( (this->r * that.r ) - (this->i * ( that.i * -1)) , (this->r * (that.i * -1)) + (that.r * this->i) ); cnumber numerator((this->r * that.r) - (this->i * (that.i * -1)),
cnumber denominator( (that.r * that.r ) - (that.i * ( that.i * -1)) , (that.r * (that.i * -1)) + (that.r * that.i) ); (this->r * (that.i * -1)) + (that.r * this->i));
cnumber denominator((that.r * that.r) - (that.i * (that.i * -1)),
(that.r * (that.i * -1)) + (that.r * that.i));
cnumber ratio(numerator.r / denominator.r, numerator.i / denominator.r); cnumber ratio(numerator.r / denominator.r, numerator.i / denominator.r);
return ratio; return ratio;
} }
friend ostream &operator<<( ostream &os, const cnumber &z ) { friend ostream &operator<<(ostream &os, const cnumber &z) {
if (z.r != 0) { if (z.r != 0) {
os << z.r; os << z.r;
if ((z.i.get_sign() == 1) && (z.i > 0)) { if ((z.i.get_sign() == 1) && (z.i > 0)) {
@ -74,9 +78,8 @@ class cnumber {
} }
return os; return os;
} }
void operator=(const cnumber &z ) { void operator=(const cnumber &z) {
r = z.r; r = z.r;
i = z.i; i = z.i;
} }
}; };

Loading…
Cancel
Save