You have to implement the other 3 operators, '-', '*', and '/', which are defined as follows. Suppose
Z1 = x1 + y1i
Z2 = x2 + y2i
are complex numbers, then
Z1 - Z2 = (x1 - x2) + (y1 - y2)i
Z1 * Z2 = (x1 x2 - y1 y2) + (x1 y2 + x2 y1)i
Z1 / Z2 = (x1 x2 +
y1 y2) / D + (x2 y1 -
x1 y2)/D i
where
|
Here is the code for your problem.
#include <iostream>
#include <cmath>
using namespace std;
class Complex
{
private:
double real, imag;
public:
Complex(double r = 0, double i = 0)
{
real = r;
imag = i;
}
// This is automatically called when '+' is used with
// between two Complex objects
Complex operator+(Complex const &obj)
{
Complex res;
res.real = real + obj.real;
res.imag = imag + obj.imag;
return res;
}
// This is automatically called when '-' is used with
// between two Complex objects
Complex operator-(Complex const &obj)
{
Complex res;
res.real = real - obj.real;
res.imag = imag - obj.imag;
return res;
}
// This is automatically called when '*' is used with
// between two Complex objects
Complex operator*(Complex const &obj)
{
Complex res;
res.real = real * obj.real - imag * obj.imag;
res.imag = real * obj.imag + obj.real * imag;
return res;
}
// This is automatically called when '/' is used with
// between two Complex objects
Complex operator/(Complex const &obj)
{
Complex res;
double D = pow(obj.real, 2) + pow(obj.imag, 2);
res.real = (real * obj.real + imag * obj.imag) / D;
res.imag = (obj.real * imag - real * obj.imag) / D;
return res;
}
void print()
{
cout << real << " + i" << imag << endl;
}
};
int main()
{
Complex c1(10, 5), c2(2, 4);
Complex c3 = c1 + c2; // An example call to "operator+"
c3.print();
c3 = c1 - c2; // An example call to "operator-"
c3.print();
c3 = c1 * c2; // An example call to "operator*"
c3.print();
c3 = c1 / c2; // An example call to "operator/"
c3.print();
}
Here is the screenshot of the code if the indentation is not clear.
Here is the output of the code.
Hope this helps.
Please rate the answer if you like it.
Do leave a comment.Any suggestion/query is much appreciated.
You have to implement the other 3 operators, '-', '*', and '/', which are defined as...
THIS IS THE QUESTION FROM THE SUBJECT ELECTROMAGNETICS AND YOU HAVE TO TAKE VALUE OF YOUR OWN. FIRST WRITE THE QUESTION WITH VALUES AND THEN SOLVE IT .... find “E” at point P (x1, y1, z1) in free space due to the following charge distributions: point charge, A nC, at point P (x2, y2, z2) in free space; uniform line charge density, B nC/m, at x = t, y = t1; uniform surface charge density, C nC/m2 at x =...
THE QUESTION I AM SHARING WITH YOU IS THE QUESTION FROM THE SUBJECT ELECTROMAGNETICS IN THIS QUESTION WE HAVE TO USE MATLAB PLEASE COMMENT EACH STEP AND DO YOUR BEST TO SLOVE IT Question2: [5 marks] Use MATLAB to write a generic program to find “E” at point P (x1, y1, z1) in free space due to the following charge distributions: point charge, A nC, at point P (x2, y2, z2) in free space; uniform line charge density, B nC/m,...
3 Cual es magnitud de E debido a Q1-38 nC r1( x1-1, y1-3, z1-3) y Q2-47_nC r1( x2-3, y2-5, z2-1 ) en el origen (0,0,0) A) 45.81 N/C B) 24.98 NIC C) 35.18 NIC D) 51.02 NIC r (x1,y1,z1) Q2 r2 (x2,y2,z2) 0 (0,0,0)
16. Find the direction of the force between Q1-5uC r1 (x1-2,y1-3,z1-3) and Q2-4uC r2 (x2-2, y2-3,z2-2) A) 0i 0j-1.3k 21 B) OiOj-56k R12 0 c) 0i 0j-1.45k 17. Find the force (vector) between Q1-33uCr1 (x1-1, y1-2, z1-3) and Q2-63uC r2 (x2-3, y2-3,z2-1) A) .76i .38j -.77k F2 B) .971 48j-.98k R12 C) 1.17i .58j-1.18k D) 1.38i .69-1.39k 16. Find the direction of the force between Q1-5uC r1 (x1-2,y1-3,z1-3) and Q2-4uC r2 (x2-2, y2-3,z2-2) A) 0i 0j-1.3k 21 B) OiOj-56k R12...
(d) Let (x1,x) R..9x 2 yo} (3) S is the set of combinations of (x,x2) which produce at least output level yo.Economists refer to S'as the upper contour set associated with output yo. Assume that x (x,x2) S and y (y,y2) S. That is xfx yo and yy z yo. i) Let z (z1,z2) R.. What must be true for ze S? ( mark) ii) Let z= (z1,z2) x +(1A)y where 02<1 Prove that zE S Hint: Using results on...
Hello I need help understanding these questions show the steps. Thanks. Rather than use the standard definitions of addition and scalar multiplication in R3, suppose these two operations are defined as follows. With these new definitions, is R3 a vector space? Justify your answers. (a) (x1, Y1, 21) + (x2, Y2, 22) = (x1 + x2, Y1 + y2, 21 + 22) c(x, y, z) = (cx, 0, cz) O The set is a vector space. O The set is...
2. [1 point] Linear independence: a. Let x1=[1 2 3] , y1=[4 5 6] and z1=[5 7 9]. Are three of them independent? Show which MATLAB command(s) can be used to find out the answer. Also show the results of using the command(s). b. Repeat the process for x2=[1 0 3], y2=[4 5 6] and z2=[5 2 9].
Two events occur in an inertial system O as follows: Event 1: x1=0, y1=0, z1=0, t1=0 s Event 2: x2=2.50 c.s, y2=0, z2=0, t2=1.75 s Describe the motion of a frame O’ with respect to O in which these events appear to be simultaneous. Explain your answer. Describe the motion of a frame O’ with respect to O in which these events appear to happen at the same place. Explain your answer. What values do Δs2and Δs’2have for these two events in O and...
2. Find the force (vector) between Q1-40uC r1 (x1-2,y1-2,z1-3) and Q2-47uCr2 (x2-3,y2-3,z2-1) A) .68i 34j -69k B) 1.25 .62j-1.26k 12 0 Fi C) 1.44i .72-145k D) 1.06i .53j-1.07k 5. When the coordinates of a system don't have components over the coordinates, we determine that they are D. Rectangular A. Orthogonal C. Inclusive 7. A vector V1 (x=4, y-6, z-8), which is the magnitude of the projection on the YZ plane A) 10 X 1 V 1 B) 8.5 C 13...
The observations make up the population of the variable X: X1 = 2, X2 = 3, X3 = 4 a. Find the population mean of X, μX. b. Find the population standard deviation of X, σX. Suppose that the variable Y is defined as follows: Y = (X – μX) / σX c. Calculate Y1, Y2, and Y3. d. Find the mean of Y, μY e. Find the standard deviation of Y, σY.