Programming Assignment # AC CIRCUIT ANALYSIS It is useful so be able so generate
ID: 3866499 • Letter: P
Question
Programming Assignment # AC CIRCUIT ANALYSIS It is useful so be able so generate tables of information involving repeated calculations in engineering. One cxample of this is wore the current is to be calculatod (as a function of frequency) for a series RLC electrical ciecuit Backgroun Shown on page 3 is a "series RLC cincuit, consisting of a sinusoidal voltage source, a resistor, an indactor, and a capacitor. The current in this circuit changes as the frequency of the sinusoidal voltage changes R- Resistance in Olms () L-Inductance in Henries (H) C-Capacitance in Farads (F) 1 -Current in Amperes (A) E Sinusoidall volage in Volts (V), at soene Erequency,f Froquency in Hertz (Ha) The current, 1, can be calculated in the circuit using the following relationshis: x.-inactive reactance-2.-f-Lin obm (3) x-capacitive reactance-2indrmin, Z-total circuit impodance R(XL Xe in(a) curtin Amperes (A) · The user should be prompted so input the values fr E, R·L,C,G The value for R shouild be entered in oms (for example, the user enters 5000.) . The value of E should be entered in volls The value of C should be entered in mF, uF or nF (then convert it to F). For example, the user eners 10 mF . The value of L should be entered in mH or uH (then convert it o H * The value of fan and f should be entered in Hz, kHz, or MI lz (den converte to H2). Create a table containing values off, XL XC, Z, and I for a range of values of * Use a loop vary f from 4-so the first value of f greater than or equal to low where fdoubles each ime through the loop. For example, if f 100 and fl-E, tho -100, 200,400 800, 1638400 (his spacing is common as graphs oen place frequency on a log scalk). During each pass though the loop call separate functions to calculate XL. XC, and Z. Use at lcant two additional user-defined functions The resultsshould be displayod in a meat, ormatied table with headings, units ctc The valae of the current, 1, 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 estra credit . XL, XC, and z Your loop should also determine the maximum value of the current in the table and the corresponding eeqaencyExplanation / Answer
The code below answers the question. I could not get the ohm symbol printed using ê as indicated in question. I got the unicode value of ohm from google and used that instead. The output is shown below. Please don't forget to rate the answer if it helped. Thank you.
#include <iostream>
#include <iomanip>
#include <cmath>
using namespace std;
void calculateReactance(long f, double L, double C, double& XL, double& XC);
void calculateCurrent(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(12) << "Freq(Hz)" << setw(12) << "XC(u03A9)" ;
cout << setw(13) << "XL(u03A9)" << setw(13) << "Z(u03A9)";
cout << setw(12) << "I(mA)" << endl;
 Â
long f = f_initial;
while(true)
{
cout << "------------------------------------------------------------------------" << endl;
 Â
calculateReactance(f, L, C, XL, XC);
calculateCurrent(R, XL, XC, E, Z, I);
I *= 1000; //convert from Ampere to milli ampere
 Â
 Â
cout << setw(12) << f << setprecision(1) << setw(12) << XC ;
cout << setw(12) << XL << setw(12) << Z << setw(12) << setprecision(3) << I << endl;
if(f > f_final)
break;
else
f *= 2;
}
 Â
cout << " Perform another calculation ? (y/n) : ";
cin >> ans;
}
}
//calculate and output XL, XC. variables XL and XC are passed by reference
void calculateReactance(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 calculateCurrent(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
Perform another calculation ? (y/n) : y
Enter resistance R in : 1000
Enter inductance L in mH: 6.33
Enter capacitance C in µF: 1.0
Enter sinusoidal voltage E in V: 48
Enter initial frequency in Hz: 50
Enter final frequency in Hz: 1000000
Freq(Hz) XC() XL() Z() I(mA)
------------------------------------------------------------------------
50 -3183.1 2.0 3334.6 14.395
------------------------------------------------------------------------
100 -1591.6 4.0 1876.3 25.583
------------------------------------------------------------------------
200 -795.8 8.0 1273.1 37.705
------------------------------------------------------------------------
400 -397.9 15.9 1070.5 44.840
------------------------------------------------------------------------
800 -198.9 31.8 1013.9 47.343
------------------------------------------------------------------------
1600 -99.5 63.6 1000.6 47.969
------------------------------------------------------------------------
3200 -49.7 127.3 1003.0 47.856
------------------------------------------------------------------------
6400 -24.9 254.5 1026.0 46.782
------------------------------------------------------------------------
12800 -12.4 509.1 1116.5 42.990
------------------------------------------------------------------------
25600 -6.2 1018.2 1422.7 33.739
------------------------------------------------------------------------
51200 -3.1 2036.4 2265.9 21.184
------------------------------------------------------------------------
102400 -1.6 4072.7 4192.2 11.450
------------------------------------------------------------------------
204800 -0.8 8145.4 8205.8 5.850
------------------------------------------------------------------------
409600 -0.4 16290.8 16321.1 2.941
------------------------------------------------------------------------
819200 -0.2 32581.7 32596.8 1.473
------------------------------------------------------------------------
1638400 -0.1 65163.3 65170.9 0.737
Perform another calculation ? (y/n) : n
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.