#include <iostream>
using namespace std;
class Complex {
private:
float real;
float imag;
public:
// Constructor to initialize complex number
Complex(float r = 0, float i = 0) : real(r), imag(i) {}
// Function to set the value of the complex number
void setValue(float r, float i) {
real = r;
imag = i;
// Function to show the value of the complex number
void showValue() const {
cout << "Complex Number: " << real << " + " << imag << "i" << endl;
// Function to add two complex numbers
Complex add(const Complex& c) const {
return Complex(real + [Link], imag + [Link]);
// Function to subtract two complex numbers
Complex subtract(const Complex& c) const {
return Complex(real - [Link], imag - [Link]);
}
// Function to multiply two complex numbers
Complex multiply(const Complex& c) const {
float r = real * [Link] - imag * [Link];
float i = real * [Link] + imag * [Link];
return Complex(r, i);
// Function to multiply the complex number with a scalar value
Complex multiplyScalar(float scalar) const {
return Complex(real * scalar, imag * scalar);
};
int main() {
Complex c1(3, 4), c2(1, 2);
// Showing the values of the complex numbers
cout << "Complex number c1: ";
[Link]();
cout << "Complex number c2: ";
[Link]();
// Adding complex numbers
Complex resultAdd = [Link](c2);
cout << "Addition result: ";
[Link]();
// Subtracting complex numbers
Complex resultSub = [Link](c2);
cout << "Subtraction result: ";
[Link]();
// Multiplying complex numbers
Complex resultMul = [Link](c2);
cout << "Multiplication result: ";
[Link]();
// Multiplying complex number with a scalar
float scalar = 2;
Complex resultScalar = [Link](scalar);
cout << "Multiplying c1 by scalar " << scalar << ": ";
[Link]();
return 0;
}`