0% found this document useful (0 votes)
14 views

Pratical Assignment No 3 Oops Prinout

Uploaded by

potatotanmay
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
14 views

Pratical Assignment No 3 Oops Prinout

Uploaded by

potatotanmay
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

Name : Rohit Vipul Mane

Roll No : A-13.

**PRATICAL ASSIGNMENT - 3**


# CODE :
#include <iostream>
using namespace std;
class complex
{
float real, img;

public:
complex operator+(complex);
complex operator*(complex);
friend ostream &operator<<(ostream &, complex &);
friend istream &operator>>(istream &, complex &);
};
complex complex ::operator+(complex c2)
{
complex c3;
c3.real = real + c2.real;
c3.img = img + c2.img;
return c3;
}
complex complex ::operator*(complex c2)
{
complex c3;
c3.real = real * c2.real - img * c2.img;
c3.img = real * c2.img + img * c2.real;
return c3;
}
ostream &operator<<(ostream &out, complex &c)
{
out << c.real << " + " << "i" << c.img << endl;
return out;
}
istream &operator>>(istream &in, complex &c)
{
cout << "Enter the Real part :";
in >> c.real;
cout << "Enter the imgainary part : ";
in >> c.img;
return in;
}

int main()
{
complex c1, c2, c3;
cout << "Enter the first complex number :" << endl;
cin >> c1;
cout << "Enter the second complex number : " << endl;
cin >> c2;
c3 = c1 + c2;
cout << "Sum Of complex number is : " << c3 << endl;
c3 = c1 * c2;
cout << "Mul plica on of complex number is : " << c3 << endl;
return 0;
}

#OUTPUT :
Enter the first complex number :
Enter the Real part :65
Enter the imgainary part : 89
Enter the second complex number :
Enter the Real part :78
Enter the imgainary part : 56
Sum Of complex number is : 143 + i145
Mul plica on of complex number is : 86 + i10582

***************************************

You might also like