Assignment 3
Assignment 3
#include<iostream>
using namespace std;
class Complex{
public:
double R,I;
Complex(){
R=0;
I=0;
}
Complex(double r,double i){
R=r;
I=i;
}
Complex operator+(Complex obj){
Complex temp;
temp.R=R+obj.R;
temp.I=I+obj.I;
return temp;
}
Complex operator*(Complex O){
Complex T;
T.R=R*O.R-I*O.I;
T.I=R*O.I+I*O.R;
return T;
}
void Display(){
cout<<R;
if(I>=0){
cout<<"+"<<I<<"i";
}else{
cout<<"-"<<-I<<"i";
}
cout<<endl;
}
};
int main(){
Complex C1(5,7),C2(3,2);
Complex Sum=C1+C2;
Complex Product=C1*C2;
cout<<"First Complex Number is:";
C1.Display();
cout<<"Second Complex Number is:";
C2.Display();
cout<<"Sum of the two Complex Numbers is:";
Sum.Display();
cout<<"Multiplication of the two Complex Numbers is:";
Product.Display();
return 0;
}
Output