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

Write a C++ program to do the following: The “main” section of the program will

ID: 3808712 • Letter: W

Question

Write a C++ program to do the following:

The “main” section of the program will ask the user for the value of four resistors in your series circuit and the total voltage (V) applied to the series circuit.

In the “main” section it must call a function that will calculate the total series resistance and return the total resistance value to the “main” section.

In the “main” call a function that will calculate the voltage across each resistor.

In the “main” call a function that will calculate the power dissipated in each resistor.

In the “main” call a function that will display an output that looks like

For the series circuit :

R1 = #####   R2=####     R3=####        R4=####       Rtotal=######

IR1= #####    IR2=####    IR3=####     IR4=####      Itotal=######

VR1=#####     VR2=####   VR3=####     VR4=####    Vtotal=#####

PR1=#####    PR2=####   PR3=####      PR4=####     Ptotal=#####

Note: all resistor values have no decimal values and are 1000 ohms or more and all output values should only have 3 decimal places.

Explanation / Answer

Please refer below code

#include<iostream>
#include<iomanip>

using namespace std;
//total resistance in series is sum of all resistance
int total_resistance(int R1,int R2, int R3, int R4)
{
return(R1+R2+R3+R4);
}
//voltage across each resistor is different and used voltage divider rule
double voltage_resistor(double V, int R, int Rtotal)
{
return (R * V)/Rtotal;
}
//power dissipation = V^2 / R
double power_dissipated(double V,int R)
{
return (V * V)/R;
}
void print_values(int R1, int R2, int R3, int R4, double IR, double VR1, double VR2, double VR3, double VR4, double PR1,
double PR2, double PR3, double PR4)
{
cout<<" R1 = "<<R1<<" R2 = "<<R2<<" R3 = "<<R3<<" R4 = "<<R4<<endl;
cout<<fixed;
cout<<setprecision(3); //precison for 3 digits after decimal point
cout<<" IR1 = "<<IR<<" IR2 = "<<IR<<" IR3 = "<<IR<<" IR4 = "<<IR<<endl;
cout<<" VR1 = "<<VR1<<" VR2 = "<<VR2<<" VR3 = "<<VR3<<" VR4 = "<<VR4<<endl;
cout<<" PR1 = "<<PR1<<" PR2 = "<<PR2<<" PR3 = "<<PR3<<" PR4 = "<<PR4<<endl;
}
int main()
{
int R1,R2,R3,R4,Rtotal;
double IR,V;
double VR1,VR2,VR3,VR4;
double PR1,PR2,PR3,PR4;

cout<<"Please Enter R1,R2,R3 and R4 :";
cin>>R1>>R2>>R3>>R4;

cout<<" Please enter total voltage applied :";
cin>>V;

Rtotal = total_resistance(R1,R2,R3,R4);
IR = V/Rtotal; //total currecnt is flowing same across each resistor in series connection
VR1 = voltage_resistor(V,R1,Rtotal);
VR2 = voltage_resistor(V,R2,Rtotal);
VR3 = voltage_resistor(V,R3,Rtotal);
VR4 = voltage_resistor(V,R4,Rtotal);

PR1 = power_dissipated(VR1,R1);
PR2 = power_dissipated(VR2,R2);
PR3 = power_dissipated(VR3,R3);
PR4 = power_dissipated(VR4,R4);

print_values(R1,R2,R3,R4,IR,VR1,VR2,VR3,VR4,PR1,PR2,PR3,PR4);

return 0;
}

Please refer below output

Please Enter R1,R2,R3 and R4 :1000 1100 1200 2000


Please enter total voltage applied :230


R1 = 1000 R2 = 1100 R3 = 1200 R4 = 2000

IR1 = 0.043 IR2 = 0.043 IR3 = 0.043 IR4 = 0.043

VR1 = 43.396 VR2 = 47.736 VR3 = 52.075 VR4 = 86.792

PR1 = 1.883 PR2 = 2.072 PR3 = 2.260 PR4 = 3.766

Process returned 0 (0x0) execution time : 18.048 s
Press any key to continue.

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