|
-
March 9th, 2012, 03:50 PM
#1
You don't seem to be initializing the amount data member properly.
I need help I cant find why amount is not initializing properly, here is the problem:
Write the implementation (.cpp file) of the GasTank class of the previous exercise. The full specification of the class is:
A data member named amount of type double.
An data member named capacity of type double.
A constructor that accepts a parameter of type double. The value of the parameter is used to initialize the value of capacity .
A function named addGas that accepts a parameter of type double . The value of the amount instance variable is increased by the value of the parameter. However, if the value of amount is increased beyond the value of capacity , amount is set to capacity .
A function named useGas that accepts a parameter of type double . The value of the amount data member is decreased by the value of the parameter. However, if the value of amount is decreased below 0 , amount is set to 0 .
A function named isEmpty that accepts no parameters and returns a boolean value. isEmpty returns true if the value of amount is less than 0.1 , and false otherwise.
A function named isFull that accepts no parameters and returns a boolean value.. isFull returns true if the value of amount is greater than capacity-0.1 , and false otherwise.
A function named getGasLevel that accepts no parameters. getGasLevel returns the value of the amount data member.
here is my code....idk what im doing wrong i followed every direction:
GasTank::GasTank(double a)
{
capacity = a;
}
void GasTank::addGas(double a)
{
amount += a;
if(amount > capacity)
{
amount = capacity;
}
}
void GasTank::useGas(double a)
{
amount -= a;
if(amount < 0)
{
amount = 0;
}
}
bool GasTank::isEmpty()
{
if(amount < 0.1)
{
return true;
}
else
{
return false;
}
}
bool GasTank::isFull()
{
if(amount > (capacity-0.1))
{
return true;
}
else
{
return false;
}
}
double GasTank::getGasLevel()
{
return amount;
}
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|