0% found this document useful (0 votes)
2 views4 pages

C++ Complex Number Operations

The document presents a C++ program that defines a class for complex numbers, allowing operations such as addition and subtraction. It includes methods for displaying the complex numbers and their results. The program prompts the user for input and outputs the sum and difference of two complex numbers.

Uploaded by

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

C++ Complex Number Operations

The document presents a C++ program that defines a class for complex numbers, allowing operations such as addition and subtraction. It includes methods for displaying the complex numbers and their results. The program prompts the user for input and outputs the sum and difference of two complex numbers.

Uploaded by

drsaranyarcw
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

OBJECT ORIENTED PROGRAMMING WITH C++

\* COMPLEX NUMBER*/

#include<iostream.h>

#include<iomanip.h>

#include<conio.h>

class complexnumber

private:

if(imaginary<0)

cout<<real<<”=”<<imaginary<<”i”<<endl;

else

cout<<real<<”+”<<imaginary<<”i”<<endl;

void add(complexnumber c2)

double r=real+[Link];

double i= imaginary+[Link];

cout<<”sum of 2 complex number:”<<endl;

result(r,i);

void subtract(complexnumber c2)

double r=[Link];

double i= [Link];

cout<<”sum of 2 complex number:”<<endl;

RAJESWARI COLLEGE OF ARTS AND SCIENCE FOR WOMEN


OBJECT ORIENTED PROGRAMMING WITH C++
result(r,i);

void result(double real, double imaginary)

if(imaginary<0)

cout<<real<<”-“<<imaginary <<”i”<<endl;

else

cout<<real<<”+“<<imaginary <<”i”<<endl;

};

void main()

complexnumber c1,c2;

double r1,r2,i1,i2;

cout<<ënter the real and imaginary part of is t complex number:”;

cin>>r1>>i1;

cout<<ënter the real and imaginary part of 2nd complex number:”;

cin>>r2>>i2;

[Link]-value(r1,i1);

[Link]-value(r2,i2);

cout<<”complex number:”;

[Link]-value();

[Link]-value();

[Link](c2);

RAJESWARI COLLEGE OF ARTS AND SCIENCE FOR WOMEN


OBJECT ORIENTED PROGRAMMING WITH C++
[Link](c2);

getch();

RAJESWARI COLLEGE OF ARTS AND SCIENCE FOR WOMEN


OBJECT ORIENTED PROGRAMMING WITH C++

Output:

/*COMPLEX NUMBER*/

ENTER THE REAL NUMBER AND IMAGINARY PART OF A IST


COMPLEX NUMBER: 5 6

ENTER THE REAL AND IMAGINARY PART OF @ND COMPLEX


NUMBER:6 7

COMPLEX NUMBER

5+6i

6+7i

SUM OF @ COMPLEX NUMBER : 11+13i

DIFFERENCE OF TWO COMPLEX NUMBER: -1-1i

RAJESWARI COLLEGE OF ARTS AND SCIENCE FOR WOMEN

You might also like