Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 216
  • Last Modified:

??? Need help on this question!!! URGENT PLZ!!

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:

using namespace std;

class Impedance {

        float resistance;
        float reactance;
        float impedance_mag;
        float phaseangle;

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.


2 Solutions
What is this, a programming class or an electrical engineering class?

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:


>> What is this, a programming class or an electrical engineering class?

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 & i) const //total series IMP.
  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.

Featured Post

Concerto's Cloud Advisory Services

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.

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