Вы находитесь на странице: 1из 5

#include<iostream>

#include<cstdlib>

#include<conio.h>

using namespace std;

// variables to be used in program

double result, valueA, valueB, valA, valB;

int choice;

char cont;

//functions to perform the calculations

double mult(double valueA, double valueB){

result = valueA * valueB;

return result;

double div(double valueA, double valueB)

result = valueA / valueB;

return result;

//functions that promt the user to enter the values to be calculated

double getValueA(string unit){

cout<<"Enter "<<unit<<": "<<endl;

cin>> valA;

cout<<endl;

return valA;
}

double getValueB(string unit){

cout<<"Enter "<<unit<<": "<<endl;

cin>>valB;

cout<<endl;

return valB;

void title(){

cout<<"****** Ohms Law Values Calculator ******"<<endl;

cout<<"* for *"<<endl;

cout<<" Physics (phy109) project 2019"<<endl;

cout<<endl<<endl<<endl;

void showMenu(){

cout<< " Main Menu: "<<endl;

cout<<endl;

cout<< " Ohm's law"<<endl;

cout<< " 1. Voltage "<<endl;

cout<< " 2. Ressistance "<<endl;

cout<< " 3. Current "<<endl;

cout<< " Power Law "<<endl;

cout<< " 4. Watt "<<endl;

cout<< " 5. Voltage "<<endl;

cout<< " 6. Current "<<endl;

cout<<endl;

cout<<" 0. Exit the program. "<<endl;


}

//shows result of calculation

void displayResult(string units) {

cout<<result<<" "<<units;

cout<<endl<<endl;

//Takes the user choice and calls functions accordingly

void processMenu(){

cin>>choice;

switch(choice){

case 0:

exit(0);

case 1:

getValueA("Current");

getValueB("Ressitance");

mult(valA, valB);

displayResult("Volts");

break;

case 2:

getValueA("Volts");

getValueB("Current");

div(valA, valB);

displayResult("Ohms");

break;

case 3:

getValueA("Volts");

getValueB("Ressistance");

div(valA, valB);

displayResult("Amps");
break;

case 4:

getValueA("Volts");

getValueB("Current");

mult(valA, valB);

displayResult("Watts");

break;

case 5:

getValueA("Watts");

getValueB("Current");

div(valA, valB);

displayResult("Volts");

break;

case 6:

getValueA("Watts");

getValueB("Volts");

div(valA, valB);

displayResult("Amps");

break;

default:

cout<< "Invalid choice. ";

int main()

title();

do{

showMenu();

processMenu();
cout <<" Perform another calculation? (y or n)"<<endl;

cin>>cont;

while(cont != 'n');

cout<<"Press any key to Exit"<<endl;

_getch();

return 0;

Вам также может понравиться