#include<iostream>
#include<cstring>
using namespace std;
class Complex{
public:
double x;
double y;
Complex(double x = 0.0, double y = 0.0){
this->x=x;
this->y=y;}
~Complex(){};
Complex & operator+=(const Complex &);
Complex & operator-=(const Complex &);
Complex & operator*=(const Complex &);
Complex & operator/=(const Complex &);
friend Complex operator+(const Complex &, const Complex &);
friend Complex operator-(const Complex &, const Complex &);
friend Complex operator*(const Complex &, const Complex &);
friend Complex operator/(const Complex &, const Complex &);
friend bool operator==(const Complex &, const Complex &);
friend bool operator!=(const Complex &, const Complex &);
friend ostream & operator<<(ostream &, const Complex &);
friend istream & operator>>(istream &, Complex &);
};
istream & operator>>(istream &in,Complex &c){
in>>c.x>>c.y;
return in;
}
ostream & operator<<(ostream &out,Complex &c){
out<<c.x<<" + "<<c.y<<"i";
return out;
}
Complex operator+(const Complex &c1, const Complex &c2){
Complex a;
a.x=c1.x+c2.x;
a.y=c1.y+c2.y;
return a;
}
Complex operator-(const Complex &c1, const Complex &c2){
Complex a;
a.x=c1.x-c2.x;
a.y=c1.y-c2.y;
return a;
}
Complex operator*(const Complex &c1, const Complex &c2){
Complex b;
b.x=c1.x*c2.x-c1.y*c2.y;
b.y=c1.x*c2.y+c1.y*c2.x;
return b;
}
Complex operator/(const Complex &c1, const Complex &c2){
Complex d;
d.x=(c1.x*c2.x+c1.y*c2.y)/(c2.x*c2.x+c2.y*c2.y);
d.y=(c1.y*c2.x-c1.x*c2.y)/(c2.x*c2.x+c2.y*c2.y);
return d;
}
Complex &Complex::operator+=(const Complex &c){
this->x+=c.x;
this->y+=c.y;
return *this;
}
Complex &Complex:: operator-=(const Complex &c){
this->x-=c.x;
this->y-=c.y;
return *this;
}
Complex &Complex:: operator*=(const Complex &c){
*this=*this*c;
return *this;
}
Complex &Complex:: operator/=(const Complex &c){
*this=*this/c;
return *this;
}
bool operator==(const Complex &c1, const Complex &c2){
if(c1.x==c2.x&&c1.y==c2.y)
return 1;
else
return 0;
}
bool operator!=(const Complex &c1, const Complex &c2){
if(c1.x!=c2.x||c1.y!=c2.y)
return 1;
else
return 0;
}
int main()
{
Complex c1, c2;
cin >> c1 >> c2;
cout << "c1 = " << c1 << "\n" << "c2 = " << c2 << endl;
cout << "c1+c2 = " << c1 + c2 << endl;
cout << "c1-c2 = " << c1 - c2 << endl;
cout << "c1*c2 = " << c1 * c2 << endl;
cout << "c1/c2 = " << c1 / c2 << endl;
cout << (c1 += c2) << endl;
cout << (c1 -= c2) << endl;
cout << (c1 *= c2) << endl;
cout << (c1 /= c2) << endl;
cout << (c1 == c2) << " " << (c1 != c2) << endl;
return 0;
}
using namespace std;
class Complex {
public:
double x;
double y;
Complex(double x = 0.0, double y = 0.0) {
this->x = x;
this->y = y;
}
~Complex() {};
Complex & operator+=(const Complex &);
Complex & operator-=(const Complex &);
Complex & operator*=(const Complex &);
Complex & operator/=(const Complex &);
friend Complex operator+(const Complex &, const Complex &);
friend Complex operator-(const Complex &, const Complex &);
friend Complex operator*(const Complex &, const Complex &);
friend Complex operator/(const Complex &, const Complex &);
friend bool operator==(const Complex &, const Complex &);
friend bool operator!=(const Complex &, const Complex &);
friend ostream & operator<<(ostream &, const Complex &);
friend istream & operator>>(istream &, Complex &);
};
istream & operator>>(istream &in, Complex &c) {
in >> c.x >> c.y;
return in;
}
ostream & operator<<(ostream &out, Complex &c) {
out << c.x << " + " << c.y << "i";
return out;
}
Complex operator+(const Complex &c1, const Complex &c2) {
Complex a;
a.x = c1.x + c2.x;
a.y = c1.y + c2.y;
return a;
}
Complex operator-(const Complex &c1, const Complex &c2) {
Complex a;
a.x = c1.x - c2.x;
a.y = c1.y - c2.y;
return a;
}
Complex operator*(const Complex &c1, const Complex &c2) {
Complex b;
b.x = c1.x*c2.x - c1.y*c2.y;
b.y = c1.x*c2.y + c1.y*c2.x;
return b;
}
Complex operator/(const Complex &c1, const Complex &c2) {
Complex d;
d.x = (c1.x*c2.x + c1.y*c2.y) / (c2.x*c2.x + c2.y*c2.y);
d.y = (c1.y*c2.x - c1.x*c2.y) / (c2.x*c2.x + c2.y*c2.y);
return d;
}
Complex &Complex::operator+=(const Complex &c) {
this->x += c.x;
this->y += c.y;
return *this;
}
Complex &Complex:: operator-=(const Complex &c) {
this->x -= c.x;
this->y -= c.y;
return *this;
}
Complex &Complex:: operator*=(const Complex &c) {
*this = *this*c;
return *this;
}
Complex &Complex:: operator/=(const Complex &c) {
*this = *this / c;
return *this;
}
bool operator==(const Complex &c1, const Complex &c2) {
if (c1.x == c2.x&&c1.y == c2.y)
return 1;
else
return 0;
}
bool operator!=(const Complex &c1, const Complex &c2) {
if (c1.x != c2.x || c1.y != c2.y)
return 1;
else
return 0;
}
int main()
{
Complex c1, c2;
cin >> c1 >> c2;
cout << "c1 = " << c1 << "\n" << "c2 = " << c2 << endl;
Complex c3;
c3 = c1 + c2;
cout << "c1+c2 = " << c3 << endl;
c3 = c1 - c2;
cout << "c1-c2 = " << c3 << endl;
c3 = c1 * c2;
cout << "c1*c2 = " << c3 << endl;
c3 = c1 / c2;
cout << "c1/c2 = " << c3 << endl;
cout << (c1 += c2) << endl;
cout << (c1 -= c2) << endl;
cout << (c1 *= c2) << endl;
cout << (c1 /= c2) << endl;
cout << (c1 == c2) << " " << (c1 != c2) << endl;
return 0;
}