Hi, This C++ program should be typed in CLR Console Application in visual studio
ID: 3682381 • Letter: H
Question
Hi,
This C++ program should be typed in CLR Console Application in visual studio.
Instruction:
You will develop a solution in the form of a computer program to solve a simple circuit with a single voltage source and resistors in different combination of parallel and series. Your program will give the user the option to test/demonstrate the characteristics of the elements in the circuit and present the results in a tabular format. Your program should be able to solve both configurations of the circuit when the user is presented with a choice over which one. Additional bonus points will be given for programs that give users to option to choose other configurations different than the two provided. The program shouls runs in a loop and continuously present the user with the option to start over.
Comment heavily.
Ohms Law: V = I*R where V is voltage, I is current and R is resistance of resistor. Power: P = I * I * R = V * I where P is the power dissipated by the resistor. Resistors: Reff = R1 + R2 + R3 … (series) 1/Reff = (1/R1) + (1/R2) + (1/R3) … (Parallel)
The program should allow the user to not only choose from configuration 1 or 2 but allows the user to enter the number of resistor greater or equal to 6 in increment of 2,
Configuration 1 Configuration 2 Bonus Point: R1 Choose number of Resis. R2 Minimum 6! R3 --Explanation / Answer
#include <iostream>
using namespace std;
void test();
void demonstrate(); // function declarations
int main() // main function starts here
{
char choose;
cout << "Enter T to test D to Demonstrate "; //option to choose
cin>>choose;
if(choose=='T')
test(); // calling test function
else if(choose=='D')
demonstrate(); // calling demonstrate function
return 0;
}
void test() // function implementation
{
float r[8];float v,i,i1,i2,i3,i4,r1,r2,r7,r8,res,res1,res2,res3,res4;
float p1,p2,p3,p4,p; // declaring required values
char ch;
while(ch!='D') // allowing user to choose options/ configurations
{
cout<< " Enter A for configuration1";
cout<<" Enter B for configuration2 ";
cout<<" Enter C for My configuration";
cout<<" Enter D to exit the program";
cin>>ch;
switch(ch)
{
case 'A': // when user hits a enters into first configuration
cout<<"Enter the value of v: ";
cin>>v;
cout<<"Enter the resitances in order r1,r2,r3,r4,r5,r6,r9,r10";
for(int j=0;j<8;j++)
cin>>r[j];
res1=1/(1/r[2]+1/r[3]); // calculation of i at each resistors
i1=v/res1;
p1=v*i1; // calculation of p at each level
res2=1/(1/r[4]+1/r[5]);
i2=v/res2;
p2=v*i2;
res3=1/(1/r[6]+1/r[7]);
i3=v/res3;
res=res2+res3+res1+r[0]+r[1]; // rinal resulting resistance
i=v/res;
p=v*i; // final power calculation
cout<<"Resistors: r1 r2 r3 r4 r5 r6 r9 r10 "; // printing the data in tabular form
for(int k=0;k<8;k++)
{
if(k==0)
cout<<" ";
cout<<" "<<r[k];
}
cout<<" Current I:"<<i<<" "<<i<<" "<<i1<<" "<<i1<<" "<<i2<<" "<<i2<<" "<<i3<<" "<<i3;
cout<<" power p:"<<p<<" "<<p<<" "<<p1<<" "<<p1<<" "<<p2<<" "<<p2<<" "<<p3<<" "<<p3;
break;
case 'B':
cout<<"Enter the value of v: "; // other case for configuration 2
cin>>v;
cout<<"Enter the two resistors r1 and r2";
cin>>r7;
cin>>r8;
res=1/((1/r7)+(1/r8));
i=v/res;
p=v*i;
cout<<"Resistors: "<<r7<<" "<<r8;
cout<<"Current I:"<<i<<" "<<i;
cout<<"Power p: "<<p<<" "<<p;break;
case 'C': cout<<"Enter the value of i :"; // other case for user defined configuration myconfiguration
cin>>i;
cout<<"Enter the two resistance include r1 and r2 ";
cin>>r1;
cin>>r2;
res=r1+r2;
i=v/res;
p=v*i;
cout<<"Resistors: "<<r1<<" "<<r2;
cout<<"current I: "<<i<<" "<<i;
cout<<"power p: "<<p<<" "<<p;
break;
case 'D': cout<<"Thank you"; break; //to exit from the program
}
}
}
void demonstrate() // function to demonstrate the program
{
float voltage,power,current,resistance;
cout<<"Demonstration of the program is here: ";
cout<<"There are three configorations you have to choose ur configaration "; // user instructions
cout<<"When you are aked to enter the volatage Enter the volatage and press enter ";
cout<<"Then you will be asked to enter resistance to find I";
cout<<"for Example enter the voltage now";
cin>>voltage; // an example calculation
cout<<"now enter the resistance";
cin>>resistance;
current=voltage/resistance;
power=current*voltage;
cout<<"Resistor:"<<resistance;
cout<<" current i:"<<current; // displyaing an example one
cout<<" power p:"<<power;
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.