Include:
iostream.h
conio.h
stdlib.h
class complex
{
float x,y;
public:
complex()
{
}
complex(float real,float imaginary)
{
x=real;
y=imaginary;
}
complex operator+(complex c);
complex operator-(complex c);
complex operator*(complex c);
complex operator/(complex c);
void display()
{
cout<
}
};
// Overloading Operator " - "
complex complex::operator-(complex c)
{
complex temp;
temp.x=x-c.x;
temp.y=y-c.y;
return temp;
}
// Overloading Operator " * "
complex complex::operator*(complex c)
{
complex temp;
temp.x=x*c.x;
temp.y=y*c.y;
return temp;
}
// Overloading Operator " + "
complex complex::operator+(complex c)
{
complex temp;
temp.x=x+c.x;
temp.y=y+c.y;
return temp;
}
// Overloading Operator " / "
complex complex::operator/(complex c)
{
complex temp;
temp.x=x/c.x;
temp.y=y/c.y;
return temp;
}
void main()
{
float a,b,c,d;
int ch;
clrscr();
complex c1,c2,c3;
cout<<"\n--------Operation on Complex Numbers-------";
do
{
cout<<"\n1.Default operation";
cout<<"\n2.Addition";
cout<<"\n3.Substraction";
cout<<"\n4.Multiplication";
cout<<"\n5.Division";
cout<<"\n6.Exit" ;
cout<<"\n\nEnter Your Choice : ";
cin>>ch;
switch(ch)
{
case 1: c1=complex(2.1,3.3);
c2=complex(3.4,5.8);
cout<<"\nEquation 1 : ";
c1.display();
cout<<"\nEquation 2 : ";
c2.display();
cout<<"\nAddition : ";
c3=c1+c2;
c3.display();
cout<<"\nsubstraction : ";
c3=c1-c2;
c3.display();
cout<<"\nMultiplication : ";
c3=c2*c1;
c3.display();
cout<<"\nDivision : ";
c3=c1/c2;
c3.display();
break;
case 2: cout<<"\nEnter Real & Imaginary Part of Eq 1 : ";
cin>>a>>b;
cout<<"\nEnter Real & Imaginary Part of Eq 2 : ";
cin>>c>>d;
c1=complex(a,b);
c2=complex(c,d);
cout<<"\nEquation 1 : ";
c1.display();
cout<<"\nEquation 2 : ";
c2.display();
cout<<"\nAddition : ";
c3=c1+c2;
c3.display();
break;
case 3: cout<<"\nEnter Real & Imaginary Part of Eq 1 : ";
cin>>a>>b;
cout<<"\nEnter Real & Imaginary Part of Eq 2 : ";
cin>>c>>d;
c1=complex(a,b);
c2=complex(c,d);
cout<<"\nEquation 1 : ";
c1.display();
cout<<"\nEquation 2 : ";
c2.display();
cout<<"\nSubstraction : ";
c3=c1-c2;
c3.display();
break;
case 4: cout<<"\nEnter Real & Imaginary Part of Eq 1 : ";
cin>>a>>b;
cout<<"\nEnter Real & Imaginary Part of Eq 2 : ";
cin>>c>>d;
c1=complex(a,b);
c2=complex(c,d);
cout<<"\nEquation 1 : ";
c1.display();
cout<<"\nEquation 2 : ";
c2.display();
cout<<"\nMultiplication : ";
c3=c2*c1;
c3.display();
break;
case 5: cout<<"\nEnter Real & Imaginary Part of Eq 1 : ";
cin>>a>>b;
cout<<"\nEnter Real & Imaginary Part of Eq 2 : ";
cin>>c>>d;
c1=complex(a,b);
c2=complex(c,d);
cout<<"\nEquation 1 : ";
c1.display();
cout<<"\nEquation 2 : ";
c2.display();
cout<<"\nDivision : ";
c3=c1/c2;
c3.display();
break;
case 6:exit(0);
}
} while(1);
}
iostream.h
conio.h
stdlib.h
class complex
{
float x,y;
public:
complex()
{
}
complex(float real,float imaginary)
{
x=real;
y=imaginary;
}
complex operator+(complex c);
complex operator-(complex c);
complex operator*(complex c);
complex operator/(complex c);
void display()
{
cout<
}
};
// Overloading Operator " - "
complex complex::operator-(complex c)
{
complex temp;
temp.x=x-c.x;
temp.y=y-c.y;
return temp;
}
// Overloading Operator " * "
complex complex::operator*(complex c)
{
complex temp;
temp.x=x*c.x;
temp.y=y*c.y;
return temp;
}
// Overloading Operator " + "
complex complex::operator+(complex c)
{
complex temp;
temp.x=x+c.x;
temp.y=y+c.y;
return temp;
}
// Overloading Operator " / "
complex complex::operator/(complex c)
{
complex temp;
temp.x=x/c.x;
temp.y=y/c.y;
return temp;
}
void main()
{
float a,b,c,d;
int ch;
clrscr();
complex c1,c2,c3;
cout<<"\n--------Operation on Complex Numbers-------";
do
{
cout<<"\n1.Default operation";
cout<<"\n2.Addition";
cout<<"\n3.Substraction";
cout<<"\n4.Multiplication";
cout<<"\n5.Division";
cout<<"\n6.Exit" ;
cout<<"\n\nEnter Your Choice : ";
cin>>ch;
switch(ch)
{
case 1: c1=complex(2.1,3.3);
c2=complex(3.4,5.8);
cout<<"\nEquation 1 : ";
c1.display();
cout<<"\nEquation 2 : ";
c2.display();
cout<<"\nAddition : ";
c3=c1+c2;
c3.display();
cout<<"\nsubstraction : ";
c3=c1-c2;
c3.display();
cout<<"\nMultiplication : ";
c3=c2*c1;
c3.display();
cout<<"\nDivision : ";
c3=c1/c2;
c3.display();
break;
case 2: cout<<"\nEnter Real & Imaginary Part of Eq 1 : ";
cin>>a>>b;
cout<<"\nEnter Real & Imaginary Part of Eq 2 : ";
cin>>c>>d;
c1=complex(a,b);
c2=complex(c,d);
cout<<"\nEquation 1 : ";
c1.display();
cout<<"\nEquation 2 : ";
c2.display();
cout<<"\nAddition : ";
c3=c1+c2;
c3.display();
break;
case 3: cout<<"\nEnter Real & Imaginary Part of Eq 1 : ";
cin>>a>>b;
cout<<"\nEnter Real & Imaginary Part of Eq 2 : ";
cin>>c>>d;
c1=complex(a,b);
c2=complex(c,d);
cout<<"\nEquation 1 : ";
c1.display();
cout<<"\nEquation 2 : ";
c2.display();
cout<<"\nSubstraction : ";
c3=c1-c2;
c3.display();
break;
case 4: cout<<"\nEnter Real & Imaginary Part of Eq 1 : ";
cin>>a>>b;
cout<<"\nEnter Real & Imaginary Part of Eq 2 : ";
cin>>c>>d;
c1=complex(a,b);
c2=complex(c,d);
cout<<"\nEquation 1 : ";
c1.display();
cout<<"\nEquation 2 : ";
c2.display();
cout<<"\nMultiplication : ";
c3=c2*c1;
c3.display();
break;
case 5: cout<<"\nEnter Real & Imaginary Part of Eq 1 : ";
cin>>a>>b;
cout<<"\nEnter Real & Imaginary Part of Eq 2 : ";
cin>>c>>d;
c1=complex(a,b);
c2=complex(c,d);
cout<<"\nEquation 1 : ";
c1.display();
cout<<"\nEquation 2 : ";
c2.display();
cout<<"\nDivision : ";
c3=c1/c2;
c3.display();
break;
case 6:exit(0);
}
} while(1);
}
Comments
Post a Comment