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 21:00
Simon says is a memory game where "simon" outputs a sequence of 10 characters (r, g, b, y) and the user must repeat the sequence. create a for loop that compares the two strings starting from index 0. for each match, add one point to userscore. upon a mismatch, exit the loop using a break statement. assume simonpattern and userpattern are always the same length. ex: the following patterns yield a userscore of 4: simonpattern: rrgbryybgy userpattern: rrgbbrybgy
Answers: 2
question
Computers and Technology, 23.06.2019 00:00
What season was better from fortnite?
Answers: 2
question
Computers and Technology, 23.06.2019 14:30
Choose the answers that best complete each sentence. on average,are more expensive than other kinds of postsecondary schools. the cost of room and board includes. to save money, some students attend auniversity in their home state.
Answers: 2
question
Computers and Technology, 24.06.2019 06:30
Ineed to know the anwser to all these questions
Answers: 2
You know the right answer?
Assignment: Complex Number (C++ Coding Question) For this assignment, you need to implement several...
Questions
question
English, 16.12.2020 20:30
question
History, 16.12.2020 20:30
question
Health, 16.12.2020 20:30
question
Mathematics, 16.12.2020 20:30
question
Mathematics, 16.12.2020 20:30
question
Business, 16.12.2020 20:30
question
English, 16.12.2020 20:30
question
Mathematics, 16.12.2020 20:30
Questions on the website: 13722363