/*
write a c++ program to class complex
{
float real,imaginary;
public:\\method
}
overload operator '+' to add two object of that class use parameterised
constructor for accepting value of complex number
*/
#include<conio.h>
#include<iostream.h>
class complex
{
float real,imag;
public:complex(float a,float b)
{
real=a;
imag=b;
}
void operator +(complex &c2)
{
float ans1,ans2;
ans1=real+c2.real;
ans2=imag+c2.imag;
cout<<"\naddition of real:-"<<ans1;
cout<<"\naddition of imaginary:-"<<ans2;
}
};
int main()
{
int a,b;
clrscr();
cout<<"\nenter two float number:-";
cin>>a>>b;
complex c1(a,b);
cout<<"\nenter two float number:-";
cin>>a>>b;
complex c2(a,b);
c1+c2;
getch();
return 0;
}
/*
enter two float number:-3 5
enter two float number:-8 7
addition of real:-11
addition of imaginary:-12
*/
write a c++ program to class complex
{
float real,imaginary;
public:\\method
}
overload operator '+' to add two object of that class use parameterised
constructor for accepting value of complex number
*/
#include<conio.h>
#include<iostream.h>
class complex
{
float real,imag;
public:complex(float a,float b)
{
real=a;
imag=b;
}
void operator +(complex &c2)
{
float ans1,ans2;
ans1=real+c2.real;
ans2=imag+c2.imag;
cout<<"\naddition of real:-"<<ans1;
cout<<"\naddition of imaginary:-"<<ans2;
}
};
int main()
{
int a,b;
clrscr();
cout<<"\nenter two float number:-";
cin>>a>>b;
complex c1(a,b);
cout<<"\nenter two float number:-";
cin>>a>>b;
complex c2(a,b);
c1+c2;
getch();
return 0;
}
/*
enter two float number:-3 5
enter two float number:-8 7
addition of real:-11
addition of imaginary:-12
*/
No comments:
Post a Comment