In: Physics
What is the flowchart for this code. Thank You!
#include<iostream>
#include<iomanip>
#include<string>
#include<cmath>
using namespace std;
float series(float r[], int n)
{
float sum = 0;
int i;
for (i = 0; i < n; i++)
sum += r[i];
return sum;
}
float parallel(float r[], int n)
{
float sum = 0;
int i;
for (i = 0; i < n; i++)
sum = sum + (1 / r[i]);
return 1 / sum;
}
int main()
{
int n;
cout << "Enter number of resistors: " <<
endl;
cin >> n;
float res[1000];
cout << "Enter each resistor value: " <<
endl;
int i;
for (i = 0; i < n; i++)
cin >> res[i];
char respar;
cout << "Are resistors in series (s) or parallel
(p): " << endl;
cin >> respar;
if (respar == 's' || respar == 'S')
{
if (series(res, n) < 1000)
{
cout <<
"The total series resistance is: " << series(res, n) <<
" Ohms for " << n << " resistors." << endl;
int i;
for (i = 0; i
< n; i++)
cout << " " << res[i] << "
Ohms" << endl;
}
else if (series(res, n) > 1000
&& series(res, n) < 1000000)
{
cout <<
"The total series resistance is: " << series(res, n) / 1000
<< " kOhms for " << n << " resistors." <<
endl;
int i;
for (i = 0; i
< n; i++)
cout << " " << res[i] << "
Ohms" << endl;
}
else if (series(res, n) >
1000000)
{
cout <<
"The total series resistance is: " << series(res, n) /
1000000 << " MOhms for " << n << " resistors."
<< endl;
int i;
for (i = 0; i
< n; i++)
cout << " " << res[i] << "
Ohms" << endl;
}
}
else if (respar == 'p' || respar == 'P')
{
if (parallel(res, n) <
1000)
{
cout <<
"The total parallel resistance is: " << parallel(res, n)
<< " Ohms for " << n << " resistors." <<
endl;
int i;
for (i = 0; i
< n; i++)
cout << " " << res[i] << "
Ohms" << endl;
}
else if (parallel(res, n) > 1000
&& parallel(res, n) < 1000000)
{
cout <<
"The total parallel resistance is: " << parallel(res, n) /
1000 << " kOhms for " << n << " resistors."
<< endl;
int i;
for (i = 0; i
< n; i++)
cout << " " << res[i] << "
Ohms" << endl;
}
else if (parallel(res, n) >
1000000)
{
cout <<
"The total parallel resistance is: " << parallel(res, n) /
1000000 << " MOhms for " << n << " resistors."
<< endl;
int i;
for (i = 0; i
< n; i++)
cout << " " << res[i] << "
Ohms" << endl;
}
}
int z;
for (z = 0; z < n; z++)
{
if (res[z] == 0 && respar
== 'p' || respar == 'P')
{
cout <<
"Parallel resistance is zero, there is a short circuit." <<
endl;
}
}
return 0;
}
The flowchart for calculating whether resitors are in series or parallel and finding their sum.