Answer to Question #272549 in C++ for ABagha

Question #272549

Create and Implement a C++ program to overload >, <, == operators for the class Complex

numbers. Take two objects of class and compare both objects. Write a driver program to test

your class.


1
Expert's answer
2021-11-28T05:25:24-0500
#include <iostream>
using namespace std;


class Complex
{
private:
    int real, imaginary;


public:
    Complex(int r = 0, int i = 0)
    {
        real = r;
        imaginary = i;
    }
    friend ostream &operator<<(ostream &output, const Complex &c);
    friend istream &operator>>(istream &in, Complex &c);
};


ostream &operator<<(ostream &output, const Complex &c)
{
    output << c.real;
    output << "+i" << c.imaginary << endl;
    return output;
}


istream &operator>>(istream &in, Complex &c)
{
    cout << "Enter Real Part ";
    in >> c.real;
    cout << "Enter imaginary Part ";
    in >> c.imaginary;
    return in;
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS