omplex.h #pragma once #include #include "imaginary.h" 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 operator^(const int &exponent) const;         friend ostream& operator<<(ostream &lhs,const Complex& rhs);         friend istream& operator>>(istream &lhs,Complex& rhs); }; 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 code.   Complex::Complex() { }   Complex::Complex(int new_real, Imaginary new_imagine) { }   Complex Complex::operator+(const Complex &rhs) const { }   Complex Complex::operator-(const Complex &rhs) const { }   Complex Complex::operator*(const Complex &rhs) const { }   bool Complex::operator==(const Complex &rhs) const { }   Complex Complex::operator^(const int &exponent) const { }   //This function should output 3+5i for Complex(3,5), etc. ostream& operator<<(ostream &lhs,const Complex& rhs) {     //Output a Complex here }   //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 } imaginary.h #pragma once #include 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); }; imaginary.cc #include "imaginary.h" #include using namespace std;   //Sample Code - I have done the addition operator for you so you can see //what a functioning operator should look like. Given this function below, //in main() you could write the following code: //  Imaginary foo(3); //foo is 3i //  Imaginary bar(5); //bar is 5i //  foo = foo + bar; //foo will become 8i //In the above example, this function would get called on foo, with //bar being passed in as the parameter named rhs (right hand side). Imaginary Imaginary::operator+(const Imaginary& rhs) const {     return Imaginary(coeff+rhs.coeff); //My coeff is 3; rhs.coeff is 5. So construct a new one with a coeff of 8. }   //These you will need to implement yourself. //They currently are just stub functions Imaginary::Imaginary() { //Default cstor     //coeff = ?? }   Imaginary::Imaginary(int new_coeff) { //One parameter cstor     //coeff = ?? }   int Imaginary::get_coeff() const { //Get function     return 0; //Change this }   Imaginary Imaginary::operator-(const Imaginary& rhs) const {     return Imaginary(coeff-rhs.coeff); }   Imaginary Imaginary::operator*(const int& rhs) const { //5i * 2 = 10i }   int Imaginary::operator*(const Imaginary& rhs) const {     //i * i = -1 }   //This function is functional Imaginary Imaginary::operator=(const Imaginary& rhs) {     coeff = rhs.coeff;     return rhs; }   //This function is functional Imaginary Imaginary::operator=(const int& rhs) {     coeff = rhs;     return Imaginary(rhs); }   bool Imaginary::operator==(const Imaginary& rhs) const {     return (true); }   //This function is done for you. It will allow you to cout variables of type Imaginary. //For example, in main you could write: //  Imaginary foo(2); //  cout << foo << endl; //And this would print out "2i" ostream& operator<<(ostream& lhs, const Imaginary& rhs) {     lhs << showpos;     lhs << rhs.coeff << "i"; //Will echo +4i or +0i or -3i or whatever     lhs << noshowpos;     return lhs; }   istream& operator>>(istream& lhs, Imaginary& rhs) {     int i;     lhs >> i;     rhs.coeff = i;     return lhs; } HELP ME WITH HOMEWORK I CONFUSE. THANK YOU SO MUCH C++

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

complex.h

#pragma once

#include <iostream>

#include "imaginary.h"

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 operator^(const int &exponent) const;

        friend ostream& operator<<(ostream &lhs,const Complex& rhs);

        friend istream& operator>>(istream &lhs,Complex& rhs);

};

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 code.

 

Complex::Complex() {

}

 

Complex::Complex(int new_real, Imaginary new_imagine) {

}

 

Complex Complex::operator+(const Complex &rhs) const {

}

 

Complex Complex::operator-(const Complex &rhs) const {

}

 

Complex Complex::operator*(const Complex &rhs) const {

}

 

bool Complex::operator==(const Complex &rhs) const {

}

 

Complex Complex::operator^(const int &exponent) const {

}

 

//This function should output 3+5i for Complex(3,5), etc.

ostream& operator<<(ostream &lhs,const Complex& rhs) {

    //Output a Complex here

}

 

