0% found this document useful (0 votes)
28 views2 pages

Second

This document contains a C++ program that defines a 'complex' class for performing arithmetic operations on complex numbers. It includes overloaded operators for addition and multiplication, as well as input and output stream operators. The main function demonstrates how to input two complex numbers and perform addition and multiplication, displaying the results.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
28 views2 pages

Second

This document contains a C++ program that defines a 'complex' class for performing arithmetic operations on complex numbers. It includes overloaded operators for addition and multiplication, as well as input and output stream operators. The main function demonstrates how to input two complex numbers and perform addition and multiplication, displaying the results.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd

#include<iostream>

using namespace std;


class complex
{
public:
float real,img;
complex()
{
real=0;
img=0;
}
complex operator +(complex);
complex operator *(complex);
friend ostream &operator<<(ostream&,complex&);
friend istream &operator>>(istream&,complex&);
};

complex complex::operator +(complex obj)


{
complex temp;
[Link]=real+[Link];
[Link]=img+[Link];
return (temp);
}

complex complex::operator *(complex obj)


{
complex temp;
[Link]=(real*[Link])-(img*[Link]);
[Link]=(real*[Link])+(img+[Link]);
return (temp);
}

istream &operator>>(istream& is,complex& obj)


{
is>>[Link];
is>>[Link];
return is;

ostream &operator<<(ostream& os,complex& obj)


{
os<<[Link];
os<<"+"<<[Link]<<"i";
return os;
}

int main()
{
complex a,b,c,d;
//cout<<"\n Enter first complex number"<<endl;
cout<<"\n Enter real and imaginary part of first complex number:";
cin>>a;

//cout<<"\n Enter second complex number"<<endl;


cout<<"\n Enter real and imaginary part of second complex number:";
cin>>b;
cout<<"\n Arithmetic operations are :";
c=a+b;
cout<<"\n Addition is:"<<c;

d=a*b;
cout<<"\n Multiplication is:"<<d<<"\n";
return 0;
}

You might also like