Last active
July 30, 2016 17:26
-
-
Save ravikiran0606/be152b32d51fedab98d451fac1e00b29 to your computer and use it in GitHub Desktop.
C++ program to implement a complex number class and its basic functions :
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 cmplx{ | |
int real,img; | |
public: | |
cmplx(int x,int y); | |
void add(cmplx a,cmplx b); | |
void display(); | |
}; | |
cmplx::cmplx(int x=0,int y=0){ | |
real=x; | |
img=y; | |
} | |
void cmplx::add(cmplx a,cmplx b){ | |
real=a.real+b.real; | |
img=a.img+b.img; | |
} | |
void cmplx::display(){ | |
cout<<"The addition of two complex numbers is "<<real<<" + "<<img<<" i\n"; | |
} | |
int main() | |
{ | |
int x,y; | |
cout<<"Enter the real and imaginary part of the first complex number.."; | |
cin>>x>>y; | |
cmplx a(x,y); | |
cout<<"Enter the real and imaginary part of the second complex number.."; | |
cin>>x>>y; | |
cmplx b(x,y); | |
cmplx c; | |
c.add(a,b); | |
c.display(); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment