Sunday, 20 March 2016

Write C++ program for addison of two complex numbers by overloading „+‟ operator. Make necessary assumptions wherever required.

#include<iostream>
#include<conio.h>
using namespace std;
class complex
{
int real,imaginary;
public:complex()
{
}
complex(int a,int b)
{
real=a;
imaginary=b;
}
void operator+(complex);
};
void complex::operator+(complex c)
{
complex temp;
temp.real=real+c.real;
temp.imaginary=imaginary+c.imaginary;
cout<<"real sum is:"<<temp.real<<endl;
}
int main(void)
{
complex c1(10,20);
complex c2(20,30);
c1+c2;
getch();
}

No comments:

Post a Comment