complex program
complex program
ImplementaclassComplexwhichrepresentstheComplexNumberdatatype.
Implement
The following operations:
1. Constructor (including a default constructor which creates the
complex number 0+0i).
2. Overloaded operator + to add two complex numbers.
3. Overloaded operator * to multiply two complex numbers.
4. Overloaded << and >> to print and read Complex Numbers. */
#include<iostream>
using namespace std;
class complex
{
float x;float y;
public:
complex() // Default constructor
{
x=0;y=0;
}
}; //class closing
complex complex::operator+(complex c)
{
complex temp;
temp.x=x+c.x;
temp.y=y+c.y;
return(temp);
}
complex complex::operator*(complex c)
{
complex temp2;
temp2.x=(x*c.x)-(y*c.y);
temp2.y=(y*c.x)+(x*c.y);
return(temp2);
}
int main()
{
complex c1,c2,c3,c4;//object of class
cout<<"Default constructor value=\n";
cout<<c1;
c3=c1+c2;
c4=c1*c2;
return 0;