This program will be used to calculate the voltage and the current. It needs to have an interactive menu where the user can freely choose.
i am thinking the output to be something like this:
Please choose from following options:
1 - Set Resistance
2 - Change Voltage
3 - Change Current
4 - Exit
1
Please input new resistance value: 5
Resistance is now 5(Ohm).
Please choose from following options:
1 - Set Resistance
2 - Change Voltage
3 - Change Current
4 - Exit
2
Please input new voltage value: 20
************************************
Resistance is now 5(Ohm).
Voltage is now 20(V).
Current is now 4(A).
************************************
Please choose from following options:
1 - Set Resistance
2 - Change Voltage
3 - Change Current
4 - Exit
3
Please input new current value: 17
************************************
Resistance is now 5(Ohm).
Voltage is now 85(V).
Current is now 17(A).
************************************
Please choose from following options:
1 - Set Resistance
2 - Change Voltage
3 - Change Current
4 - Exit
4
It has to be done using OOP but i'm not that familiar with that.
So I have declared the class and designated public and private control access, and set up the class functions. But on my main part of the program I am having problems allowing the user to insert the voltage value.
Help me please, my head is frying right now :D
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49
|
//this program will have a interactive menu to set and change current, resistor resistance and voltage
#include<iostream>
#include<string.h>
using namespace std;
class Resistor{
private:
double resist_value;
double voltage_value;
double current_value;
char resistor_unit;
char voltage_unit;
char current_unit;
public:
double setResist_value();
void setVoltage_value(double);
void setCurrent_value(double);
double getResist_value() const;
double getVoltage_value() const;
double getCurrent_value() const;
Resistor(); //resistor default constructor
Resistor(double resistValue); // Overloaded constructor
~Resistor();
//Setting up resistor values
Resistor::Resistor() {resist_value = 20.0;} //Setting up resistor default constructor value to 20 OHMs
Resistor::Resistor(double resistValue) { resistValue = resist_value; } //Allowing resistor to have a custom value by overloading the constructor
//Setting up Resistor functions
double Resistor::getResist_value() { voltage_value / current_value;}
double Resistor::getVoltage_value() { current_value * resist_value;}
double Resistor::getCurrent_value() { voltage_value / resist_value;}
double Resistor::setResist_value();
double Resistor::setVoltage_value();
double Resistor::setCurrent_value();
int main()
{
int option; // the user option is going to be stored in this variable
do // do-while loop start. The loop will continue until the user press the "EXIT" option
{
// menu display start
cout << "1- Set Resistance value: " << endl;
cin >> setResist_value;
cout << "2- Change Voltage value: " << endl;
cout << "3- Change Current value: " << endl;
cout << "4- Exit " << endl;
|