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, 21.06.2019 23:00
What computer network component allows data transfers from one computer to another through a telephone line?
Answers: 1
question
Computers and Technology, 23.06.2019 03:30
In vista and windows 7, the appearance and personalization option allows you to change the
Answers: 1
question
Computers and Technology, 23.06.2019 11:30
Auser is given read permission to a file stored on an ntfs-formatted volume. the file is then copied to a folder on the same ntfs-formatted volume where the user has been given full control permission for that folder. when the user logs on to the computer holding the file and accesses its new location via a drive letter, what is the user's effective permission to the file? a. read b. full control c. no access d. modify e. none of the above
Answers: 1
question
Computers and Technology, 23.06.2019 13:30
Best laptops for college [$100-$500 range]?
Answers: 2
You know the right answer?
Assignment: Complex Number (C++ Coding Question) For this assignment, you need to implement several...
Questions
question
Mathematics, 17.10.2020 01:01
Questions on the website: 13722359