Skip to content

Commit

Permalink
Merge pull request kothariji#178 from Aditya-1904/master
Browse files Browse the repository at this point in the history
Created  C++ Complex numbers  program
  • Loading branch information
kothariji authored Oct 20, 2020
2 parents b31ff4d + 280cb27 commit 9b0b6e0
Showing 1 changed file with 47 additions and 0 deletions.
47 changes: 47 additions & 0 deletions C++ Complex numbers
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
#include<iostream>
#include<new>
using namespace std;
class complex
{
float real,img;
public:

complex(float a,float b)
{
real=a;
img=b;
}
complex(float a)
{
real=a;
img=1;
}
complex(complex &p)
{
real=p.real;
img=p.img;
}
void display()
{
cout<<endl<<real<<"+i"<<img;
}
complex& sum(complex &z)
{
complex w(0,0);
w.real=this->real+z.real;
w.img=this->img+z.img;
return w;
}
};
int main()
{
complex *c1=new complex(2.0,3);
complex *c2=new complex(4);
complex *c3=new complex(*c1);
c1->display();
c2->display();
c3->display();
*c3=c2->sum(*c1);
c3->display();
return 0;
}

0 comments on commit 9b0b6e0

Please sign in to comment.