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

Pract 1

oops pract 1

Uploaded by

Ketan Belekar
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)
5 views2 pages

Pract 1

oops pract 1

Uploaded by

Ketan Belekar
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/ 2

Practical No.

1
Input: -

# include<iostream> {
using namespace std; Complex tmp;
class Complex //decaring Class tmp.real = real * c2.real - img * c2.img;
Complex tmp.img = real * c2.img + img * c2.real;
{ return tmp;
double real; }
double img; int main()
public: {
Complex(); // Default Constructor Complex C1, C2, C3, C4;
friend istream & operator >> (istream &, int flag = 1;
Complex &); // Input char b;
friend ostream & operator << (ostream &, const while (flag == 1)
Complex &); // Output {
Complex operator + (Complex); // Addition cout << "Enter Real and Imaginary part of the
Complex operator * (Complex); // Complex Number 1 : \n";
Multiplication cin >> C1;
}; cout << "Enter Real and Imaginary part of the
Complex::Complex() // Default Complex Number 2 : \n";
Constructor cin >> C2;
{ int f = 1;
real = 0; while (f == 1)
img = 0; {
} cout << "Complex Number 1 : " << C1 << endl;
istream & operator >> (istream &, Complex & cout << "Complex Number 2 : " << C2 << endl;
i) cout << "**********MENU**********" <<
{ endl;
cin >> i.real >> i.img; cout << "1. Addition of Complex Numbers" <<
return cin; endl;
} cout << "2. Multiplication of Complex
ostream & operator << (ostream &, const Numbers" << endl;
Complex & d) cout << "3. Exit\n";
{ int a;
cout << d.real << " + " << d.img << "i" << cout << "Enter your choice from above MENU
endl; (1 to 3) : ";
return cout; cin >> a;
} if (a == 1)
Complex Complex::operator + (Complex c1) // {
Overloading + operator C3 = C1+C2;
{ cout << "Addition : " << C3 << endl;
Complex temp; cout << "Do you wan to perform another
temp.real = real + c1.real; operation (y/n) : \n";
temp.img = img + c1.img; cin >> b;
return temp; if (b == 'y' || b == 'Y')
}
Complex Complex::operator * (Complex c2) // {
Overloading * Operator f=1;
} }
else else
{ {
cout << "Thanks for using this program!!\n"; cout << "Thanks for using this program!!\n";
flag=0; flag=0;
f=0; f=0;
} }
} }
else if (a == 2) else
{ {
C4 = C1 * C2; cout << "Thanks for using this program!!\n";
cout << "Multiplication : " << C4 << endl; flag=0;
cout << "Do you wan to perform another f=0;
operation (y/n) : \n"; }
cin >> b; }
if (b == 'y' || b == 'Y') }
return 0;
{ }
f=1;

Output : -

Enter Real and Imaginary part of the Complex Number 1:


5
4
Enter Real and Imaginary part of the Complex Number 2:
5
4
Complex Number 1: 5 + 4i
Complex Number 2: 5 + 4i
********** MENU **********
Addition of Complex Numbers
Multiplication of Complex Numbers
Exit
Enter your choice from above MENU (1 to 3): 1
Addition: 10 + 8i
Do you want to perform another operation (y/n):
y
Complex Number 1: 5 + 4i
Complex Number 2: 5 + 4i
********** MENU **********
Addition of Complex Numbers
Multiplication of Complex Numbers
Exit
Enter your choice from above MENU (1 to 3): 2

Multiplication: 9 + 40i

Do you want to perform another operation (y/n):

You might also like