#include #include using namespace std; class TotalResistance { double series_res,parallel_res,sp_res; public: TotalResistance() { series_res=parallel_res=sp_res=0; } void seriesResistance(double resistance[],int n); void parallelResistance(double resistance[],int n); void spResistance(double resistance[],int n); }; void TotalResistance::seriesResistance(double resistance[],int n) { for(int i=0;i>n; double resistance_values[n]; cout<<"Enter resistances values: "; for(int i=0;i>resistance_values[i]; TotalResistance robj; robj.seriesResistance(resistance_values,n); robj.parallelResistance(resistance_values,n); robj.spResistance(resistance_values,n); ///////////////////////////////////////////// cout<<"Enter total number of capacitors: "; int c; cin>>c; double capacitance_values[c]; cout<<"Enter capacitance values: "; for(int i=0;i>capacitance_values[i]; TotalCapacitance cobj; cobj.seriesCapacitance(capacitance_values,c); cobj.parallelCapacitance(capacitance_values,c); cobj.spCapacitance(capacitance_values,c); ///////////////////////////////////////////// cout<<"Enter total number of inductors: "; int i; cin>>i; double inductance_values[i]; cout<<"Enter inductance values: "; for(int j=0;j>inductance_values[j]; TotalInductance iobj; iobj.seriesInductance(inductance_values,i); iobj.parallelInductance(inductance_values,i); iobj.spInductance(inductance_values,i); int R,L,C; cout<<"In order to find terminal voltage: enter the values of \n--> Effective Resistance: R\n"; cin>>R; cout<<"-->Enter Effective Capacitance: C or Effective Inductance: L (select 'C' or 'L') \n"; char ch; cin>>ch; int flag=0; if(ch=='c' || ch=='C') { flag=1; cin>>C; } else cin>>L; if(flag==1) cout<<"Time constant is: "<
#include<iostream>
#include<math.h>
using namespace std;
class TotalResistance
{
double series_res,parallel_res,sp_res;
public:
TotalResistance()
{
series_res=parallel_res=sp_res=0;
}
void seriesResistance(double resistance[],int n);
void parallelResistance(double resistance[],int n);
void spResistance(double resistance[],int n);
};
void TotalResistance::seriesResistance(double resistance[],int n)
{
for(int i=0;i<n;i++)
series_res += resistance[i];
cout<<"Total Resistance in series is: "<<series_res<<endl;
}
void TotalResistance::parallelResistance(double resistance[],int n)
{
double temp=0;
for(int i=0;i<n;i++)
temp += (1/resistance[i]);
parallel_res = 1/temp;
cout<<"Total Resistance in parallel is: "<<parallel_res<<endl;
}
void TotalResistance::spResistance(double resistance[],int n)
{
for(int i=0;i<n;i++)
series_res += resistance[i];
double temp=0;
for(int i=0;i<n;i++)
temp += (1/resistance[i]);
parallel_res = 1/temp;
cout<<"Total Resistance in series parallel is: "<<parallel_res+series_res<<endl;
}
///////////////////////////////////////////////////////////////////////////////////////////////////////////////
class TotalCapacitance
{
double series_cap,parallel_cap,sp_cap;
public:
TotalCapacitance()
{
series_cap=parallel_cap=sp_cap=0;
}
void seriesCapacitance(double capacitance[],int c);
void parallelCapacitance(double capacitance[],int c);
void spCapacitance(double capacitance[],int c);
};
void TotalCapacitance::seriesCapacitance(double capacitance[],int c)
{
double temp=0;
for(int i=0;i<c;i++)
temp += (1/capacitance[i]);
parallel_cap = 1/temp;
cout<<"Total Capacitance in series is: "<<parallel_cap<<endl;
}
void TotalCapacitance::parallelCapacitance(double capacitance[],int c)
{
for(int i=0;i<c;i++)
series_cap += capacitance[i];
cout<<"Total Capacitance in parallel is: "<<series_cap<<endl;
}
void TotalCapacitance::spCapacitance(double capacitance[],int c)
{
double temp=0;
for(int i=0;i<c;i++)
temp += (1/capacitance[i]);
parallel_cap = 1/temp;
for(int i=0;i<c;i++)
series_cap += capacitance[i];
cout<<"Total Capacitance in series parallel is: "<<parallel_cap+series_cap<<endl;
}
///////////////////////////////////////////////////////////////////////////////////////////////////////////////
class TotalInductance
{
double series_ind,parallel_ind,sp_ind;
public:
TotalInductance()
{
series_ind=parallel_ind=sp_ind=0;
}
void seriesInductance(double inductance[],int id);
void parallelInductance(double inductance[],int id);
void spInductance(double inductance[],int id);
};
void TotalInductance::seriesInductance(double inductance[],int id)
{
for(int i=0;i<id;i++)
series_ind += inductance[i];
cout<<"Total Inductance in series is: "<<series_ind<<endl;
}
void TotalInductance::parallelInductance(double inductance[],int id)
{
double temp=0;
for(int i=0;i<id;i++)
temp += (1/inductance[i]);
parallel_ind = 1/temp;
cout<<"Total Inductance in parallel is: "<<parallel_ind<<endl;
}
void TotalInductance::spInductance(double inductance[],int id)
{
for(int i=0;i<id;i++)
series_ind += inductance[i];
double temp=0;
for(int i=0;i<id;i++)
temp += (1/inductance[i]);
parallel_ind = 1/temp;
cout<<"Total Resistance in series parallel is: "<<parallel_ind+series_ind<<endl;
}
///////////////////////////////////////////////////////////////////////////////////////////////////////////////
int main()
{
cout<<"Enter total number of resistors: ";
int n;
cin>>n;
double resistance_values[n];
cout<<"Enter resistances values: ";
for(int i=0;i<n;i++)
cin>>resistance_values[i];
TotalResistance robj;
robj.seriesResistance(resistance_values,n);
robj.parallelResistance(resistance_values,n);
robj.spResistance(resistance_values,n);
/////////////////////////////////////////////
cout<<"Enter total number of capacitors: ";
int c;
cin>>c;
double capacitance_values[c];
cout<<"Enter capacitance values: ";
for(int i=0;i<c;i++)
cin>>capacitance_values[i];
TotalCapacitance cobj;
cobj.seriesCapacitance(capacitance_values,c);
cobj.parallelCapacitance(capacitance_values,c);
cobj.spCapacitance(capacitance_values,c);
/////////////////////////////////////////////
cout<<"Enter total number of inductors: ";
int i;
cin>>i;
double inductance_values[i];
cout<<"Enter inductance values: ";
for(int j=0;j<i;j++)
cin>>inductance_values[j];
TotalInductance iobj;
iobj.seriesInductance(inductance_values,i);
iobj.parallelInductance(inductance_values,i);
iobj.spInductance(inductance_values,i);
int R,L,C;
cout<<"In order to find terminal voltage: enter the values of \n--> Effective Resistance: R\n";
cin>>R;
cout<<"-->Enter Effective Capacitance: C or Effective Inductance: L (select 'C' or 'L') \n";
char ch;
cin>>ch;
int flag=0;
if(ch=='c' || ch=='C')
{
flag=1;
cin>>C;
}
else
cin>>L;
if(flag==1)
cout<<"Time constant is: "<<R*C<<endl;
else
cout<<"Time constant is: "<<(L/R)<<endl;
return 0;
}
Question
provide comments for each line of code above.
Step by step
Solved in 2 steps