Hello there my C++ experts! :)

I need help in doing this question. You guyz have to help me out how to do this question. It is driving me nuts!! I wrote a bit of the code.. and got stuck at the 2nd function.

Here is the question:

-----------------------------------------------------------------------------------------------------------------------------------------

--Operator Overloading--

Design a class Impedance, which contains four data members: an active resistance R, reactive resistance (reactance) X, impedance magnitude ZM and phase angle θ. The class should use a constructor function to initialize the data members.

The class should also contain six operator functions to perform the following operations:

1. Add impedances connected in series and return equivalent impedance

2. Add impedances connected in parallel and return equivalent impedance

3. Change the sign of the reactance

4. Input an impedance; the user should be able to input an impedance either in

rectangular or polar coordinates

5. Output an impedance in both, rectangular and polar coordinates

6. Calculate the admittance (i.e. 1/Z)

Design the main( ) function, which will test the Impedance class and use all its operator functions.

Note: Z = R+jX, where R is a real part and X an imaginary part of the impedance Z.

Z(magnitude) = sqrt(R^2 + X^2 )

Theta = atan(X/R)

R=Z(magnitude)* cos(theta);

X=Z(magnitude)* sin(theta);

-------------------------------------------------------------------------------------------------------------------------------------------

Here is my partial code:

#include<iostream>

#include<conio.h>

#include<iomanip>

#include<cmath>

using namespace std;

class Impedance {

private:

float resistance;

float reactance;

float impedance_mag;

float phaseangle;

public:

Impedance (float r, float reac, float imp, float phase){

resistance =r;

reactance = reac;

impedance_mag = imp;

phaseangle = phase; }

Impedance operator+(const Impedance &) const;

Impedance operator*(const Impedance &) const;

Impedance operator->(const Impedance &) const;

};

Impedance Impedance::operator+(const Impedance & i) const //total series IMP.

{

Impedance total;

float real, imag;

real = resistance + i.resistance;

imag = reactance + i.reactance;

total = real + imag;

return total;

}

Impedance Impedance::operator*(const Impedance & j) const//total Parallel IMP

{

Impedance total;

float real, imag, imp_tot1, imp_tot2;

real = resistance + j.resistance;

imag = reactance + j.reactance;

imp_tot1 = sqrt( ///What do i do here??? damn i am stuck!

}

------------------------------------------------------------------------------------------------------------------------------------------

I would really appreciate your help.

Thanks

dino.

I need help in doing this question. You guyz have to help me out how to do this question. It is driving me nuts!! I wrote a bit of the code.. and got stuck at the 2nd function.

Here is the question:

--------------------------

--Operator Overloading--

Design a class Impedance, which contains four data members: an active resistance R, reactive resistance (reactance) X, impedance magnitude ZM and phase angle θ. The class should use a constructor function to initialize the data members.

The class should also contain six operator functions to perform the following operations:

1. Add impedances connected in series and return equivalent impedance

2. Add impedances connected in parallel and return equivalent impedance

3. Change the sign of the reactance

4. Input an impedance; the user should be able to input an impedance either in

rectangular or polar coordinates

5. Output an impedance in both, rectangular and polar coordinates

6. Calculate the admittance (i.e. 1/Z)

Design the main( ) function, which will test the Impedance class and use all its operator functions.

Note: Z = R+jX, where R is a real part and X an imaginary part of the impedance Z.

Z(magnitude) = sqrt(R^2 + X^2 )

Theta = atan(X/R)

R=Z(magnitude)* cos(theta);

X=Z(magnitude)* sin(theta);

--------------------------

Here is my partial code:

#include<iostream>

#include<conio.h>

#include<iomanip>

#include<cmath>

using namespace std;

class Impedance {

private:

float resistance;

float reactance;

float impedance_mag;

float phaseangle;

public:

Impedance (float r, float reac, float imp, float phase){

resistance =r;

reactance = reac;

impedance_mag = imp;

phaseangle = phase; }

Impedance operator+(const Impedance &) const;

Impedance operator*(const Impedance &) const;

Impedance operator->(const Impedance &) const;

};

Impedance Impedance::operator+(const

{

Impedance total;

float real, imag;

real = resistance + i.resistance;

imag = reactance + i.reactance;

total = real + imag;

return total;

}

Impedance Impedance::operator*(const

{

Impedance total;

float real, imag, imp_tot1, imp_tot2;

real = resistance + j.resistance;

imag = reactance + j.reactance;

imp_tot1 = sqrt( ///What do i do here??? damn i am stuck!

}

--------------------------

I would really appreciate your help.

Thanks

dino.

Experts Exchange Solution brought to you by

Enjoy your complimentary solution view.

Get every solution instantly with premium.
Start your 7-day free trial.

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Is there a difference *duck*? :o)

To start with the programming part, you need to add a default constructor to your class or rethink your operators:

Impedance Impedance::operator+(const

{

Impedance total;

//...

}

will not work because the only constructor for "Impedance" that you defined takes a bunch of floats, meaning that you either have the values ready at that time or provide ways to set them later, after declarring the object. For the electrical engineering part, all instances need to share the same 'theta' value, since otherwise we've invented a new universe. With this info and knowing that parallel impedances add reciprocally, that shouldn't be a big thing anymore.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
C++

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Experts Exchange Solution brought to you by

Enjoy your complimentary solution view.

Get every solution instantly with premium.
Start your 7-day free trial.

If it's a programming class, the instructor should give you the formulas for series and parallel impedances.

or look at this link which explains all:

http://www.allaboutcircuits.com/vol_2/chpt_3/4.html