Question
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
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
// This function takes resistance from user double getResistance(vector
i++; } }
// This function calculates power void calcPower(vector
// This function calculates current double calcCurrent(double resistance, double voltage) { double current; current = voltage / resistance ; return current; }
// This function displays network void dispNetwork(vector // int main() { double user_volt, total_res , total_curr; vector // 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
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started