#include<iostream.h>
#include<conio.h>
class Complex
{
public:
int x;
int y;
void getdata()
{
cout<<"Enter the value of x (In the format of x+iy)"<<endl;
cin>>x;
cout<<"Enter the value of y (In the format of x+iy ) "<<endl;
cin>>y;
}
void showdata()
{
cout<<x<<"+"<<y<<"i";
}
Complex operator + (Complex);
};
Complex Complex :: operator + ( Complex a )
{
Complex temp;
temp.x=x+a.x;
temp.y=y+a.y;
return(temp);
}
void main()
{
Complex P;
Complex Q;
Complex R;
clrscr();
cout<<"Enter the first complex number"<<endl;
P.getdata();
cout<<"Enter the second complex number"<<endl;
Q.getdata();
R=P+Q;
cout<<"1st Complex number: "<<endl;
P.showdata();
cout<<endl;
cout<<"2nd Complex number: "<<endl;
Q.showdata();
cout<<endl;
cout<<"Result is: "<<endl;
R.showdata();
getch();
}
OUTPUT
#include<conio.h>
class Complex
{
public:
int x;
int y;
void getdata()
{
cout<<"Enter the value of x (In the format of x+iy)"<<endl;
cin>>x;
cout<<"Enter the value of y (In the format of x+iy ) "<<endl;
cin>>y;
}
void showdata()
{
cout<<x<<"+"<<y<<"i";
}
Complex operator + (Complex);
};
Complex Complex :: operator + ( Complex a )
{
Complex temp;
temp.x=x+a.x;
temp.y=y+a.y;
return(temp);
}
void main()
{
Complex P;
Complex Q;
Complex R;
clrscr();
cout<<"Enter the first complex number"<<endl;
P.getdata();
cout<<"Enter the second complex number"<<endl;
Q.getdata();
R=P+Q;
cout<<"1st Complex number: "<<endl;
P.showdata();
cout<<endl;
cout<<"2nd Complex number: "<<endl;
Q.showdata();
cout<<endl;
cout<<"Result is: "<<endl;
R.showdata();
getch();
}
OUTPUT
No comments:
Post a Comment