Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

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.

2 Solutions

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.

Tackle projects and never again get stuck behind a technical roadblock.

Join Now
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