subject

Assignment: Complex Number (C++ Coding Question) For this assignment, you need to implement several member functions and operators:
Type converter from double to Complex, in which the double becomes the real part of the complex number and the imaginary part remains 0.
Addition of two complex numbers using operator+
Subtraction of two complex numbers using operator-
Unary negation of a complex number using operator-.
Multiplication of two complex numbers using operator*
Division of two complex numbers using operator/
Find the conjugate of a complex number by overloading unary operator~.
Begin with the Complex number from class and extend it to support these operators. Here are the prototypes you should use for these member functions:
Below is the code to be completed:
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
template
typename std::enable_if::is_integer, bool>::type
almost_equal(T x, T y, int ulp)
{
// the machine epsilon has to be scaled to the magnitude of the values used
// and multiplied by the desired precision in ULPs (units in the last place)
return std::fabs(x-y) <= std::numeric_limits::epsilon() * std::fabs(x+y) * ulp
// unless the result is subnormal
|| std::fabs(x-y) < std::numeric_limits::min();
}
using namespace std;
class Complex {
private:
double real;
double imag;
public:
Complex():real(0), imag(0) {}
Complex(double re, double im)
{
real = re; imag = im;
}
Complex operator+(const Complex &rhs) const
{
Complex c;
// To do
return c;
}
Complex operator-(const Complex &rhs) const
{
Complex c;
// To do
return c;
}
Complex operator*(const Complex &rhs) const
{
Complex c;
// To do
return c;
}
Complex operator/(const Complex &rhs) const; // implement divide
Complex operator-() const // negation
{
Complex c;
// To do
return c;
}
Complex operator~() const // conjugation
{
Complex c;
// to do
return c;
}
// DO NOT MODIFY BELOW THIS
bool operator==(const Complex &other) const {
return almost_equal(real, other. real,2) && almost_equal(imag, other. imag,2);
}
bool operator!=(const Complex &other) const {
return !operator==(other);
}
friend ostream& operator<<(ostream&,const Complex &c);
};
ostream& operator<< (ostream& out, const Complex &c)
{
if (c. imag < 0)
out << "(" << c. real << " - " << -c. imag << "j)" ;
else
out << "(" << c. real << " + " << c. imag << "j)" ;
return out;
}
int main()
{
Complex z;
Complex j(0,1);
Complex x(5,0);
std::cout << "j = " << j << std::endl;
std::cout << "x = " << x << std::endl;
Complex y(1,1);
Complex c;
c = y + j*10 ; // assign y to c
std::cout << "c = " << c << std::endl;
return 0;
}

ansver
Answers: 1

Another question on Computers and Technology

question
Computers and Technology, 22.06.2019 03:30
Jessie has received a contract to build a real-time application for a baker. however, the baker doesn't want to invest too much money. his only requirement is that he wants the customers to know which cupcakes are available at what time and in what quantity. so his core requirement is that the details of product should be in real time. what platform can jessie use to develop this application?
Answers: 1
question
Computers and Technology, 22.06.2019 22:30
What is the most popular genre of video games?
Answers: 1
question
Computers and Technology, 24.06.2019 00:00
The gene form of a trait is called a(n) 
Answers: 2
question
Computers and Technology, 24.06.2019 02:30
Which option completes the explanation for conflict of interest in an organization
Answers: 1
You know the right answer?
Assignment: Complex Number (C++ Coding Question) For this assignment, you need to implement several...
Questions
question
Mathematics, 04.08.2019 05:30
Questions on the website: 13722363