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 <iostream>
#include <string>
#include <vector>
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<node>& 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<node>& 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<node>& 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<node>& N)
{
unsigned int i;
for (i = 0; i < N.size() ; ++i)
{
cout << "\n\nParameters: " <<N[i].name<<
endl;
cout << "Resistance: " << N[i].resistance << "
Ohms" << endl;
cout << "Voltage: " << N[i].voltage_across << "
volts" << endl;
cout << "Power: " << N[i].power_across << "
Watts" << endl;
}
}
//
int main()
{
double user_volt, total_res , total_curr;
vector<node> 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 << "\n\nCircuit Parameters:: \n";
cout << "\tTotal Resistance: " << total_res <<"
Ohms" << endl;
cout << "\tInput Voltage: " << user_volt <<"
Volts" << endl;
cout << "\tSeries Current: " << total_curr << "
Amp\n";
cout << "\tTotal Power: "<< total_curr * total_curr *
total_res <<" Watts\n" << endl;
dispNetwork(N);
return 0;
}
Please find the answer
if any query first let me know please,
================================================================
#include <iostream>
#include <string>
#include <vector>
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<node>& 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<node>& 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<node>& 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<node>& N)
{
unsigned int i;
for (i = 0; i < N.size() ; ++i)
{
cout << "\n\nParameters: " <<N[i].name<< endl;
cout << "Resistance: " << N[i].resistance << " Ohms" << endl;
cout << "Voltage: " << N[i].voltage_across << " volts" << endl;
cout << "Power: " << N[i].power_across << " Watts" << endl;
}
}
//
int main()
{
double user_volt, total_res , total_curr;
vector<node> 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 << "\n\nCircuit Parameters:: \n";
cout << "\tTotal Resistance: " << total_res <<" Ohms" << endl;
cout << "\tInput Voltage: " << user_volt <<" Volts" << endl;
cout << "\tSeries Current: " << total_curr << " Amp\n";
cout << "\tTotal Power: "<< total_curr * total_curr * total_res <<" Watts\n" << endl;
dispNetwork(N);
// Switch case are use to draw menu
int choice;
bool chooseMenu = true;
while (chooseMenu != false){
cout << "*******************************\n";
cout << " 1 - Change input voltage.\n";
cout << " 2 - Add a single resistor.\n";
cout << " 3 - Edit Resistor.\n";
cout << " 4 - Quit Program.\n";
cout << "*******************************\n";
cout << " Enter your choice : ";
cin >> choice;
switch (choice)
{
// case 1 for change the input voltage
case 1:
cout<<endl;
cout << "You choose change input voltage\n";
// get voltage across the resistor from user
user_volt = getVolt();
// 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);
cout << "\n\nCircuit Parameters:: \n";
cout << "\tTotal Resistance: " << total_res <<" Ohms" << endl;
cout << "\tInput Voltage: " << user_volt <<" Volts" << endl;
cout << "\tSeries Current: " << total_curr << " Amp\n";
cout << "\tTotal Power: "<< total_curr * total_curr * total_res <<" Watts\n" << endl;
break;
// case 2 to add single resistor
case 2:
cout<<endl;
cout << "You choose add single register \n";
// get voltage across the resistor from user
cout << "Enter Single Resistor : ";
double single_res;
cin>>single_res;
cout<<endl;
// Calculate series current for the one-node network
total_curr = calcCurrent(single_res, user_volt);
// Calculate the Volt across the resistor
calcVolt(N, total_curr);
// Calculate the power across the resistor
calcPower(N, total_curr);
cout << "\n\nCircuit Parameters:: \n";
cout << "\tTotal Resistance: " << single_res <<" Ohms" << endl;
cout << "\tInput Voltage: " << user_volt <<" Volts" << endl;
cout << "\tSeries Current: " << total_curr << " Amp\n";
cout << "\tTotal Power: "<< total_curr * total_curr * total_res <<" Watts\n" << endl;
break;
// case 3 for edit resistance value
case 3:
cout<<endl;
cout << "You choose edit resistor \n "<<endl;
// 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);
cout << "\n\nCircuit Parameters:: \n";
cout << "\tTotal Resistance: " << total_res <<" Ohms" << endl;
cout << "\tInput Voltage: " << user_volt <<" Volts" << endl;
cout << "\tSeries Current: " << total_curr << " Amp\n";
cout << "\tTotal Power: "<< total_curr * total_curr * total_res <<" Watts\n" << endl;
break;
// case 4 Quit the program
case 4:
cout << "Quit of Program.\n";
chooseMenu = false;
break;
default:
cout << "Not a Valid Choice. \n";
cout << "Choose again.\n";
cin >> choice;
break;
}
}
return 0;
}
==============================================================
Output


