Thursday, October 28, 2010

Object Passed As Return Type

#include

#include

class complex

{

float x;

float y;

public:

void input(float read,float imag)

{

x=read;

y=imag;

}

complex add(complex);

void show(complex);

};

complex complex::add(complex c2)

{

complex c3;

c3.x=x+c2.x;

c3.y=y+c2.y;

return c3;

}

void complex::show(complex c)

{

cout<

}

void main()

{

complex a,b,c;

a.input(3.1,5.65);

b.input(2.75,1.2);

c=a.add(b);

cout<<"A=";

a.show(a);

cout<<"B=";

b.show(b);

cout<<"C=";

c.show(c);

getch();

}

OUTPUT

A=3.1 +5.65

B=2.75+1.2

C=5.85+6.85

No comments:

Post a Comment