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

Other questions on the subject: Computers and Technology

image
Computers and Technology, 22.06.2019 16:30, nxusasmangaliso1191
The most common battery cable terminal is a that provides a large surface contact area with the ability to tighten the terminal onto the battery post using a nut and bolt.
Answers: 2
image
Computers and Technology, 23.06.2019 07:50, madim1275
Most shops require the technician to enter a starting and ending time on the repair order to track the actual time the vehicle was in the shop and closed out by the office. this time is referred to as _ time ? a. comeback b. ro c. cycle d. lead
Answers: 1
image
Computers and Technology, 23.06.2019 11:00, jaygamer37
What is the name of the sound effect that danny hears
Answers: 1
image
Computers and Technology, 24.06.2019 00:30, sethhdoty
Use the keyword strategy to remember the meaning of the following word. the meaning for the word has been provided. write your keyword and describe the picture you would create in your mind. obfuscate: to make something so confusing that it is difficult to understand.
Answers: 2
You know the right answer?
Assignment: Complex Number (C++ Coding Question) For this assignment, you need to implement several...

Questions in other subjects: