Untitled
unknown
plain_text
2 years ago
1.7 kB
7
Indexable
#include <iostream>
using namespace std;
class Complex{
public:
Complex(int inreal = 0, int inimag = 0):real(inreal),imag(inimag){}
friend istream &operator>>(istream &input, Complex &C){
input >> C.real >> C.imag;
return input;
}
friend ostream &operator<<(ostream &output, const Complex &C){
output << C.real << (C.imag >= 0 ? "+" : "") << C.imag << "i";
return output;
}
bool operator==(const Complex &C) const{
return real == C.real && imag == C.imag;
}
bool operator!=(const Complex &C) const{
return real != C.real || imag != C.imag;
}
Complex operator+(const Complex &C) const{
return Complex( real + C.real , imag + C.imag );
}
Complex operator-(const Complex &C) const{
return Complex( real - C.real , imag - C.imag );
}
Complex operator*(const Complex &C) const{
return Complex( real * C.real - imag * C.imag , real * C.imag + imag * C.real );
}
Complex operator++(int){
Complex temp = *this;
real++;
imag++;
return temp;
}
Complex operator++(){
real++;
imag++;
return *this;
}
Complex operator--(int){
Complex temp = *this;
real--;
imag--;
return temp;
}
Complex operator--(){
real--;
imag--;
return *this;
}
Complex operator+=(const Complex &C){
real += C.real;
imag += C.imag;
return *this;
}
private:
int real;
int imag;
};Editor is loading...
Leave a Comment