Addition of Two Complex Numbers
Addition of Two Complex Numbers
com/c/ComputerScienceAcademy7
video link : h ps://youtu.be/oYcBpVAtOU8
*/
/* #include<iostream.h>
#include<conio.h>
class complex
{
float areal, aimg;
float breal, bimg;
float creal, cimg;
public:
void getdata()
{
cout<<"Enter 1st complex number: ";
cin>>areal>>aimg;
void display()
{
cout<<"1st complex number : ";
cout<<areal<<" + "<<aimg<<"i"<<endl;
cout<<"Sum = ";
cout<<creal<<" + "<<cimg<<"i"<<endl;
void add();
};
void complex::add()
{
creal = areal + breal;
cimg = aimg + bimg;
void main()
{
clrscr();
complex c;
c.getdata();
c.add();
c.display();
getch();
*/
2. Addi on of two complex numbers by object as return data type and argument.
#include<iostream.h>
#include<conio.h>
class complex
{
float real, img;
public:
void getdata()
{
cin>>real>>img; //c1.real = 2 c1.img = 3
//c2.real = 5 c2.img = 4
}
void display()
{
cout<<real<<" + "<<img<<"i"<<endl;
};
return c3;
void main()
{
clrscr();
c3 = c1.add(c2);
cout<<"sum = ";
c3.display();
getch();