Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Add a menu to the existing code already written to contain the following options Change Input voltage Add a single resistor Delete resistor Edit resistor

Add a menu to the existing code already written to contain the following options

Change Input voltage

Add a single resistor

Delete resistor

Edit resistor

Group add a series of resistors

Display network

Quit program

Each item in the menu will probably end up being a function. A do-while loop and switch/case statement is probably best way to implement a menu.

You need to create at least 4 functions.

Existing code

#include #include #include

using namespace std;

// You must use this structure struct node {

string name; double resistance; double voltage_across; double power_across;

};

// An Example of the type of function you may want to create. It take node name string nodeName() { string node_name; cout << "Enter Node Name: "; cin >> node_name;

return node_name; }

// This function takes voltage from user double getVolt() { double source_voltage; cout << "Enter Voltage: "; cin >> source_voltage; return source_voltage; }

void calcVolt(vector& N, double curr) { unsigned int i; for (i = 0; i < N.size() ; ++i) { N[i].voltage_across = curr * N[i].resistance ; } }

// This function takes resistance from user double getResistance(vector& N) { double resistance , i = 0, sum = 0; while (1) { cout << "Enter Resistance (0 to exit): "; cin >> resistance; if (resistance != 0) { N.push_back(node()); N[i].name = "Node "; N[i].resistance = resistance; sum += resistance; } else return sum;

i++; } }

// This function calculates power void calcPower(vector& N, double curr) { unsigned int i; for (i = 0; i < N.size() ; ++i) { N[i].power_across = curr * curr * N[i].resistance ; } }

// This function calculates current double calcCurrent(double resistance, double voltage) { double current; current = voltage / resistance ; return current; }

// This function displays network void dispNetwork(vector& N) { unsigned int i; for (i = 0; i < N.size() ; ++i) { cout << " Parameters: " <

// int main() {

double user_volt, total_res , total_curr; vector N;

// get voltage across the resistor from user user_volt = getVolt();

// get resistor value from user total_res = getResistance(N);

// Calculate series current for the one-node network total_curr = calcCurrent(total_res, user_volt);

// Calculate the Volt across the resistor calcVolt(N, total_curr);

// Calculate the power across the resistor calcPower(N, total_curr);

// Display Node information cout << " Circuit Parameters:: "; cout << "\tTotal Resistance: " << total_res <<" Ohms" << endl; cout << "\tInput Voltage: " << user_volt <<" Volts" << endl; cout << "\tSeries Current: " << total_curr << " Amp "; cout << "\tTotal Power: "<< total_curr * total_curr * total_res <<" Watts " << endl;

dispNetwork(N);

return 0; }

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

More Books

Students also viewed these Databases questions

Question

Why is it difficult to justify BI applications?

Answered: 1 week ago

Question

Describe how language emerges.

Answered: 1 week ago