Created
September 12, 2019 17:25
-
-
Save manojnaidu619/725be351ca0157d4df85d945d13a5271 to your computer and use it in GitHub Desktop.
Calculating Complex number using Friend Function in CPP
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
using namespace std; | |
class Complex{ | |
int real,img; | |
public: | |
Complex(int real=0, int img=0){ | |
this->real = real; | |
this->img = img; | |
} | |
friend Complex compute(Complex, Complex); | |
friend void display(Complex); | |
}; | |
Complex compute(Complex c1,Complex c2){ | |
Complex temp; | |
temp.real = c1.real+c2.real; | |
temp.img = c1.img+c2.img; | |
return temp; | |
} | |
void display(Complex temp){ | |
cout << temp.real << "+i" << temp.img << endl; | |
} | |
int main(){ | |
Complex c1(1,2); | |
Complex c2(3,4); | |
Complex t = compute(c1,c2); | |
display(t); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment