I need help with this C++ problem. Here is my code: class GasTank { private: dou
ID: 3916342 • Letter: I
Question
I need help with this C++ problem. Here is my code:
class GasTank
{
private:
double amount;
public:
GasTank()
{
amount=0;
}
void addGas(double);
void useGas(double);
bool isEmpty();
double getGasLevel();
};
void GasTank::addGas(double i)
{
amount += i;
}
void GasTank::useGas(double j)
{
amount -= j;
}
bool GasTank::isEmpty(){
if(amount < 0.1){
return true;
}
else{
return false;
}
}
double GasTank::getGasLevel()
{
return amount;
}
My errors are:
Problems Detected:
? The value of e is incorrect.
? The value of result is incorrect.
arg
sequence of addGas(a)?
e
result#1
{1, 1, 0, 0, 0, 0, 0, 0, 0, 0} ? {1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0} {0, -1, 0, 0, 0, 0, 0, 0, 0, 0, 0} The value of e is incorrect.The value of result is incorrect. #2
{4.7, 1.1, 1.3, 2.3, 0, 0, 0, 0, 0, 0} ? {1, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0} {0, 4.7, 3.6, 2.3, 0, 0, 0, 0, 0, 0, 0} #3 {1, 1.2, 0, 0, 0, 0, 0, 0, 0, 0} ? {1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0} {0, 1, -0.2, 0, 0, 0, 0, 0, 0, 0, 0}
Explanation / Answer
I have created this class please check it..Otherwise please upload complete problem statment.Mention the issue on comment box.
=========================================================
//class defintion of GasTank
class GasTank
{
//private amount
double amount;
public:
//constructor
GasTank()
{
amount = 0.0;
}
//addGas memeber function
void addGas(double AG)
{
amount = amount + AG;
}
//useGas member function
void useGas(double UG)
{
amount = amount -UG;
//if amount is less than zero then set amount to 0.0
if(amount < 0)
{
amount = 0.0;
}
//member function isEmpty
bool isEmpty()
{
if(amount < 0.1)
{
return true;
}
else
{
return false;
}
//getGasLevel memebr function
double getGasLevel()
{
return amount;
}
};
//end of the class defintion
========================================================