===================================================================================
Please let me know if you have any query
Add a menu to the existing code already written to contain the following options Change Input...
C++ - I have a doubly linked list, but I haven't been able to get the "reverse list" option in the code to work(It's option #in the menu in the program). I received this guidance for testing: Test 4 cases by entering (in this order) c,a,z,k,l,m This tests empty list, head of list, end of list and middle of list. Then delete (in this order) a,z,l. This tests beginning, end and middle deletes. This exhaustively tests for pointer errors. #include...
Complete the code to produce a compiling and working program. Route 66 Kaffeine Kicks is developing an automated ordering service. The system builds their menu and then asks the user for the drink and the size. It outputs a statement providing the users with the cost of their order. Example output: Route 66 Caffeine Kicks latte venti grande $3.21 $3.95 coffee venti grande trenti $2.89 $3.45 $4.29 mocha venti grande $3.45 $4.29 hot chocolate mini venti grande trenti $2.05 $2.89 ...
Hello, I have some errors in my C++ code when I try to debug it.
I tried to follow the requirements stated below:
Code:
// Linked.h
#ifndef INTLINKEDQUEUE
#define INTLINKEDQUEUE
#include <iostream>
usingnamespace std;
class IntLinkedQueue
{
private: struct Node {
int data;
Node *next;
};
Node *front; // -> first item
Node *rear; // -> last item
Node *p; // traversal position
Node *pp ; // previous position
int size; // number of elements in the queue
public:
IntLinkedQueue();...
Hi I got error C2660 : 'valuein' : function does not take 2 parameters in visual studio 2013 this is my code so far #include <cstdlib> #include <list> #include <iostream> using namespace std; struct node { int data; node* next; }; void initialize(node*p); void insert(int data,int n); void remove(int b,int pos); bool empty(node*); void length(); bool valuein(int c); int reportvalue(int value); void ptintlist(); int menu(); int main() { struct node*head=NULL; char commands; int value; ...
Hi there. I tried to submit this before, but the copy/paste didn't copy my vectors correctly. Hello there. I am trying to implement the djikstras shortest path algorithm into my code in C++ with a vector of vectors. However, when I test I get an error "Exception thrown at 0x75FFC762 in graphMain.exe: Microsoft C++ exception: std::out_of_range at memory location 0x009CF26C" for line 115 in graph.cpp. Could you help me debug? I am so close! ----------------------------FILE NAME: pch.h--------------------------------------- // pch.cpp: source...
Hi I've a problem with this code. When I add more than 1 song to the list, it doesn't show the first one, only shows the latest one, when I called the function displaysong, let's say when you add 2 songs ID 1 then ID 2, it shows only ID 1. Can you fix it. Everything else is fine.. #include <iostream> #include<string> using namespace std; //class Song class Song{ private: int songID; string title; string artist; string album; int year; public:...
c++ programming : everything is done, except when you enter ("a" ) in "F" option , it does not work. here is the program. #include <iostream> #include <string> #include <bits/stdc++.h> #include <iomanip> #include <fstream> using namespace std; #define MAX 1000 class Inventory { private: long itemId; string itemName; int numberOfItems; double buyingPrice; double sellingPrice; double storageFees; public: void setItemId(long id) { itemId = id; } long getItemId() { return itemId; } void setItemName(string name) { itemName = name; } string...
The second picture that I attached is the input and output. I
already did the code but I also have to add the partition number
assigned to the job (if the job was allocated). Can you please do
that for me? I copied and pasted my code below.
#include <iostream>
#include <string.h>
#include <stdio.h>
using std::cout;
using std::cin;
using std::endl;
unsigned int memorySize;
// Function prototypes
unsigned int FirstFit(struct Partition *, int, struct Job *,
int);
unsigned int BestFit(struct Partition...
I keep getting errors and i am so confused can someone please help and show the input and output ive tried so many times cant seem to get it.
main.cpp
#include <iostream>
#include <vector>
#include <string>
#include "functions.h"
int main()
{
char option;
vector<movie> movies;
while (true)
{
printMenu();
cin >>
option;
cin.ignore();
switch (option)
{
case 'A':
{
string nm;
int year;
string genre;
cout << "Movie Name: ";
getline(cin, nm);
cout << "Year: ";
cin >> year;
cout << "Genre: ";
cin >> genre;
//call you addMovie() here
addMovie(nm, year, genre, &movies);
cout << "Added " << nm << " to the catalog"
<< endl;
break;
}
case 'R':
{
string mn;
cout << "Movie Name:";
getline(cin, mn);
bool found;
//call you removeMovie() here
found = removeMovie(mn, &movies);
if (found == false)
cout << "Cannot find " << mn << endl;
else
cout << "Removed " << mn << " from catalog"
<< endl;
break;
}
case 'O':
{
string mn;
cout << "Movie Name: ";
getline(cin, mn);
cout << endl;
//call you movieInfo function here
movieInfo(mn, movies);
break;
}
case 'C':
{
cout << "There are " << movies.size() << " movies
in the catalog" << endl;
// Call the printCatalog function here
printCatalog(movies);
break;
}
case 'F':
{
string inputFile;
bool isOpen;
cin >> inputFile;
cout << "Reading catalog info from " << inputFile
<< endl;
//call you readFromFile() in here
isOpen = readFile(inputFile, &movies);
if (isOpen == false)
cout << "File not found" << endl;...
C++ comment code Comment the following code #include <iostream> using namespace std; class Node { public: Node(int val); int value; Node* next; }; Node::Node(int val){ value = val; } class List { public: List(); // Uncomment the line below once you're ready List(List &other); void push_front(int value); bool pop_front(int &value); void push_back(int value); bool pop_back(int &value); int at(int index); void insert_at(int index, int value); void remove_at(int index); int size(); private: // other members you may have used Node* head; Node*...