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++
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++
![](/static/compass_v2/shared-icons/check-mark.png)
Step by step
Solved in 3 steps with 1 images
![Blurred answer](/static/compass_v2/solution-images/blurred-answer.jpg)
![Computer Networking: A Top-Down Approach (7th Edi…](https://www.bartleby.com/isbn_cover_images/9780133594140/9780133594140_smallCoverImage.gif)
![Computer Organization and Design MIPS Edition, Fi…](https://www.bartleby.com/isbn_cover_images/9780124077263/9780124077263_smallCoverImage.gif)
![Network+ Guide to Networks (MindTap Course List)](https://www.bartleby.com/isbn_cover_images/9781337569330/9781337569330_smallCoverImage.gif)
![Computer Networking: A Top-Down Approach (7th Edi…](https://www.bartleby.com/isbn_cover_images/9780133594140/9780133594140_smallCoverImage.gif)
![Computer Organization and Design MIPS Edition, Fi…](https://www.bartleby.com/isbn_cover_images/9780124077263/9780124077263_smallCoverImage.gif)
![Network+ Guide to Networks (MindTap Course List)](https://www.bartleby.com/isbn_cover_images/9781337569330/9781337569330_smallCoverImage.gif)
![Concepts of Database Management](https://www.bartleby.com/isbn_cover_images/9781337093422/9781337093422_smallCoverImage.gif)
![Prelude to Programming](https://www.bartleby.com/isbn_cover_images/9780133750423/9780133750423_smallCoverImage.jpg)
![Sc Business Data Communications and Networking, T…](https://www.bartleby.com/isbn_cover_images/9781119368830/9781119368830_smallCoverImage.gif)