Question
Please CODE complex.hpp, complex.cpp provided, code in c++ please Please make the function work and show a working version of the code!! Do not use
Please CODE complex.hpp, complex.cpp provided, code in c++ please
Please make the function work and show a working version of the code!!
Do not use different functions please use the same functions
-----------------------------------------------
For the assignment, we will modify a program that created a solution for complex numbers using classes. Use the program complex.cpp and complex.hpp, located in this assignments folder. These are the implementation and program that created a class called Complex for performing arithmetic with complex numbers. The class enables so-called complex numbers. These are numbers of the form realPart + imaginaryPart * i
where i is:
For this assignment, you will make changes to the given coding to now include the following upgrades:
Modify the class to enable input and output of complex numbers via overloaded + and - operators, respectively (addition and subtraction). Modify the class to enable input and output of complex numbers via overloaded = and * operators, respectively (assignment and multiplication).
Modify the class to enable input and output of complex numbers via overloaded >> and << operators, respectively (you should remove the print function from the class). Use friend functions to accomplish this.
Overload the == and != operators to allow comparisons of complex numbers.
Add friend member functions to enable input and output of complex numbers via overloaded >> and << operators, respectively (you should remove the print function from the class).
-------------------------------------------------------------------------
YOU MUST USE THESE GIVEN CODE
main complex:
#include
int main() { for (double i = 1; i < 10; ++ i) { Complex y{i * 2.7, i + 3.2}; Complex z{i * 6, i + 8.3};
Complex x; Complex k;
std::cout << "Enter a complex number in the form: (a, b) ? "; std::cin >> k; // demonstrating overloaded >> std::cout << "x: " << x << " y: " << y << " z: " << z << " k: " << k << ' '; // demonstrating overloaded << x = y + z; // demonstrating overloaded + and = std::cout << " x = y + z: " << x << " = " << y << " + " << z << ' '; x = y - z; // demonstrating overloaded - and = std::cout << " x = y - z: " << x << " = " << y << " - " << z << ' '; x = y * z; // demonstrating overloaded * and = std::cout << " x = y * z: " << x << " = " << y << " * " << z << " ";
if (x != k) { // demonstrating overloaded != std::cout << x << " != " << k << ' '; }
std::cout << ' '; x = k;
if (x == k) { // demonstrating overloaded == std::cout << x << " == " << k << ' '; } std::cout << std::endl; }
}
----------------------------------------------------
complex.hpp:
#include
class Complex
{
public:
Complex(double = 0.0, double = 0.0); // default constructor
Complex add(const Complex&) const; // function add
Complex subtract(const Complex&) const; // function subtract
Complex multiply(const Complex&) const; // function multiply
std::string toString() const; // return string representation
void setComplexNumber(double, double); // set complex number
private:
double realPart;
double imaginaryPart;
};
-----------------------------------------------------------
complex.cpp:
#include
Complex::Complex(double real, double imaginary) : realPart(real), imaginaryPart(imaginary) { }
Complex Complex::add(const Complex &right) const { return Complex( realPart + right.realPart, imaginaryPart + right.imaginaryPart); }
Complex Complex::subtract(const Complex &right) const { return Complex(realPart - right.realPart, imaginaryPart - right.imaginaryPart); }
Complex Complex::multiply(const Complex &right) const { return Complex((realPart * right.realPart) - (imaginaryPart * right.imaginaryPart), (imaginaryPart * right.imaginaryPart) + (realPart * right.realPart); }
std::string Complex::toString() const { std::ostringstream output; output << "(" << realPart << ", " << imaginaryPart << ")"; return output.str(); }
void Complex::setComplexNumber(double rp, double ip) { realPart = rp; imaginaryPart = ip; }
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started