HELP ME CODE COMPLEX.CC IN istream& operator>>(istream &lhs,Complex& rhs)PLEASE complex.cc #include #include "complex.h" using namespace std; //Class definition file for Complex //YOU: Fill in all of these functions //There are stubs (fake functions) in there now so that it will compile //The stubs should be removed and replaced with your own c Dr // default Complex::Complex() {         real = 0;          imagine = 0; } Complex::Complex(int new_real, Imaginary new_imagine) {         real = new_real;          imagine= new_imagine;          } // + operator overload Complex Complex::operator+(const Complex &rhs) const {             Complex num;         num.real  = real  + rhs.real;             num.imagine = imagine + rhs.imagine;             return num; } // - operator overload Complex Complex::operator-(const Complex &rhs) const {             Complex num;         num.real  = real  - rhs.real;         num.imagine = imagine - rhs.imagine;             return num; }

Computer Networking: A Top-Down Approach (7th Edition)
7th Edition
ISBN:9780133594140
Author:James Kurose, Keith Ross
Publisher:James Kurose, Keith Ross
Chapter1: Computer Networks And The Internet
Section: Chapter Questions
Problem R1RQ: What is the difference between a host and an end system? List several different types of end...
icon
Related questions
Question

HELP ME CODE COMPLEX.CC IN istream& operator>>(istream &lhs,Complex& rhs)PLEASE

complex.cc

#include <iostream>
#include "complex.h"
using namespace std;

//Class definition file for Complex

//YOU: Fill in all of these functions
//There are stubs (fake functions) in there now so that it will compile
//The stubs should be removed and replaced with your own c Dr

// default
Complex::Complex() {
        real = 0; 
        imagine = 0;
}

Complex::Complex(int new_real, Imaginary new_imagine) {
        real = new_real; 
        imagine= new_imagine;
        
}
// + operator overload
Complex Complex::operator+(const Complex &rhs) const {
            Complex num;
        num.real  = real  + rhs.real;    
        num.imagine = imagine + rhs.imagine;    
        return num;
}
// - operator overload
Complex Complex::operator-(const Complex &rhs) const {
            Complex num;
        num.real  = real  - rhs.real;
        num.imagine = imagine - rhs.imagine;    
        return num;
}
// * operator overload
Complex Complex::operator*(const Complex &rhs) const {
            Complex num;
        num.real = real * rhs.real;
        num.imagine = imagine * rhs.imagine;
        return num;
}
// = operator overload

bool Complex::operator==(const Complex &rhs) const {
    if (real == rhs.real && imagine == rhs.imagine) {
    return true;
    }
    else{
        return false;
    }
}

Complex Complex::cmul(Complex c1, Complex c2)
{
    Complex c;
    
    //for real part 
    c.real=( c1.real *c2.real) - (c1.imagine.get_coeff() * c2.imagine.get_coeff());

    // for imaginary part 
    c.imagine= (c1.imagine.get_coeff() *c2.real) + (c2.imagine.get_coeff()* c1.real);
    
    return c;
    
}

Complex Complex::operator^(const int &exponent) const {
    //return Complex(0,0);
    int product=1;

    // multiplying the real part with itself exponent number of times
    for(int i=0; i<exponent; i++)
    {
        product *= real;
    }

    // returning complex number
    return Complex(product, imagine);
}

//This function should output 3+5i for Complex(3,5), etc.
ostream& operator<<(ostream &lhs,const Complex& rhs) {
    //Output a Complex here
    lhs <<rhs.real << rhs.imagine;
    return lhs;
}

//This function should read in two ints, and construct a
// new Complex with those two ints
istream& operator>>(istream &lhs,Complex& rhs) {
    //Read in a Complex here
HElP ME CODE HERE c++
}

complex.h

 

#pragma once
#include <iostream>
#include "imaginary.h"
#include <complex>
using namespace std;

class Complex {
    private:
        int real;
        Imaginary imagine;
    public:
        //YOU: Implement all these functions
        Complex(); //Default constructor
        Complex(int new_real, Imaginary new_imagine); //Two parameter constructor
    Complex operator+(const Complex &rhs) const;
        Complex operator-(const Complex &rhs) const;
        Complex operator*(const Complex &rhs) const;
        bool    operator==(const Complex &rhs) const;
        Complex cmul(Complex c1, Complex c2);
        Complex operator^(const int &exponent) const;
        friend ostream& operator<<(ostream &lhs,const Complex& rhs);
        friend istream& operator>>(istream &lhs,Complex& rhs);
};

imaginary.h

#pragma once
#include <iostream>
using namespace std;

class Imaginary {
    private:
        int coeff; //If 5, then means 5i
    public:
        Imaginary();
        Imaginary(int new_coeff);
        int get_coeff() const;
        Imaginary operator+(const Imaginary& rhs) const; //This is a "constant method"
        Imaginary operator-(const Imaginary& rhs) const;
        int       operator*(const Imaginary& rhs) const;
        Imaginary operator*(const int& rhs) const;
        Imaginary operator=(const int& rhs);
        Imaginary operator=(const Imaginary& rhs);
        bool      operator==(const Imaginary& rhs) const;
        friend ostream& operator<<(ostream& lhs, const Imaginary& rhs);
        friend istream& operator>>(istream& lhs, Imaginary& rhs);
};

Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 3 steps

Blurred answer
Recommended textbooks for you
Computer Networking: A Top-Down Approach (7th Edi…
Computer Networking: A Top-Down Approach (7th Edi…
Computer Engineering
ISBN:
9780133594140
Author:
James Kurose, Keith Ross
Publisher:
PEARSON
Computer Organization and Design MIPS Edition, Fi…
Computer Organization and Design MIPS Edition, Fi…
Computer Engineering
ISBN:
9780124077263
Author:
David A. Patterson, John L. Hennessy
Publisher:
Elsevier Science
Network+ Guide to Networks (MindTap Course List)
Network+ Guide to Networks (MindTap Course List)
Computer Engineering
ISBN:
9781337569330
Author:
Jill West, Tamara Dean, Jean Andrews
Publisher:
Cengage Learning
Concepts of Database Management
Concepts of Database Management
Computer Engineering
ISBN:
9781337093422
Author:
Joy L. Starks, Philip J. Pratt, Mary Z. Last
Publisher:
Cengage Learning
Prelude to Programming
Prelude to Programming
Computer Engineering
ISBN:
9780133750423
Author:
VENIT, Stewart
Publisher:
Pearson Education
Sc Business Data Communications and Networking, T…
Sc Business Data Communications and Networking, T…
Computer Engineering
ISBN:
9781119368830
Author:
FITZGERALD
Publisher:
WILEY