Pratical Assignment No 3 Oops Prinout
Pratical Assignment No 3 Oops Prinout
Roll No : A-13.
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
***************************************