#include<iostream.h>
#include<conio.h>
class Complex
{
float real;
float imaginary;
public:
Complex() {}
Complex(float r,float i)
{
real=r;
imaginary=i;
}
void display()
{
cout<<real<<"x + "<<imaginary<<"i";
}
Complex operator+(Complex c)
{
Complex temp;
temp.real=real+c.real;
temp.imaginary=imaginary+c.imaginary;
return temp;
}
};//end of class
int main()
{
float f1,f2;
Complex c1,c2,c3;
clrscr();
cout<<endl<<"Enter two floating values: ";
cin>>f1>>f2;
c1=Complex(f1,f2);
cout<<endl<<"Enter two floating values: ";
cin>>f1>>f2;
c2=Complex(f1,f2);
c3=c1+c2;
cout<<endl<<"Complex Number1: ";
c1.display();
cout<<endl<<"Complex Number2: ";
c2.display();
cout<<endl<<"Complex Number3=Number1 + Number2: ";
c3.display();
getch();
return 0;
}
Post a Comment