Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Write the implementation (.cpp file) of the GasTank class of the previous exerci

ID: 3916590 • Letter: W

Question

Write the implementation (.cpp file) of the GasTank class of the previous exercise. The full specification of the class is:

I'm having trouble with my code, my error is saying "I haven't yet seen a correct solution that uses: class "

Here's my code:

class GasTank
{

double amount;
double capacity;


GasTank::GasTank(double theAmount)
{
capacity=theAmount;
}

void GasTank::addGas(double amountToAdd)
{
amount+=amountToAdd;
if (amount>capacity)
amount=capacity;
}

void GasTank::useGas(double amountToUse)
{
amount-=amountToUse;
if (amount<0)
amount=0;
}

bool GasTank::isEmpty()
{
return (amount<0.1) ? 1 : 0;
}

bool GasTank::isFull()
{
if (amount>(capacity-0.1))
return 1;
else
return 0;
}

double GasTank::getGasLevel()
{
return amount;
}

double GasTank::fillUp()
{
double difference=capacity-amount;
amount=capacity;
return difference;
}
}

Explanation / Answer

Mistake: Inside the code don't use class reference "GasTank::"

Please find below modified code:

class GasTank

{

                double amount;

                double capacity;

               

                GasTank(double theAmount)

                {

                                capacity=theAmount;

                                amount = 0;

                }

               

                void addGas(double amountToAdd)

                {

                                amount+=amountToAdd;

                                if (amount>capacity)

                                                amount=capacity;

                }

               

                void useGas(double amountToUse)

                {

                                amount-=amountToUse;

                                if (amount<0)

                                                amount=0;

                }

               

                bool isEmpty()

                {

                                return (amount<0.1) ? 1 : 0;

                }

               

                bool isFull()

                {

                                if (amount>(capacity-0.1))

                                                return 1;

                                else

                                                return 0;

                }

               

                double getGasLevel()

                {

                                return amount;

                }

               

                double fillUp()

                {

                                double difference=capacity-amount;

                                amount=capacity;

                                return difference;

                }

};