Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Shown on page 3 is a \"series RLC\" circuit, consisting of a sinusoidal voltage

ID: 3866676 • Letter: S

Question

Shown on page 3 is a "series RLC" circuit, consisting of a sinusoidal voltage source, a resistor, an inductor, and a capacitor. The current I in this circuit changes as the frequency of the sinusoidal voltage changes.

R = Resistance in Ohms ()
L = Inductance in Henries (H)
C = Capacitance in Farads (F)
I = Current in Amperes (A)
E = Sinusoidal voltage in Volts (V), at some frequency, f f = Frequency in Hertz (Hz)

The current, I, can be calculated in the circuit using the following relationships: XL = inductive reactance = 2 f L in ohms ()

XC = capacitive reactance = in ohms ()

Z=total circuitimpedance= inohms() I = current = in Amperes (A)

Program Requirements:

The user should be prompted to input the values for E, R, L, C, finitial and ffinal.

The value for R should be entered in ohms (for example, the user enters 5000.)

The value of E should be entered in volts

The value of C should be entered in mF, uF, or nF (then convert it to F). For example, the user enters 10

mF.

The value of L should be entered in mH or uH (then convert it to H).

The value of finitial and ffinal should be entered in Hz, kHz, or MHz (then convert it to Hz).

Create a table containing values of f, XL, XC, Z, and I for a range of values of f.

Use a loop vary f from finitial to the first value of f greater than or equal to ffinal where f doubles each

time through the loop. For example, if finitial = 100 and ffinal = 1E6, then f = 100, 200, 400, 800, .....

1638400 (this spacing is common as graphs often place frequency on a log scale).

During each pass though the loop call separate functions to calculate XL, XC, and Z.

Use at least two additional user-defined functions.

The results should be displayed in a neat, formatted table with headings, units, etc. The value of the

current, I, should be printed in mA rather than Amperes. An example of what this table might look like

is shown below. The lines in the table are not required, but could be included for extra credit.

Your loop should also determine the maximum value of the current in the table and the corresponding

frequency.

Page 2

The output should the table described above, as well as a title or brief explanation of the program, the values of the inputs, and the maximum value of the current and the frequency where I is maximum (include units with all input and output values).

The results should display f as an integer; XC, XL, and Z using one digit after the decimal point; and I with 3 digits after the decimal point (as shown below). The numbers should not be printed in scientific notation.

Include a loop that will give the user the option of re-running the program.

Include loops to allow the user to correct bad inputs. Test for the following:

Values entered for R, L, C, and E must be positive.

Proper units and prefixes must be used with inputs as described above.

finitial > 1 Hz, ffinal < 1E9 Hz, and ffinal > 2*finitial.

Example Output Table: (for R = 5000 , L = 20 mH, C = 0.02 F, E = 15V, finitial = 100 Hz, and ffinal = 1 MHz). Note: You might be able to print the ohm () symbol using the ASCII extended character set (cout << “10M”; - to print 10 M).

Explanation / Answer

Given below is the code with output. Please rate if it helped. Thank you.

#include <iostream>
#include <iomanip>
#include <cmath>

using namespace std;
void calcReactance(long f, double L, double C, double& XL, double& XC);
void calcCurrent(double R, double XL , double XC, double E, double& Z, double& I);


int main()
{
long f_initial, f_final; //initial and final frequencies
double XL, XC, Z, I, L, R, E, C;
string ans = "y";
cout << fixed;
while(ans == "y" || ans == "Y")
{
do
{
cout << " Enter resistance R in u03A9: "; //unicode for ohm symbol is u0349
cin >> R;
if(R <= 0)
cout << "Resistance should be positive" << endl;
  
}while(R <= 0);
  
do
{
cout << "Enter inductance L in mH: ";
cin >> L;
L /= 1000; //convert from mH to H
if(L <= 0)
cout << "Inductance should be positive" << endl;
}while(L <= 0);
  
do
{
cout << "Enter capacitance C in u00B5" << "F: " ; //unicode for micro symbol is u00B5
cin >> C;
C /= 1000000; //convert from micro Farads to farads
if(C <= 0)
cout << "Capacitance should be positive" << endl;
}while(C <= 0);
  
do
{
cout << "Enter sinusoidal voltage E in V: ";
cin >> E;
if(E <= 0)
cout << "Voltage should be positive" << endl;
}while(E <= 0);
  
do{
cout << "Enter initial frequency in Hz: ";
cin >> f_initial;
if(f_initial <= 1)
cout << "inital frequency should be greater than 1" << endl;
}while(f_initial <= 1);
  
while(true)
{
cout << "Enter final frequency in Hz: ";
cin >> f_final;
if(f_final < 2 * f_initial || f_final >= 1E9)
cout << "final frequency should be greater than 2 times initial and less than 1E9" << endl;
else
break;
}

  
cout << setw(15) << "Freq(Hz)" << setw(15) << "XC(u03A9)" ;
cout << setw(15) << "XL(u03A9)" << setw(15) << "Z(u03A9)";
cout << setw(15) << "I(mA)" << endl;
  
long f = f_initial;
while(true)
{
calcReactance(f, L, C, XL, XC);
calcCurrent(R, XL, XC, E, Z, I);
I *= 1000; //convert from amp to milli amp
  
  
cout << setw(15) << f << setprecision(1) << setw(15) << XC ;
cout << setw(15) << XL << setw(15) << Z << setw(15) << setprecision(3) << I << endl;
if(f > f_final)
break;
else
f *= 2;
}
  
cout << " Do you want to continue? (y/n) : ";
cin >> ans;
}
}

//calculate and output XL, XC. variables XL and XC are passed by reference
void calcReactance(long f, double L, double C, double& XL, double& XC)
{
double PI = 3.14159;
XL = 2 * PI * f * L;
XC = -1 / (2 * PI * f * C);
}

//calculate Z and current I (passed by ref)
void calcCurrent(double R, double XL , double XC, double E, double& Z, double& I)
{
double total = 0;
total += R * R;
total += (XL + XC) * (XL + XC);
Z = sqrt(total);
I = E / Z;
}

output

Enter resistance R in : 5000
Enter inductance L in mH: 20
Enter capacitance C in µF: 0.02
Enter sinusoidal voltage E in V: 15
Enter initial frequency in Hz: 100
Enter final frequency in Hz: 1000000
Freq(Hz) XC() XL() Z() I(mA)
100 -79577.5 12.6 79721.9 0.188
200 -39788.8 25.1 40076.8 0.374
400 -19894.4 50.3 20464.3 0.733
800 -9947.2 100.5 11043.4 1.358
1600 -4973.6 201.1 6912.1 2.170
3200 -2486.8 402.1 5417.2 2.769
6400 -1243.4 804.2 5019.2 2.988
12800 -621.7 1608.5 5096.4 2.943
25600 -310.8 3217.0 5783.2 2.594
51200 -155.4 6434.0 8026.2 1.869
102400 -77.7 12868.0 13732.8 1.092
204800 -38.9 25735.9 26179.0 0.573
409600 -19.4 51471.8 51694.8 0.290
819200 -9.7 102943.6 103055.3 0.146
1638400 -4.9 205887.2 205943.1 0.073

Do you want to continue? (y/n) : n

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote