-
Notifications
You must be signed in to change notification settings - Fork 0
/
Complex.h
32 lines (24 loc) · 1.08 KB
/
Complex.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
#pragma once
#include <iostream>
class ComplexNumber {
private:
double real;
double imag;
public:
ComplexNumber(); //Defaultkonstruktør
explicit ComplexNumber(double re); //explicit slik at foo(100) ikke skal fungere( se main)
ComplexNumber(double re, double im); //Hjelpekonstruktør
double abs();
ComplexNumber operator+(const ComplexNumber& rhs)const;
ComplexNumber& operator+=(const ComplexNumber& rhs);
friend std::ostream& operator<<(std::ostream& os, const ComplexNumber &rhs);
ComplexNumber operator*(const ComplexNumber& rhs)const;
ComplexNumber& operator*=(const ComplexNumber& rhs);
ComplexNumber operator*(double rhs)const;
friend ComplexNumber operator* (double vhs, const ComplexNumber& rhs);
bool operator==( const ComplexNumber& rhs);
const ComplexNumber operator-()const;
const ComplexNumber operator!()const; //Brukes for komplekskonjugant. Ikke egentlig god skikk siden det ikke kommer tydelig frem fre operatoren,
const double& operator[](int index)const; //En for bruk på konstante objekter
double& operator[](int index); // Og en for vanlige objekter
};