Answer:-
#include <iostream>
using namespace std;
class Complex{
float real, imaginary;
public:
Complex(){}
Complex(float a, float b): real(a), imaginary(b){}
void Display(){
cout<<real;
if(imaginary != 0) cout<<" + "<<"i";
if(imaginary < 0) cout<<"("<<imaginary<<")";
else cout<<imaginary;
}
Complex operator+(const Complex &other){
return Complex(this->real + other.real, this->imaginary + other.imaginary);
}
Complex operator*(const Complex &other){
return Complex(this->real * other.real + this->imaginary * other.imaginary, this->real * other.imaginary + this->imaginary * other.real);
}
};
Comments
Leave a comment