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 = ??     CODE HERE } Imaginary::Imaginary(int new_coeff) { //One parameter cstor     //coeff = ??     CODE HERE  } int Imaginary::get_coeff() const { //Get function        CODE HERE } Imaginary Imaginary::operator-(const Imaginary& rhs) const {     return Imaginary(coeff-rhs.coeff); } Imaginary Imaginary::operator*(const int& rhs) const {     //5i * 2 = 10i CODE HERE } int Imaginary::operator*(const Imaginary& rhs) const {     i * i = -1 CODE HERE } //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; } main.cc #include #include #include #include "imaginary.h" //YOU: include the header file for complex numbers CODE HERE using namespace std; int main() {     cout << boolalpha; //Print "true" instead of "1" when outputting bools     Imaginary i,j; //These three lines are test code, delete them later     cin >> i >> j; //Read two Imaginaries in - won't work till cstors done     cout << i+j << endl; //Output the sum of them     while (true) {         //YOU: Read in a complex number CODE HERE         //YOU: If it is 0 0, then break or exit CODE HERE         exit(EXIT_SUCCESS);         //YOU: Read in an operator (+,-,*,==,or ^) CODE HERE         //YOU: Read in the second operand (another complex or an int) CODE HERE         //YOU: Output the result CODE HERE     } } HELP ME WITH THE HOMEWORK TYPE CODE HERE. 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

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 = ??
    CODE HERE
}

Imaginary::Imaginary(int new_coeff) { //One parameter cstor
    //coeff = ??
    CODE HERE 
}

int Imaginary::get_coeff() const { //Get function
   
   CODE HERE
}

Imaginary Imaginary::operator-(const Imaginary& rhs) const {
    return Imaginary(coeff-rhs.coeff);
}

Imaginary Imaginary::operator*(const int& rhs) const {
    //5i * 2 = 10i

CODE HERE
}

int Imaginary::operator*(const Imaginary& rhs) const {
    i * i = -1

CODE HERE
}

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

main.cc
#include <iostream>
#include <iomanip>
#include <cstdlib>
#include "imaginary.h"
//YOU: include the header file for complex numbers

CODE HERE

using namespace std;

int main() {
    cout << boolalpha; //Print "true" instead of "1" when outputting bools
    Imaginary i,j; //These three lines are test code, delete them later
    cin >> i >> j; //Read two Imaginaries in - won't work till cstors done
    cout << i+j << endl; //Output the sum of them
    while (true) {
        //YOU: Read in a complex number

CODE HERE

        //YOU: If it is 0 0, then break or exit

CODE HERE
        exit(EXIT_SUCCESS);

        //YOU: Read in an operator (+,-,*,==,or ^)

CODE HERE

        //YOU: Read in the second operand (another complex or an int)

CODE HERE

        //YOU: Output the result

CODE HERE
    }
}

HELP ME WITH THE HOMEWORK TYPE CODE HERE. THANK YOU SO MUCH c++

Expert Solution
steps

Step by step

Solved in 3 steps with 1 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