Question

Write a program display the following menu: Ohms Law Calculator 1. Calculate Resistance in Ohms 2....

Write a program display the following menu:

Ohms Law Calculator

1. Calculate Resistance in Ohms

2. Calculate Current in Amps

3. Calculate Voltage in volts

4. Quit Enter your choice (1-4)

If the user enters 1, the program should ask for voltage in Volts and the current in Amps. Use the following formula:

R= E/i

Where:

E= voltage in volts

I= current in amps

R= resistance in ohms

If the user enters 2 the program should ask for the voltage in Volts and resistance in Ohms. Use the following formula:

I= E/R

Where

I= Current in Amps

E= Voltage in Volts

R= resistance in Ohms

If the user enters 3 the program should ask for resistance in Ohms and current in Amps. Use the following formula:

E= I*R

where;

I= Current in Amps

E= Voltage in volts

R= Resistance in Ohms

If the user enters 4 the program should end

. Input validation: Display an error message if the user enters a number outside the range of 1 through 4 when selecting an item from the menu and exit program Do not accept negative input values for Resistance. If a negative Resistance input value is entered display an error message and exit the program When calculating resistance, if one of inputs is negative and the other positive an error message should be displayed and then exit the program.

C++ Programming

Homework Answers

Answer #1

Solution :

#include<iostream>
using namespace std;
void resistance() {
   double E, I, R;
   cout << "Enter Voltage in Volts: ";
   cin >> E;
   cout << "Enter Current in Amps: ";
   cin >> I;
   if(E >= 0 & I > 0)
       cout << "Resistance in Ohms: " << E/I << endl;
   else cout << "ERROR! Voltage and Current should be positive" << endl;  
}

void current() {
   double E, I, R;
   cout << "Enter Voltage in Volts: ";
   cin >> E;
   cout << "Enter Resistance in Ohms: ";
   cin >> R;
   if(E >= 0 & R > 0)
       cout << "Current in Amps: " << E/R <<endl;
   else cout << "ERROR! Voltage and Resistance should be positive" << endl;  
}

void voltage() {
   double E, I, R;
   cout << "Enter Resistance in Ohms: ";
   cin >> R;
   cout << "Enter Current in Amps: ";
   cin >> I;
   if(I >= 0 & R >= 0)
       cout << "Voltage in Volts: " << I*R <<endl;
   else cout << "ERROR! Resistance and Current should be positive" << endl;  
}

int main() {  
   double E, I, R;
   int choice;
   while(true)
   {
       cout << "\nOhms Law Calculator" << endl;
       cout << "1. Calculate Resistance in Ohms\n2. Calculate Current in Amps\n3. Calculate Voltage in volts\n4. Quit" << endl;
       cout << "Enter Your Choice(1-4): ";
       cin >> choice;
       if(choice == 1)
           resistance();
       else if(choice == 2)
           current();
       else if(choice == 3)
           voltage();
       else if(choice == 4)
           break;
       else cout << "Wrong choice, Plzzz choose correct option\n" << endl;              
   }
   return 0;
}

Screenshot:

Know the answer?
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
Similar Questions
Write a phython program to display a menu with the following options: (1) add, (2) subtract,...
Write a phython program to display a menu with the following options: (1) add, (2) subtract, (3) multiply, (4) divide (5) mod, and (6) do nothing. If the user enters something else (except 1-6), the program should display an error message. Otherwise, it should ask the user for two numbers, perform the calculation, and display the result.
The resistance R in ohms of a conductor is given by R = E/I when E...
The resistance R in ohms of a conductor is given by R = E/I when E is the potential in volts and I is the current in amperes . Write a script that will: 0. call a function to prompt the user for the potential and the current 0. call a function that will print resistance ; this will call a subfunction to calculate and return the resistance . write the function as well using MATLAB
Create a flowgorithm program to calculate the Area of Circle first then do the Circumference of...
Create a flowgorithm program to calculate the Area of Circle first then do the Circumference of Circle. The user will have the ability to convert Area OR the Circumference. That means we need to add a decision structure to the program. Furthermore, they need to be able to do it as many times as they want. That means we need to add a main loop structure to the program. The user will also have the choice of whether to run...
Write a Python program named lastNameVolumes that finds the volumes of different 3 D objects such...
Write a Python program named lastNameVolumes that finds the volumes of different 3 D objects such as a cube, sphere, cylinder and cone. In this file there should be four methods defined. Write a method named cubeVolFirstName, which accepts the side of a cube in inches as an argument into the function. The method should calculate the volume of a cube in cubic inches and return the volume. The formula for calculating the volume of a cube is given below....
Days of the week Write a program that asks the user for a number in the...
Days of the week Write a program that asks the user for a number in the range of 1 through 7. The program should display the corresponding day of the week, where 1 = Monday, 2 = Tuesday, 3 = Wednesday, 4 = Thursday, 5 = Friday, 6 = Saturday, and 7 = Sunday. The program should display an error message if the user enters a number that is outside of the range of 1 though 7.
Console ================================================================                        Baseball Team Manager MENU OPTIONS 1 – Display
Console ================================================================                        Baseball Team Manager MENU OPTIONS 1 – Display lineup 2 – Add player 3 – Remove player 4 – Move player 5 – Edit player position 6 – Edit player stats 7 - Exit program POSITIONS C, 1B, 2B, 3B, SS, LF, CF, RF, P Team data file could not be found. You can create a new one if you want. ================================================================ Menu option: 2 Name: Mike Position: SS At bats: 0 Hits: 0 Mike was added....
Write a program that asks the user for a number in the range 1 through 12....
Write a program that asks the user for a number in the range 1 through 12. The program should display the corresponding month of the year, where 1 = January, 2 = February, 3 = March, 4 = April, 5 = May, 6 = June, 7 = July, 8 = August, 9 = September, 10 = October, 11 = November, and 12 = December. The program should display an error message if the user enters a number that is outside...
This is a Java program Program Description You work for a local cell phone company and...
This is a Java program Program Description You work for a local cell phone company and have been asked to write a program to calculate the price of a cell phone data plan being purchased by a customer. The program should do the following tasks: Display a menu of the data plans that are available to be purchased. Read in the user’s selection from the menu.  Input Validation: If the user enters an invalid option, the program should display an error...
In this lab we will design a menu-based program. The program will allow users to decide...
In this lab we will design a menu-based program. The program will allow users to decide if they want to convert a binary number to base 10 (decimal) or convert a decimal number to base 2 (binary). It should have four functions menu(), reverse(), base2(), and base10(). Each will be outlined in detail below. A rubric will be included at the bottom of this document. Menu() The goal of menu() is to be the function that orchestrates the flow of...
Selection control structure The if statement The switch statement (optional) Relational operators and logical operators Use...
Selection control structure The if statement The switch statement (optional) Relational operators and logical operators Use of relational and logical operators to check numeric ranges User friendly Use of user friendly user prompt and simple input validation Use of meaningful output labels and format Use of output manipulators Working with string type Use of getline() Project Description There are two main systems for measuring distance, weight and temperature, the Imperial System of Measurement and the Metric System of Measurement. Most...
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT