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
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...
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...
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....
For this assignment, you will be creating a simple “Magic Number” program. When your program starts,...
For this assignment, you will be creating a simple “Magic Number” program. When your program starts, it will present a welcome screen. You will ask the user for their first name and what class they are using the program for (remember that this is a string that has spaces in it), then you will print the following message: NAME, welcome to your Magic Number program. I hope it helps you with your CSCI 1410 class! Note that "NAME" and "CSCI...
Write a program in Java that: 1. will prompt user with a menu that contains options...
Write a program in Java that: 1. will prompt user with a menu that contains options to: a. Add a To-Do Item to a todo list. A To-Do Item contains: i. An arbitrary reference number (4; 44,004; etc.) ii. A text description of the item ("Pick up dry cleaning", etc.) iii. A priority level (1, 2, 3, 4, or 5) b. View an item in the list (based on its reference number) c. Delete an item from the list (based...
Data Encryption (Strings and Bitwise Operators) Write a C program that uses bitwise operators (e.g. bitwise...
Data Encryption (Strings and Bitwise Operators) Write a C program that uses bitwise operators (e.g. bitwise XOR) to encrypt/decrypt a message. The program will prompt the user to select one of the following menu options: 1. Enter and encrypt a message 2. View encrypted message 3. Decrypt and view the message (NOTE: password protected) 4. Exit If the user selects option 1, he/she will be prompted to enter a message (a string up to 50 characters long). The program will...
IN PYTHON Menu: 1. Hotdog. ($2) 2. Salad ($3)  3. Pizza ($2) 4.Burger ($4) 5.Pasta ($7) Write...
IN PYTHON Menu: 1. Hotdog. ($2) 2. Salad ($3)  3. Pizza ($2) 4.Burger ($4) 5.Pasta ($7) Write a menu-driven program for  Food Court. (You need to use functions!) Display the food menu to a user . 5 options Use numbers for the options and for example "6" to exit. Ask the user what he/she wants and how many of it. (Check the user inputs) AND use strip() function to strip your inputs(if needed) Keep asking the user until he/she chooses the exit...
Consider the following parallel circuit. The voltage of the battery is 24 volts. Lamp 1 is...
Consider the following parallel circuit. The voltage of the battery is 24 volts. Lamp 1 is rated at 48 watts, and lamp 2 at 72 watts. a) What is the voltage drop (loss) across lamp 1, in volts? b) What is the voltage drop (loss) across lamp 2, in volts? c) What is the current which flows through lamp 1, in amps? d) What is the current that flows through lamp 2, in amps? e) Find the resistance of lamp...
Written in MASM Assembly Problem Definition: Write a program to calculate Fibonacci numbers. • Display the...
Written in MASM Assembly Problem Definition: Write a program to calculate Fibonacci numbers. • Display the program title and programmer’s name. Then get the user’s name, and greet the user. • Prompt the user to enter the number of Fibonacci terms to be displayed. Advise the user to enter an integer in the range [1 .. 46]. • Get and validate the user input (n). • Calculate and display all of the Fibonacci numbers up to and including the nth...
Python: Simple Banking Application Project Solution: • Input file: The program starts with reading in all...
Python: Simple Banking Application Project Solution: • Input file: The program starts with reading in all user information from a given input file. The input file contains information of a user in following order: username, first name, last name, password, account number and account balance. Information is separated with ‘|’. o username is a unique information, so no two users will have same username. Sample input file: Username eaglebank has password 123456, account number of BB12 and balance of $1000....