C++ LAB

PROGRAM 1 PROGRAM 2 PROGRAM 3 PROGRAM 4 PROGRAM 5 PROGRAM 6 PROGRAM 7

PART- B

PROGRAM 1 PROGRAM 2 PROGRAM 3 PROGRAM 4 PROGRAM 5 PROGRAM 6 PROGRAM 7 PROGRAM 8

old

PROGRAM 8 PROGRAM 9 PROGRAM 10 PROGRAM 11 PROGRAM 12 PROGRAM 13 PROGRAM 14 . . .

write a c++ program to add two complex numbers using operator overloading

 
 #include < iostream >
#include < iomanip >
using namespace std;
class complex
{
	int re,im;
	public:
		void get()
		{
			cin >> re >> im;
		}
		void disp()
		{
			cout << re << "+" << im << "i";
 
		}
		void sum(complex,complex);
};
void complex::operator+(complex c1,complex c2)
{
	re=c1.re+c2.re;
	im=c1.im+c2.im;
}
int main()
{
	complex c1,c2,c3;
	cout << "Enter 1st complex no.:";
	c1.get();
	cout << "Enter 2nd complex no.:";
	c2.get();
	cout << "The 1st complex no. is";
	c1.disp();
	cout << "\nThe 2nd complex no. is";
	c2.disp();
	c3=c1+c2;
//	c3.sum(c1,c2);
	cout << "\nThe resultant complex no. is";
	c3.disp();
 
}