0% found this document useful (0 votes)
6 views3 pages

OOP PR 3 (Complex)

The document contains a C++ program that defines a class for complex numbers, allowing operations such as addition, subtraction, multiplication, and division. It prompts the user to input the real and imaginary parts of two complex numbers and then displays the results of the operations. The output includes the entered complex numbers, their sum, difference, product, and quotient.

Uploaded by

anises208
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)
6 views3 pages

OOP PR 3 (Complex)

The document contains a C++ program that defines a class for complex numbers, allowing operations such as addition, subtraction, multiplication, and division. It prompts the user to input the real and imaginary parts of two complex numbers and then displays the results of the operations. The output includes the entered complex numbers, their sum, difference, product, and quotient.

Uploaded by

anises208
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
You are on page 1/ 3

//prajwal popalghat SE A-135

#include<iostream>
using namespace std;
class complex
{
private:
float R1,R2,Ra,I1,I2,Ia,Rs,Is,M1,M2,Dr,Di;
float final;
public:
void read()
{
cout<<"Enter real part of first and second complex number:"<<endl;
cin>>R1>>R2;
cout<<"Enter imaginary part of first and second complex number:"<<endl;
cin>>I1>>I2;
}

void in()
{
cout<<"Your Entered Complex number is"<<endl;
cout<<R1<<" + "<<I1<<"i"<<endl;
cout<<R2<<" + "<<I2<<"i"<<endl<<endl;
}

void sum()
{
Ra=R1+R2;
Ia=I1+I2;
cout<<"The sum of The given complex number is :"<<endl;
cout<<Ra<<" + "<<Ia<<"i"<<endl<<endl;

}
void sub()
{
Rs=R1-R2;
Is=I1-I2;
cout<<"The sub of The given complex number is :"<<endl;
cout<<Rs<<" + "<<Is<<"i";

}
void mult(){

M1=(R1*R2)+(-(I1*I2));
M2=(R1*I2)+(R2*I1);
cout<<"\n\nThe multiplication of The given complex number is :"<<endl;
cout<<M1<<" + "<<M2<<"i"<<endl;
}

void div()
{
float denom = R2*R2 + I2*I2;
Dr = (R1*R2 + I1*I2) / denom;
Di = (I1*R2 - R1*I2) / denom;
cout<<"\n\nThe division of The given complex number is :"<<endl;
cout<<Dr<<" + "<<Di<<"i"<<endl;
}
};
int main(void)
{
complex C1,C2,C3;
C1.read();
C1.in();
C1.sum();
C1.sub();
C1.mult();
C1.div();
}
Output:
Enter real part of first and second complex number:
10
20
Enter imaginary part of first and second complex number:
5
6
Your Entered Complex number is
10 + 5i
20 + 6i

The sum of The given complex number is :


30 + 11i

The sub of The given complex number is :


-10 + -1i

The multiplication of The given complex number is :


170 + 160i

The division of The given complex number is :


0.527523 + 0.0917431i

You might also like