0 Replies - 1872 Views - Last Post: 05 May 2012 - 08:58 AM

#1 az.tech   User is offline

  • New D.I.C Head
  • member icon

Reputation: 0
  • View blog
  • Posts: 6
  • Joined: 21-February 09

Electronics - DC Parallel Resistors using a vector

Posted 05 May 2012 - 08:58 AM

Description: Compile & runEnter the supply voltage
Enter the number of resistors in the circuit
Enter values for those resistors
Calculate the equivalent resistance, total current and branch currents
#include<iostream>
#include<vector>

using namespace std;

int main()
{
   // Declare variables & set parameters for calculations
   vector <float> pr;
   int n;
   float resistance, par_Resistance, voltage, current, percent_I;
   cout << "Enter the supply voltage." << endl;
   cin >> voltage;
   cout << "Enter number of parallel resistors in the circuit." << endl;
   cin >> n;
   cout << endl;

   // Create a vector & resize it to enter & store the resistor values
   pr.resize(n);
   for (int i = 0; i < n; i++)
{
    cout << "Enter the value of R" << i + 1 << endl;
    cin >> pr[i];
}
   //Calculate & display the equivelent parallel resistance
   for (int i = 0; i < n; i++)
   {
      resistance = 1/pr[i];
      par_Resistance += resistance;
   }
   resistance = 1/par_Resistance;
   cout << endl;
   cout << "The equivelent parallel resistance is " << resistance << " ohms." << endl;

   //Calculate current through the entire circuit
   current = voltage / resistance;
   cout << "The total current is " << current << " amps." << endl << endl;

   // Calculate the branch currents through each resistor
   for (int i = 0; i < n; i++)
   {
      percent_I = (resistance / pr[i]) * current;
      cout << "Current through R" << i + 1 << " is " << percent_I << " amps." << endl;
   }
}



Is This A Good Question/Topic? 0
  • +

Page 1 of 1