Skip to content

Instantly share code, notes, and snippets.

@manojnaidu619
Created September 12, 2019 17:25
Show Gist options
  • Save manojnaidu619/725be351ca0157d4df85d945d13a5271 to your computer and use it in GitHub Desktop.
Save manojnaidu619/725be351ca0157d4df85d945d13a5271 to your computer and use it in GitHub Desktop.
Calculating Complex number using Friend Function in CPP
#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