//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

}

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);

};

imaginary.cc

#include "imaginary.h"

#include <iomanip>

using namespace std;

 

//Sample Code - I have done the addition operator for you so you can see

//what a functioning operator should look like. Given this function below,

//in main() you could write the following code:

//  Imaginary foo(3); //foo is 3i

//  Imaginary bar(5); //bar is 5i

//  foo = foo + bar; //foo will become 8i

//In the above example, this function would get called on foo, with

//bar being passed in as the parameter named rhs (right hand side).

Imaginary Imaginary::operator+(const Imaginary& rhs) const {

    return Imaginary(coeff+rhs.coeff); //My coeff is 3; rhs.coeff is 5. So construct a new one with a coeff of 8.

}

 

//These you will need to implement yourself.

//They currently are just stub functions

Imaginary::Imaginary() { //Default cstor

    //coeff = ??

}

 

Imaginary::Imaginary(int new_coeff) { //One parameter cstor

    //coeff = ??

}

 

int Imaginary::get_coeff() const { //Get function

    return 0; //Change this

}

 

Imaginary Imaginary::operator-(const Imaginary& rhs) const {

    return Imaginary(coeff-rhs.coeff);

}

 

Imaginary Imaginary::operator*(const int& rhs) const {

//5i * 2 = 10i

}

 

int Imaginary::operator*(const Imaginary& rhs) const {

    //i * i = -1

}

 

//This function is functional

Imaginary Imaginary::operator=(const Imaginary& rhs) {

    coeff = rhs.coeff;

    return rhs;

}

 

//This function is functional

Imaginary Imaginary::operator=(const int& rhs) {

    coeff = rhs;

    return Imaginary(rhs);

}

 

bool Imaginary::operator==(const Imaginary& rhs) const {

    return (true);

}

 

//This function is done for you. It will allow you to cout variables of type Imaginary.

//For example, in main you could write:

//  Imaginary foo(2);

//  cout << foo << endl;

//And this would print out "2i"

ostream& operator<<(ostream& lhs, const Imaginary& rhs) {

    lhs << showpos;

    lhs << rhs.coeff << "i"; //Will echo +4i or +0i or -3i or whatever

    lhs << noshowpos;

    return lhs;

}

 

istream& operator>>(istream& lhs, Imaginary& rhs) {

    int i;

    lhs >> i;

    rhs.coeff = i;

    return lhs;

}

HELP ME WITH HOMEWORK I CONFUSE. THANK YOU SO MUCH C++

main.cc
#include <iostream>
#include <iomanip>
#include <cstdlib>
#include "imaginary.h"
IYOU: include the header file for complex numbers
using namespace std:
|
int main() {
COut << boolalpha: //Print "true" instead of "1" when outputting bools
Imaginary įj; /These three lines are test code, delete them later
GiO >> i >> j; I/Read two Imaginaries in - won't work till cstors, done
Cout << iti << endl: //Output the sum of them
while (true) {
IYOU: Read in a complex number
IYOU: If it is 0 0, then break or exit
exit(EXIT_SUCCESS);
IYOU: Read in an operator (+*,==,or ^)
IYOU: Read in the second operand (another complex or an int)
IYOU: Output the result
}
}
Transcribed Image Text:main.cc #include <iostream> #include <iomanip> #include <cstdlib> #include "imaginary.h" IYOU: include the header file for complex numbers using namespace std: | int main() { COut << boolalpha: //Print "true" instead of "1" when outputting bools Imaginary įj; /These three lines are test code, delete them later GiO >> i >> j; I/Read two Imaginaries in - won't work till cstors, done Cout << iti << endl: //Output the sum of them while (true) { IYOU: Read in a complex number IYOU: If it is 0 0, then break or exit exit(EXIT_SUCCESS); IYOU: Read in an operator (+*,==,or ^) IYOU: Read in the second operand (another complex or an int) IYOU: Output the result } }
Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 5 steps with 2 images

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