Question

For a given electrical circuit, composed from a network ofresistors, arranged in parallel and/or series, write a program to calculate the total resistance of the circuit. To facilitate user to define the network, by giving the network circuit formula in text, a notation is used, whereand 7 operators mean series and parallel layout respectively. Please note that parallel operator has higher precedence than seriesoperator Table below shows a few examples of circuit diagrams and their respective circuit formulas using aforementioned notation No Circuit Formula Circuit Diagram 1 2.0/2.0+3.0/3.0 2.0Ω 3.0m Ti 2.0Ω 2 2.0+2.0/3.0+3.0 2.02 2.02 3.02 T2 3 2.0+3.0/3.0/3.0+2.0 3.0 Ω 2.0Ω 3.02 2.052 3.02 The program interacts with user using only text console. Menu such as below is presented to user at the start of the program. Please implement all functions as advertised by the menu helcome to Total Reaistance Caleulator Prog ram . Enter circuit formula Generate circuit randomly 3.Show circuit formula 4. Calculate total resistance Your choice [1-4 For example, user can enter a circuit using its formula Your choice (1-4]1 ter circuit formula: 2.0/2.0+3.0/3.0 Your choice (1-4] ircuit total resistance is 2.5 ohm KIE1004: Programming l Semester 1, 2018/2019 Or circuit can be generated randomly by computer Your choice [14] 2 circuit is generated Your choice [1-43 rcuit formula is 2.0+2.0/3.0+3.0 Your choice (1-4] 4 Circuit total resistance is 6.2 ohm For random generation of circuit, please make sure the following specifications are met. . Total number of resistors in the circuit is between 3 and 8 The circuit network layout is restricted only to the one which can be expressed by a circuit formula. The total line of codes must be less than or equal to 500 lines, and please adhere to below good programming practices Variables and functions with meaningful names (for example, not using cryptic single letter name Codes are refactored into well-defined functions. Maintain consistent code indentations throughout the program. Comments are used to describe the working of some complex codes. . . .Using C++

0 1
Add a comment Improve this question Transcribed image text
Answer #1


Please let me know if you have any doubts or you want me to modify the answer. And if you find this answer useful then don't forget to rate my answer as thumps up. Thank you! :)

#include <iostream>
#include <string>
#include <sstream>
#include <iomanip>

using namespace std;

double totalResistance(string);
int main()
{
    int choice;
    string formula;

    cout << "*** Welcome to Total Resistance Calculator Program ***" << endl;
    cout << "1. Enter circuit formula." << endl;
    cout << "2. Generate circuit randomly." << endl;
    cout << "3. Show circuit formula." << endl;
    cout << "4. Calculate total resistance." << endl;

    while (choice !=-1)
    {
        cout << "Your choice (1-4) : ";
        cin >> choice;
        switch(choice)
        {
            case 1:
                cout << "Enter circuit formula: ";
                cin >> formula;
                break;
            case 3:
                cout << "Circuit formula is " << formula << endl;
                break;
            case 4:
                cout << "Circuit total resistance is " << totalResistance(formula) << " ohm" << endl ;
                break;
        }
    }
}

double totalResistance (string tempFormula)
{
    double total=0;
    double value[8];
    char valueOperator[8];

    stringstream assignation(tempFormula);

    for(int i=0; i<4; i++)
    {
        assignation >> value[i];
        assignation >> valueOperator[i];
    }
                                                //need to create word counter, and randomize case
    for(int i=0; i<4; i++)
    {
        if(valueOperator[i]== '/')
        {
            total += ((value[i]*value[i+1])/(value[i]+value[i+1]));
            i++;
        }
        else if(valueOperator[i]== '+')
            total += value[i];
        else if(i==3)
            total += value[i];

    }

    return total;
}
演| ResistanceCalculator [~/CLionProjects/ResistanceCalculator]-.../main.cpp E Project ▼ *끗 *ー△CMakeLists.txt. 원.main.cpp 兴▶ lll External Libraries using nanespace std; 8double totalResistance(string); 9int main() 10 int choice string formula; 12 Calculator Program endL:l 15 16 17 18 cout << k WeLcome to Total cout 1. Enter circuit formula. endl; cout << 2. Generate circuit randomly. <endl; cout << 3. Show circuit formula.< endl; cout 4. Calculate total resistance. endl; while (choice!-1) cout << Your choice (1-4): cin > choice; switch(choice) 24 25 26 case 1: 28 29 30 cout Enter circuit formula: cin » formula; break; case 3: main Rune ResistanceCalculatorx /Users/swapnil/CLionProjects/ResistanceCalculator/cmake-build-debug/ResistanceCalculator olo Welcome to Total Resistance Calculator Program ook 1. Enter circuit formula 2. Generate circuit randomly Il 3. Show circuit formula 4. Calculate total resistance Your choice (1-4): Your choice (1-4) Enter circuit formula: Your choice (1-4): Your choice (1-4): Circuit formula is 2.0/2.0+3/3.0 Your choice (1-4): Circuit total resistance is 2.5 ohn Your choice (1-4) Q Event Log Build finished in 2 s 26 ms (2 minutes ago 74 chars 14:78 LF; UTF-8; 4 spaces; Context: ResistanceCalculatorp

Add a comment
Know the answer?
Add Answer to:
Using C++ For a given electrical circuit, composed from a network ofresistors, arranged in parallel and/or...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Using Matlab When several resistors are connected in an electrical circuit in parallel, the current through...

    Using Matlab When several resistors are connected in an electrical circuit in parallel, the current through each of them is given by in=vs/Rnwhere in and Rn are the current through resistor n and its resistance, respectively, and vs is the source voltage. The equivalent resistance, Req, can be determined from the equation 1/Req=1/R1+1/R2+1/R3+.......+1/Rn. The source current is given by is , and the power, Pn, dissipated in each resistor is given by . is=vs/Req, and Pn=vsin. Write a program in...

  • Problem: Design and write a C language program that can be used to calculate Voltage, Current...

    Problem: Design and write a C language program that can be used to calculate Voltage, Current and Total Resistance for a Series or Parallel or a Series Parallel circuit. The program should display the main menu that contains the three types of circuit calculations that are available and then the user will be prompted to select a circuit first. After the circuit has been selected the program should then display another menu (i.e., a submenu) requesting the necessary data for...

  • Design program so that it correctly meets the program specifications given below.   Specifications: Create a menu-driven...

    Design program so that it correctly meets the program specifications given below.   Specifications: Create a menu-driven program that finds and displays areas of 3 different objects. The menu should have the following 4 choices: 1 -- square 2 -- circle 3 -- right triangle 4 -- quit If the user selects choice 1, the program should find the area of a square. If the user selects choice 2, the program should find the area of a circle. If the user...

  • THIS IS FOR C++ PROGRAMMING USING VISUAL STUDIO THE PROGRAM NEEDS TO BE IN C++ PROGRAMMING #inclu...

    THIS IS FOR C++ PROGRAMMING USING VISUAL STUDIO THE PROGRAM NEEDS TO BE IN C++ PROGRAMMING #include "pch.h" #include #include using namespace std; // Function prototype void displayMessage(void); void totalFees(void); double calculateFees(int); double calculateFees(int bags) {    return bags * 30.0; } void displayMessage(void) {    cout << "This program calculates the total amount of checked bag fees." << endl; } void totalFees() {    double bags = 0;    cout << "Enter the amount of checked bags you have." << endl;    cout <<...

  • ELT 103 Final Exam Spring 2019 1. A series-parallel circuit is: a. typically combination of series banks and parallel strings c always a combination of series banks in parallel e. always a combinatio...

    ELT 103 Final Exam Spring 2019 1. A series-parallel circuit is: a. typically combination of series banks and parallel strings c always a combination of series banks in parallel e. always a combination of parallel banks in series. d. usually a combination of series strings and parallel banks. 2. When analyzing resistance in a series-parallel circuit, you start: a. anywhere in the circuit. / b. at the source. c. at the farthest resistor from the source. d. in any parallel...

  • C++ programming For this assignment, write a program that will act as a geometry calculator. The...

    C++ programming For this assignment, write a program that will act as a geometry calculator. The program will be menu-driven and should continue to execute as long as the user wants to continue. Basic Program Logic The program should start by displaying a menu similar to the following: Geometry Calculator 1. Calculate the area of a circle 2. Calculate the area of a triangle 3. Quit Enter your choice(1-3): and get the user's choice as an integer. After the choice...

  • A) Given An AC circuit in the frequency domain has an impedance Z represented by the...

    A) Given An AC circuit in the frequency domain has an impedance Z represented by the vectors E and I 40v 16.87 60 hertz 20° 8.0A B) Determine Step 1: The value of the impedance Z as a complex number in rectangular form. Step 2: The sketch of Z in terms of an equivalent series circuit representation. Step 3: The value of the reactive element of the series equivalent circuit representation Step 4: The value of the admittance Y -...

  • Plz give me correct code and screen shots for this question by using SASM !!!!!!!! Implement...

    Plz give me correct code and screen shots for this question by using SASM !!!!!!!! Implement the following working C++ program in assembler. Submit assembler code and screen shot. #include <iostream> #include <iomanip> using namespace std; // This menu-driven Health Club membership program carries out the // appropriate actions based on the menu choice entered. A do-while loop // allows the program to repeat until the user selects menu choice 4. int main() { // Constants for membership rates const...

  • Using C++ programming Write a program that compares a student’s answers in a 5-question quiz to...

    Using C++ programming Write a program that compares a student’s answers in a 5-question quiz to the teacher’s answer key. The answer key is: {'C', 'D', 'B', 'B', 'A'} You MUST use TWO functions: One for input and the other for comparing/output. The output is simply the # of questions answered correctly. This program will test your ability to handle parallel arrays. Output: Look at the questions and choices on page 999 of your textbook. Enter the UPPERCASE letter of...

  • Please, I need help, I cannot figure out how to scan variables in to the function...

    Please, I need help, I cannot figure out how to scan variables in to the function prototypes! ******This is what the program should look like as it runs but I cannot figure out how to successfully build the code to do such.****** My code: #define _CRT_SECURE_NO_WARNINGS #include <stdio.h> #include <math.h> #include <conio.h> float computeSeriesResistance(float R1, float R2, float R3); float computeParallelResistance(float R1, float R2, float R3); float computeVoltage(int current, float resistance); void getInputR(float R1, float R2, float R3); void getInputCandR(int...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT