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

Posted on 2004-11-13
Last Modified: 2010-04-01
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.


Question by:dinorama
    LVL 22

    Assisted Solution

    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:

    LVL 86

    Accepted Solution

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

    Enabling OSINT in Activity Based Intelligence

    Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

    Join & Write a Comment

    What is C++ STL?: STL stands for Standard Template Library and is a part of standard C++ libraries. It contains many useful data structures (containers) and algorithms, which can spare you a lot of the time. Today we will look at the STL Vector. …
    This article will show you some of the more useful Standard Template Library (STL) algorithms through the use of working examples.  You will learn about how these algorithms fit into the STL architecture, how they work with STL containers, and why t…
    The viewer will learn how to use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.
    The viewer will learn how to user default arguments when defining functions. This method of defining functions will be contrasted with the non-default-argument of defining functions.

    732 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    19 Experts available now in Live!

    Get 1:1 Help Now