0% found this document useful (0 votes)
5 views2 pages

Assignment 3

The document contains a C++ program that defines a Complex class for handling complex numbers. It includes methods for addition and multiplication of complex numbers, as well as a display function to output the complex number in standard form. The main function demonstrates the creation of two complex numbers, their sum, and their product, displaying the results accordingly.

Uploaded by

21questionpaper
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)
5 views2 pages

Assignment 3

The document contains a C++ program that defines a Complex class for handling complex numbers. It includes methods for addition and multiplication of complex numbers, as well as a display function to output the complex number in standard form. The main function demonstrates the creation of two complex numbers, their sum, and their product, displaying the results accordingly.

Uploaded by

21questionpaper
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/ 2

Assignment-3

#include<iostream>
using namespace std;
class Complex{
public:
double R,I;
Complex(){
R=0;
I=0;
}
Complex(double r,double i){
R=r;
I=i;
}
Complex operator+(Complex obj){
Complex temp;
temp.R=R+obj.R;
temp.I=I+obj.I;
return temp;
}
Complex operator*(Complex O){
Complex T;
T.R=R*O.R-I*O.I;
T.I=R*O.I+I*O.R;
return T;
}
void Display(){
cout<<R;
if(I>=0){
cout<<"+"<<I<<"i";
}else{
cout<<"-"<<-I<<"i";
}
cout<<endl;
}
};
int main(){
Complex C1(5,7),C2(3,2);
Complex Sum=C1+C2;
Complex Product=C1*C2;
cout<<"First Complex Number is:";
C1.Display();
cout<<"Second Complex Number is:";
C2.Display();
cout<<"Sum of the two Complex Numbers is:";
Sum.Display();
cout<<"Multiplication of the two Complex Numbers is:";
Product.Display();
return 0;
}
Output

You might also like