Question

In: Computer Science

in C++ Write a program to compute the current and the power dissipation in an AC...

in C++ Write a program to compute the current and the power dissipation in an AC circuit that has four resistors R1, R2, R3, and R4 in parallel. The voltage source is V. Test your solution with various voltage levels and resistor values. Execute and submit the program and the results in screen captures. Please note that the equivalent resistor is given by 1/Rtotal = 1/R1 + 1/R2 + 1/R3 + 1/R4 and the current I is given by I = V/Rtotal. The Power dissipation is given by P = V x I

B) Repeat the problem above when the resistors are connected in series.

Solutions

Expert Solution

Here i am writing the code in C++.

here for the Rtotal our logic will be like

first we take LCM of all denominator then compute the addtion .

so if we want calculation same like this 1/Rtotal=1/R1+1/R2+1/R3+1/R4 then we have to do fraction addition in program so that we will get numerator and denomintor both the value then we compute our power and current

for fraction addition

step 1

find a common denominator by finding the LCM of the denominators

step 2:

chaange the fractions to have the same denominator and add both of terms

step 3:

reduce the final fraction obtained into its simpler form by dividing both numerator and denominator by there largest common factor;

so these logic i will use for Rtotal calcuation in parallel circuit.

i am pasting my code here

#include<iostream>

#include<math.h>

using namespace std;

int gcd(int a,int b)   // finding GCD of number

{

    if(a==0)

    return b;

    return gcd(b%a,a);

}

void smallest(int &den3, int &n3) findinf lcm of two number

{

    int common_factor=gcd(n3,den3);

    den3=den3/common_factor;

    n3=n3/common_factor;

}

void add_frac(int n1,int den1,int n2, int den2, int &n3, int &den3) //adding two fraction

{

    den3=gcd(den1,den2);

    den3=(den1*den2)/den3;

    n3=(n1)*(den3/den1) +(n2)*(den3/den2);

    smallest(den3,n3);

}

int main()

{

    int choice;

    int r1,r2,r3,r4,n1=1,n2=1,r5,n3,r6,n4,n5,r7,total; // these all variable will use in program

    float req,v,p,i,temp,tem;

    while(1)

    {

        cout<<"Enter your choice:-"<<endl;

        cout<<"1 for Parallel"<<endl;

        cout<<"2 for Series"<<endl;

        cout<<"3 for Quit"<<endl;

        cin>>choice;

        switch(choice)

        {

            case 1:

            cout<<"Enter R1 value ";

            cin>>r1;

            cout<<"Enter R2 value ";

            cin>>r2;

            cout<<"Enter R3 value ";

            cin>>r3;

            cout<<"Enter R4 value ";

            cin>>r4;

            cout<<"Enter Voltage Value ";

            cin>>v;

            add_frac(n1,r1,n2,r2,n3,r5);   // first we add R1 and R2

            add_frac(n1,r3,n2,r4,n4,r6); // then we add R3 and R4

            add_frac(n3,r5,n4,r6,n5,r7); // then we will add summation of R1 or R2 and summation of R3 or R4

            temp=r7; // we will save denominator of Rtoal in temp

            tem=n5; // and numerator in tem then all are simple calculation

            req=temp/tem;

            i=v/req;

            p=v*i;

            cout<<"The current is "<<i<<endl;

            cout<<"The power is "<<p<<endl;

            break;

            case 2:

            cout<<"Enter R1 value ";

            cin>>r1;

            cout<<"Enter R2 value ";

            cin>>r2;

            cout<<"Enter R3 value ";

            cin>>r3;

            cout<<"Enter R4 value ";

            cin>>r4;

            cout<<"Enter Voltage Value ";

            cin>>v;

            total = r1+r2+r3+r4; // in series

            req=total;

            i=v/req;

            p=v*i;

            cout<<"The current is "<<i<<endl;

            cout<<"The power is "<<p<<endl;

            break;

            case 3:

            exit(0);

        }

    }

    return 0;

}


