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() {
real = 0;
imagine = 0;
}
Complex::Complex(int new_real, Imaginary new_imagine) {
real = new_real;
image = new_image;
}
Complex Complex::operator+(const Complex &rhs) const {
Complex num;
num.real = real + rhs.real;
num.imagine = imagine + rhs.imagine;
return num;
}
Complex Complex::operator-(const Complex &rhs) const {
Complex num;
num.real = real – rhs.real;
num.imagine = imagine – rhs.imagine;
return num;
}
Complex Complex::operator*(const Complex &rhs) const {
Complex num;
num.real = (real * rhs.real) – (imagine * rhs.imagine);
num.imagine = (real * rhs.imagine) + (imagine * rhs.real);
return num;
}
bool Complex::operator==(const Complex &rhs) const {
if (real == rhs.real && imagine == rhs.imagine) {
return true;
}
else{
return false;
}
}
//Complex exponent
Complex Complex::operator^(const int &exponent) const {
CODE HERE
}
//This function should output 3+5i for Complex(3,5), etc.
ostream& operator<<(ostream &lhs,const Complex& rhs) {
//Output a Complex here
CODE 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
CODE 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);
};
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 THE HOMEWORK TYPE CODE. THANK YOU SO MUCH c++
Delivering a high-quality product at a reasonable price is not enough anymore.
That’s why we have developed 5 beneficial guarantees that will make your experience with our service enjoyable, easy, and safe.
You have to be 100% sure of the quality of your product to give a money-back guarantee. This describes us perfectly. Make sure that this guarantee is totally transparent.
Read moreEach paper is composed from scratch, according to your instructions. It is then checked by our plagiarism-detection software. There is no gap where plagiarism could squeeze in.
Read moreThanks to our free revisions, there is no way for you to be unsatisfied. We will work on your paper until you are completely happy with the result.
Read moreYour email is safe, as we store it according to international data protection rules. Your bank details are secure, as we use only reliable payment systems.
Read moreBy sending us your money, you buy the service we provide. Check out our terms and conditions if you prefer business talks to be laid out in official language.
Read more
Recent Comments