You want to help your friend who is taking Electric Circuit I by writing a compu
ID: 2314569 • Letter: Y
Question
You want to help your friend who is taking Electric Circuit I by writing a computer program in C+ + language. Write a program to meet the following specifications: Your program should compute sum of any number of resistor the user enters, for example if the user enter number of resistors as 4 then the total resistance is Rt = R1 + R2 +R3 + R4 If the user enters the voltage applied to these resistors then your program should compute current 1= E/Rt If the user enters I (current in amps only) then your program should compute voltage Finally compute the power P using the formula P=E*IExplanation / Answer
#include <iostream>
using namespace std;
int main()
{
int t,Rt=0,r=0,I,E,P=0;
char o;
cout << "Enter the number of resistances present in the circuit" << endl;
cin >> t;
for (int i = 1; i <= t; ++i)
{
cout << "Enter the Resistance value" << endl;
cin >> r;
Rt += r;
}
cout << "Total Resistance Rt = " << Rt;
switch(o)
{
case 'a':
cout << "Enter Current value in amperes: ";
cin >> I;
P=I*I*Rt;
cout << "Power" << P;
break;
case 'b':
cout << "Enter Voltage value in volts: ";
cin >> V;
P=(V*V)/Rt;
cout << "Power" << P;
break;
default:
/* If operator is other than a or b, error message is shown */
cout << "Error! operator is not correct";
break;
}
return 0;
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.