WAP USING CONSTRUCTOR OVERLOADING USING (>,++ & +=)
#include<iostream.h>
#include<conio.h>
#include<math.h>
class complex
{
float i,r,m;
public:
void getdata()
{
cout<<"\nEnter the real & imaginary part::";
cin>>r>>i;
}
friend void operator++(complex &);
friend void operator>(complex &,complex &);
friend void operator+=(complex &,complex &);
void disp()
{
cout<<"\nComplex no is::\n"<<r<<"+i"<<i;
}
};
void operator>(complex &c1,complex & c2)
{
c1.m=sqrt(c1.r*c1.r + c1.i*c1.i);
c2.m=sqrt(c2.r*c2.r + c2.i*c2.i);
if(c1.m>c2.m)
cout<<"\nGreater number is::"<<c1.r<<"+i"<<c1.i;
else
cout<<"\nGreater number is::"<<c2.r<<"+i"<<c2.i;
}
void operator++(complex &c1)
{
c1.r=c1.r+5;
c1.i=c1.i+5;
}
void operator+=(complex &c1,complex & c2)
{
c1.r+=c2.r;
c1.i+=c2.i;
}
void main()
{
clrscr();
complex c1,c2;
c1.getdata();
c2.getdata();
operator++(c1);
cout<<"\nAfter incrementing 5 to the current value::\n";
c1.disp();
operator>(c1,c2);
operator+=(c1,c2);
cout<<"\nComposite assignment::\n";
c2.disp();
getch();
}
#include<iostream.h>#include<conio.h>
#include<math.h>
class complex
{
float i,r,m;
public:
void getdata()
{
cout<<"\nEnter the real & imaginary part::";
cin>>r>>i;
}
friend void operator++(complex &);
friend void operator>(complex &,complex &);
friend void operator+=(complex &,complex &);
void disp()
{
cout<<"\nComplex no is::\n"<<r<<"+i"<<i;
}
};
void operator>(complex &c1,complex & c2)
{
c1.m=sqrt(c1.r*c1.r + c1.i*c1.i);
c2.m=sqrt(c2.r*c2.r + c2.i*c2.i);
if(c1.m>c2.m)
cout<<"\nGreater number is::"<<c1.r<<"+i"<<c1.i;
else
cout<<"\nGreater number is::"<<c2.r<<"+i"<<c2.i;
}
void operator++(complex &c1)
{
c1.r=c1.r+5;
c1.i=c1.i+5;
}
void operator+=(complex &c1,complex & c2)
{
c1.r+=c2.r;
c1.i+=c2.i;
}
void main()
{
clrscr();
complex c1,c2;
c1.getdata();
c2.getdata();
operator++(c1);
cout<<"\nAfter incrementing 5 to the current value::\n";
c1.disp();
operator>(c1,c2);
operator+=(c1,c2);
cout<<"\nComposite assignment::\n";
c2.disp();
getch();
}
No comments:
Post a Comment