subject

Write a full class definition for a class named GasTank , and containing the following members: A data member named amount of type double.
A constructor that no parameters. The constructor initializes the data member amount to 0.
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.
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 a boolean value: true if the value of amount is less than 0.1 , and false otherwise.
A function named getGasLevel that accepts no parameters. getGasLevel returns the value of the amount data member.
class GasTank
{
private:
double amount;
public:
GasTank();
void addGas(double);
void useGas(double);
bool isEmpty();
double getGasLevel();
};
GasTank::GasTank(){amount = 0;}
void GasTank::addGas(double a){amount += a;}
void GasTank::useGas(double a){amount -= a; if (amount < 0) amount = 0; }
bool GasTank::isEmpty(){if(amount < .1) return true; else return false;}
double GasTank::getGasLevel() {return amount;}

ansver
Answers: 3

Another question on Computers and Technology

question
Computers and Technology, 21.06.2019 18:20
Write a method replacekey in the minheap class with the following signature: public void replacekey(integer oldkey, integer newkey) the method will replace the first occurrence of oldkey with the newkey, and restore the min-heap property after the change. if the oldkey does not exist in the heap, the method prints an appropriate message and returns without changing the heap. example: suppose our binary heap object (bh) has the following keys: *** 4 6 7 32 19 64 26 99 42 54 28 then the method call: bh.replacekey (oldkey integer(54), newkey integer(2))
Answers: 1
question
Computers and Technology, 22.06.2019 08:10
Alook-up table used to convert pixel values to output values on a monitor. essentially, all pixels with a value of 190 or above are shown as white (i.e. 255), and all values with a value of 63 or less are shown as black (i.e. 0). in between the pixels are scaled so that a pixel with a value p is converted to a pixel of value 2/127 −+3969). if a pixel has a value of 170 originally, what value will be used to display the pixel on the monitor? if a value of 110 is used to display the pixel on the monitor, what was the original value of the pixel?
Answers: 1
question
Computers and Technology, 23.06.2019 07:30
Write a program that inserts the digits of an integer into an array in originalorderfollowed by reverse order. first, promptthe user to enter a positive integer(> 0). determine the number of digits of the integer. create a dynamically allocated integer arrayof a size twice the number of digits.now insert the digits in original order which will occupy half of the array. then, insert the digits in reverse order.finally, output thedigits in thearray.use at least two functions to organize your program.
Answers: 3
question
Computers and Technology, 23.06.2019 09:30
Name the range function that would generate the following list of integers values: 0,1,2,3,4,5.
Answers: 1
You know the right answer?
Write a full class definition for a class named GasTank , and containing the following members: A d...
Questions
question
Mathematics, 13.10.2019 22:30
question
Mathematics, 13.10.2019 22:30
Questions on the website: 13722360