Hello, i have a question for my C++ program.

void GasPump::setHighGal(int gallons){

    gallons = 0;
}
void GasPump::setMedGal(int gallons){
    gallons = 0;
}
void GasPump::setLow(int gallons){  
    gallons = 0;
}

Those functions will sets the quantity of gas in the indicated tank to parameter value,resets total cash for that type of gas to 0
So is that mean I should initialize gallons to 0? I don't understand what it does. Thanks

Edited 3 Years Ago by mike_2000_17: Fixed formatting

My crystal ball needs new batteries, so I really don't know what you're trying to do, or what your assignment is asking you to do.

Just looking at this bit of code, each of the three functions are setting the same class member "gallons" to 0, regardless of what value the input parameter may hold.

I suspect that is not the behavior you're really trying to accomplish.

Comments
LoL

Well my assignment is basically about write a program which simulates a one-pump gasoline service station.

- Buy a quantity of low grade gasoline, displaying the cost of the gasoline. If the low grade tank is empty, display a message to that effect. If the required quantity of gasoline is not available, dispense what is left, and output a message to that effect.

- Buy a quantity of medium grade gasoline, displaying the cost of the gasoline. If the medium grade tank is empty, display a message to that effect. If the required quantity of gasoline is not available, dispense what is left, and output a message to that effect.

Buy a quantity of high grade gasoline, displaying the cost of the gasoline. If the high grade tank is empty, display a message to that effect. If the required quantity of gasoline is not available, dispense what is left, and output a message to that effect.

I'm not asking to write a code for me, all I'm asking is the function I posted, and I'm not sure if my assignment is clear.

With that added information, I'd first suggest that you should have data members for each grade of gas. That is, in the ground you might have at a given moment 100 gal lowgrade, 250 midgrade, and 3 gal highgrade.

Now, the three functions you gave should have the purpose of modifying their respective gas quantities. So, how about:

void GasPump::setHighGal(int gallons)
{
      highGallons = gallons;
}

and do the same with the other functions.

In use in your program, you will probably get the amount of gas the user wants to buy. Then find out how much gas is in the ground with a getHighGal( ) function. Adjust how much is left, store the remainder with the setHighGal( ).

Does that help?

With that added information, I'd first suggest that you should have data members for each grade of gas. That is, in the ground you might have at a given moment 100 gal lowgrade, 250 midgrade, and 3 gal highgrade.

Now, the three functions you gave should have the purpose of modifying their respective gas quantities. So, how about:

void GasPump::setHighGal(int gallons)
{
      highGallons = gallons;
}

and do the same with the other functions.

In use in your program, you will probably get the amount of gas the user wants to buy. Then find out how much gas is in the ground with a getHighGal( ) function. Adjust how much is left, store the remainder with the setHighGal( ).

Does that help?

I think you meant constructors right? Or something like this

GasPump price1(2.00, 2.25, 2.50);

about that highGallons = gallons;, yeah thats the one I used before I read my homework instructions and I thought is was wrong , lol, so thats why I asking here to make sure I doing it correctly.
:)

Thanks

This article has been dead for over six months. Start a new discussion instead.