OOOP1
OOOP1
class Complex {
float x; // Real part
float y; // Imaginary part
public:
// Default constructor
Complex() : x(0), y(0) {}
// Parameterized constructor
Complex(float real, float imag) : x(real), y(imag) {}
// Overloaded + operator
Complex operator+(const Complex& c) const {
return Complex(x + c.x, y + c.y); // Adds real and imaginary parts
}
// Overloaded * operator
Complex operator*(const Complex& c) const {
return Complex((x * c.x) - (y * c.y), (y * c.x) + (x * c.y)); // Multiplies complex numbers
}
c3 = c1 + c2; // Addition
c4 = c1 * c2; // Multiplication
return 0;
}
OUTPUT:-
Default constructor value:
0+0i