## Program-Develop a class to represent complex number

- A f
^{n}to get the CN from user. - A f
^{n}to display the CN - A f
^{n}to add the two CN which are accepted as parameters. - Multiply
- Subtract
- Divide

^{n}.

^{2}+d

^{2})

Method II

Addition of two CN.

#include

class complex

{

float r, i ;

public:

void getcomplex ( );

void display ( );

complex add (complex);

complex subtract (complex);

complex multiply (complex);

complex divide (complex);

};

void complex :: get complex ( )

{

cin>>r>>i;

}

void complex :: display ( ).

{

cout<

}

complex complex :: add (complex c)

{

complex temp;

temp.r = r+c.r;

temp.i = i+c.i;

return temp ;

}

complex complex :: multiply (complex c)

{

complex temp;

temp.r = r * c.r – i * c.i ;

temp.i = i * c.r + r* c.i ;

return temp ;

}

complex complex :: divide (complex c)

{

temp.r = (r*c.r + i * c.i) / ( c.r*c.r+c.i+c.i)

temp.i = (1*c.r – r* c.1) / (c.r*c.r+c.i*c.i) ;

return temp ;

}

complex complex :: subtract (complex)

{ temp.r = r – c.r ;

temp.i = i – c.i ;

return temp ;

}

void main ( )

{

complex c_{1}, c_{2}, a, s, m, d ;

cout<<"Enter CN = \n" ;

c1.getcomplex ( ) ;

cout<<"Enter CN = \n" ;

c_{2}.get complex ( );

a = c_{1}.add (c_{2}) ;

s= c_{2}.sbutract (c_{2}) ;

m = c_{1}.multiply (c_{2}) ;

d = c_{1}.divide (c_{2}) ;

cout<<"Addition=\n" ;

a.display ( );

cout<<"subtraction=\n";

a.display ( ) ;

cout<<"multiplication = \n" ;

m.display ( ) ;

cout<<"division=\n" ;

d.display ( );

}

Like it on Facebook, +1 on Google, Tweet it or share this article on other bookmarking websites.

## Comments (0)