#include<iostream>
using namespace std;
class Complex {
private:
int re, im;
public:
Complex(int r = 0, int i =0) {re = r; im = i;}
Complex operator - (Complex const &ob) {
Complex comp;
comp.re = re - ob.re;
comp.im = im - ob.im;
return comp;
}
Complex operator * (Complex const &ob) {
Complex comp;
comp.re= re * ob.re;
comp.im = im * ob.im;
return comp;
}
Complex operator / (Complex const &ob) {
Complex comp;
comp.re = re / ob.re;
comp.im= im / ob.im;
return comp;
}
Complex operator + (Complex const &ob) {
Complex comp;
comp.re = re + ob.re;
comp.im= im + ob.im;
return comp;
}
void print() { cout << re << " + i" << im << endl; }
};
int main()
{
Complex comp1(10, 5), comp2(2, 4);
Complex comp3 = comp1 + comp2;
Complex comp4 = comp3 - comp1;
Complex comp5 = comp1 * comp2;
Complex comp6 = comp1 / comp2;
comp3.print();
cout<<endl;
comp4.print();
cout<<endl;
comp5.print();
cout<<endl;
comp6.print();
}
Comments
Leave a comment