0% found this document useful (0 votes)
22 views

Addition of Two Complex Numbers

Class notes addition of 2 complex no.

Uploaded by

saadkhan73212
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
22 views

Addition of Two Complex Numbers

Class notes addition of 2 complex no.

Uploaded by

saadkhan73212
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

channel link : h ps://www.youtube.

com/c/ComputerScienceAcademy7
video link : h ps://youtu.be/oYcBpVAtOU8

/* Addi on of two complex numbers


2 + 3i
4 + 2i
-----------
6 + 5i

1. Addi on of two complex numbers by normal OOP technique.

*/
/* #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;

cout<<"Enter 2nd complex number: ";


cin>>breal>>bimg;

void display()
{
cout<<"1st complex number : ";
cout<<areal<<" + "<<aimg<<"i"<<endl;

cout<<"2nd complex number : ";


cout<<breal<<" + "<<bimg<<"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;

complex add(complex c2);

};

complex complex::add(complex c2)


{
complex c3;
c3.real = real + c2.real;
c3.img = img + c2.img;

return c3;

void main()
{
clrscr();

complex c1, c2, c3;

cout<<"1st complex number: ";


c1.getdata(); //2 3

cout<<"2nd complex number: ";


c2.getdata(); //5 4

c3 = c1.add(c2);

cout<<"sum = ";
c3.display();

getch();

You might also like