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

C++ project PART 1: Resistance [10 points] Let R be a circuit made up of three r

ID: 3567231 • Letter: C

Question

C++ project

PART 1: Resistance [10 points]
Let R be a circuit made up of three resistors, r1, r2, and r3. Write a function in
C++ called calcResistance() that calculates the total resistance of R given the
resistances of r1, r2, and r3 as input arguments. Assume r1, r2 and r3 are
integers.
To answer this problem, you also need to know how the resistors are arranged in
the circuit. The resistors could be arranged in series, in parallel, or in a
combination of the two. Thus, calcResistance() must have a 4th input argument
that can take one of three string values:

Explanation / Answer

#include "stdafx.h"
#include <iostream>
#include<string>

using namespace std;
float calResistance(int r1,int r2,int r3,string str);
float calVoltage(float r,int i);

int main()
{
   int cir[10][4],i,j,n;
   float voltage,resistance;
   char type;
   cout << "Hello World" << endl;
   cout<<"Enter the number of circuits ";
   cin>>n;
   i = 0;
    while(i<n)
    {
        j=0;
        cout<<"Enter the Resistances and the current ";
        cin>>cir[i][j]>>cir[i][j+1]>>cir[i][j+2]>>cir[i][j+3];
        i++;
    }
    i=0;
    while(i<n)
    {
        cout<<"Calculating the Resistance for the "<<i+1<<"row ";
        cout<<"S-series P-parallel C-Combination ";
        j=0;
        cin>>type;       
        if(type == 'S')
        {
            resistance = calResistance(cir[i][j],cir[i][j+1],cir[i][j+2],"series");
            voltage = calVoltage(resistance,cir[i][j+3]);
            cout<<"The Resistance of the Circuit"<<i+1<<"is "<<resistance<<endl;
            cout<<"The voltage of the Circuit"<<i+1<<"is "<<voltage<<endl;
        }
        else if(type=='P')
        {
            resistance = calResistance(cir[i][j],cir[i][j+1],cir[i][j+2],"parallel");
            voltage = calVoltage(resistance,cir[i][j+3]);
             cout<<"The Resistance of the Circuit"<<i+1<<"is "<<resistance<<endl;
            cout<<"The voltage of the Circuit"<<i+1<<"is "<<voltage<<endl;
        }
         else if(type=='C')
         {
            resistance = calResistance(cir[i][j],cir[i][j+1],cir[i][j+2],"combination");
            voltage = calVoltage(resistance,cir[i][j+3]);
             cout<<"The Resistance of the Circuit"<<i+1<<"is "<<resistance<<endl;
            cout<<"The voltage of the Circuit"<<i+1<<"is "<<voltage<<endl;
         }
          else
          cout<<" Sorry Wrong Output";
        i++;
    }
system("pause");
   return 0;
}


float calResistance(int r1,int r2,int r3,string str)
{
    if(str=="series")
    {
        return (r1+r2+r3);
    }
    else if(str=="parallel")
    {
        return 1/((1/r1)+(1/r2)+(1/r3));
    }
    else// if(str=="combination")
    {
        return (r3+r2*r1/(r2+r1));
    }
    return 0.0;
}

float calVoltage(float r,int i)
{
   return (i*r);
}


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