dinorama
asked on
??? 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:
#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.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.