Related Solutions

Program in C++ **********Write a program to compute the number of collisions required in a long...
Program in C++ **********Write a program to compute the number of collisions required in a long random sequence of insertions using linear probing, quadratic probing and double hashing. For simplicity, only integers will be hashed and the hash function h(x) = x % D where D is the size of the table (fixed size of 1001). The simulation should continue until the quadratic hashing fails.*********
Java Programming: Write a program that allows the user to compute the power of a number...
Java Programming: Write a program that allows the user to compute the power of a number or the product of two numbers. Your program should prompt the user for the following information: • Type of operation to perform • Two numbers (the arguments) for the operation to perform The program then outputs the following information: • The result of the mathematical operation selected. Menu to be displayed for the user: MATH TOOL 1. Compute the power of a number 2....
C program help 1. Write a program to compute the Mileage given by a vehicle. Mileage...
C program help 1. Write a program to compute the Mileage given by a vehicle. Mileage = (new_odometer – old_odometer)/(gallons_gas) // illustrating how ‘for’ loop works. 2. How to initialize an array of size 5 using an initializer list and to compute it’s sum How to initialize an array of size 5 with even numbers starting from 2 using ‘for’ loop and to compute it’s sum 3. Program to compute the car insurance premium for a person based on their...
write c++ program that takes the depth ( in kilometer) inside the earth to compute and...
write c++ program that takes the depth ( in kilometer) inside the earth to compute and display the temperature at the depth in degrees celsius and fahrenheit. the relevant formulas are: celsius+ 10 x depth + 20 fahrenheit = 9/5 celsius + 23
*********C++ Program************ Enhance the Account class to compute the interest on the current balance. An account...
*********C++ Program************ Enhance the Account class to compute the interest on the current balance. An account has initial balance of $10,000.00, and 6% percent annual interest is compounded monthly until the investment is double. Write a main function to determine the number of months to double the initial investment. Create function name "double investment" for this project. Create a menu to allow the user to enter the initial investment and the annual interest rate. Please create a header file(bank.h) and...
Write a program In C to compute internet charges according to a rate schedule. The rate...
Write a program In C to compute internet charges according to a rate schedule. The rate schedule is as follows: $0.08 per GB for usage between 0 and 40 GB, inclusive $0.07 per GB for usage between 41 GB and 70 GB, inclusive $0.05 per GB for usage between 71 GB and 110 GB, inclusive $0.04 per GB for usage greater than 110 GB Learning Objectives In this assignment, you will: Use a selection control structure Use a repetition control...
Using C++ Write a program to compute the number of collisions required in a long random...
Using C++ Write a program to compute the number of collisions required in a long random sequence of insertions using linear probing, quadratic probing, and double hashing.
Subject is C++ Write a program to compute internet charges according to a rate schedule. The...
Subject is C++ Write a program to compute internet charges according to a rate schedule. The rate schedule is as follows: $0.08 per GB for usage between 0 and 40 GB, inclusive $0.07 per GB for usage between 41 GB and 70 GB, inclusive $0.05 per GB for usage between 71 GB and 110 GB, inclusive $0.04 per GB for usage greater than 110 GB code must use these four functions, using these names (in addition to main): getData computeCharges...
These questions are about the relationship between AC current power supply and Inductance. Primary Coil (magnetic...
These questions are about the relationship between AC current power supply and Inductance. Primary Coil (magnetic field connected to source) Secondary Coil (magnetic field induced by the primary) 1. How does changing the frequency (length & height) of an AC power supply affect induced current on a secondary coil and why? 2. How does changing the distance between the primary and secondary coil affect induced current on the secondary coil and why? 3. How does reducing the number of loops...
Examples and describe voltage, current, and phase angle. Describe power and resonance in ac circuits. Examples...
Examples and describe voltage, current, and phase angle. Describe power and resonance in ac circuits. Examples in daily life and explain how transformers work. PLEASE DO NOT WRITE IT BY HAND
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT