Skip to main content

Posts

Showing posts with the label Write a program to add two complex numbers of two different classes.

Write a program to add two complex numbers of two different classes.

 Here's a program to add two complex numbers of two different classes: #include <iostream> using namespace std; class Complex1 { private:     double real;     double imag; public:     Complex1(double r = 0, double i = 0) {         real = r;         imag = i;     }     void display() {         cout << real << " + " << imag << "i" << endl;     } }; class Complex2 { private:     double real;     double imag; public:     Complex2(double r = 0, double i = 0) {         real = r;         imag = i;     }     void display() {         cout << real << " + " << imag << "i" << endl;     }     Complex2 operator+(const Complex1& c1) {         Complex2 temp; ...