#include<iostream>
#include<stdlib.h>
using namespace std;
class Complex
{
public:
Complex(double real,double imag)
:_real(real),_imag(imag)
{
}
Complex(const Complex& s)
:_real(s._real),_imag(s._imag)
{
}
Complex& operator=(Complex& s)
{
if(this!=&s)
{
_real=s._real;
_imag=s._imag;
}
return *this;
}
~Complex()
{
}
public:
Complex operator+(const Complex& s)
{
_real=_real+s._real;
_imag=_imag+s._imag;
return *this;
}
Complex operator-(const Complex& s)
{
_real=_real-s._real;
_imag=_imag-s._imag;
return *this;
}
Complex &operator+=(const Complex& s)
{
_real=_real+s._real;
_imag=_imag+s._imag;
return *this;
}
Complex &operator-=(const Complex& s)
{
_real=_real-s._real;
_imag=_imag-s._imag;
return *this;
}
Complex& operator++(int)
{
_real++;
_imag++;
return *this;
}
Complex& operator++()
{
Complex tmp=*this;
_real++;
_imag++;
return tmp;
}
bool operator==(const Complex& s)
{
if((_real==s._real)&&(_imag==s._imag))
return true;
else
return false;
}
bool operator!=(const Complex& s)
{
if((_real!=s._real)||(_imag!=s._imag))
return true;
else
return false;
}
bool operator>(const Complex& s)
{
if((_real>s._real)&&(_imag>s._imag))
return true;
else
return false;
}
bool operator>=(const Complex& s)
{
if((_real>=s._real)&&(_imag>=s._imag))
return true;
else
return false;
}
bool operator<(const Complex& s)
{
if((_real<s._real)&&(_imag<s._imag))
return true;
else
return false;
}
bool operator<=(const Complex& s)
{
if((_real<=s._real)&&(_imag)<=(s._imag))
return true;
else
return false;
}
void Display()
{
cout<<_real<<" "<<_imag<<endl;
}
private:
double _real;
double _imag;
};
void main()
{
Complex c(2.0,3.0);
Complex c1(c);
Complex c3(4.0,3.0);
Complex c4(5.0,3.0);
c3=c4=c;
Complex c5=c3-=c;
c.Display();
c1.Display();
c3.Display();
c4.Display();
c5.Display();
system("pause");
}
Complex复数类
最新推荐文章于 2021-10-26 20:43:45 发布