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

Assignment N5

The document is an assignment by Shreya Ravindra Desai that demonstrates an OOP program in C++ for multiplying two complex numbers using operator overloading. It defines a Complex class with methods for multiplication and displaying the complex number. The program creates two complex numbers, multiplies them, and displays the results.

Uploaded by

shreya.d2829
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 views

Assignment N5

The document is an assignment by Shreya Ravindra Desai that demonstrates an OOP program in C++ for multiplying two complex numbers using operator overloading. It defines a Complex class with methods for multiplication and displaying the complex number. The program creates two complex numbers, multiplies them, and displays the results.

Uploaded by

shreya.d2829
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

Assignment No:6

Name: Shreya Ravindra Desai


Roll No: 9354
//Q:Write OOP program to perform multiplication of two
complex numbers using binary operator overloading

#include <iostream.h>
#include <conio.h>
class Complex {
private:
float real;
float imag;
public:
Complex(float r = 0, float i = 0) : real(r), imag(i) {}
Complex operator*(const Complex& c)
{
Complex temp;
temp.real = (real * c.real) - (imag * c.imag);
temp.imag = (real * c.imag) + (imag * c.real);
return temp;
}
void display() {
if (imag < 0)
cout << real << " - " << -imag << "i" << endl;
else
cout << real << " + " << imag << "i" << endl;
}
};
void main()
{
clrscr();
Complex c1(3, 2); // 3 + 2i
Complex c2(1, 7); // 1 + 7i
Complex c3 = c1 * c2;
cout << "First complex number: ";
c1.display();
cout << "Second complex number: ";
c2.display();
cout << "Result of multiplication: ";
c3.display();
getch();
}
/*
First complex number: 3 + 2i
Second complex number: 1 + 7i
Result of multiplication: -11 + 23i
*/

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy