Popular Posts

32.Write a program to show the sum of complex numbers .

32.Write a program to show the sum of complex numbers .

#include
#include
class complex
{
float x,y;
public:
complex(){}
complex(float real,float imag)
{x=real;y=imag;}
complex operator+(complex);
void display(void);
};
complex complex::operator+(complex c)
{
complex temp;
temp.x=x+c.x;
temp.y=y+c.y;
return(temp);
}
void complex::display(void)
{
cout< }
int main()
{
clrscr();
complex c1,c2,c3;
c1=complex(2.5,3.5);
c2=complex(1.6,2.7);
c3=c1+c2;
cout<<"c1= ";c1.display();
cout<<"c2= ";c2.display();
cout<<"c3= ";c3.display();
getch();
return 0;
}

Output:

c1= 2.5+j3.5
c2= 1.6+j2.7
c3= 4.1+j6.2

No comments: