#include<iostream.h>

#include<conio.h>

class complex

{

float x,y;

public:

void input(float real,float imag)

{

x=real;

y=imag;

}

friend complex sum(complex,complex);

void show(complex);

};

complex sum(complex c1,complex c2)

{

complex c3;

c3.x=c1.x+c2.x;

c3.y=c1.y+c2.y;

return(c3);

}

void complex::show(complex c)

{

cout<<"\n"<<c.x<<"+ j"<<c.y;

}

void main()

{

complex a,b,c;

clrscr();

a.input(3.1,5.65);

b.input(27.5,1.2);

c=sum(a,b);

cout<<"\nA =";

a.show(a);

cout<<"\nB = ";

b.show(b);

cout<<"\nC =";

c.show(c);

getch();

}

#include<conio.h>

class complex

{

float x,y;

public:

void input(float real,float imag)

{

x=real;

y=imag;

}

friend complex sum(complex,complex);

void show(complex);

};

complex sum(complex c1,complex c2)

{

complex c3;

c3.x=c1.x+c2.x;

c3.y=c1.y+c2.y;

return(c3);

}

void complex::show(complex c)

{

cout<<"\n"<<c.x<<"+ j"<<c.y;

}

void main()

{

complex a,b,c;

clrscr();

a.input(3.1,5.65);

b.input(27.5,1.2);

c=sum(a,b);

cout<<"\nA =";

a.show(a);

cout<<"\nB = ";

b.show(b);

cout<<"\nC =";

c.show(c);

getch();

}

**OUTPUT:-**

Nice answers in replace of the question with real point of view and explaining about that.

ReplyDeletetutorial on c++