For this assignment you will design a set of classes that work together to simulate a car's fuel gauge and
odometer. The classes you will design are:
· The FuelGauge Class: This class will simulate a fuel gauge. Its responsibilities are
- To know the car's current amount of fuel, in gallons.
3- To report the car's current amount of fuel, in gallons.
- To be able to increment the amount of fuel by 1 gallon. This simulates putting fuel in the car.
(The car can hold a maximum of 15 gallons.)
- To be able to decrement the amount of fuel by 1 gallon, if the amount of fuel is greater than
0 gallons. This simulates burning fuel as the car runs.
· The Odometer Class: This class will simulate the car's odometer. Its responsibilities are:
- To know the car's current milage.
- To report the car's current milage.
- To be able increment the current mileage by 1 mile. The maximum mileage the odometer
can be store is 999, 999 miles. When this amount is exceeded, the odometer resets the current
mileage to 0.
- To be able to work with a FuelGauge object. It should decrease the FuelGauge object's
current amount of fuel by 1 gallon for every 24 miles traveled. (The car's fuel economy is 24
miles per gallon).
Demonstrate the classes by creating instances of each. Simulate filling the car up with fuel, and then
run a loop that increments the odometer until the car runs out of fuel. During each loop iteration, print
the car's current milage and amount of fuel.
Here is the program I have so far:
# include <iostream>
# include <string>
using namespace std;
class FuelGauge
{
private:
int CurrentFuel;
public:
FuelGauge();
~FuelGauge();
FuelGauge(int g)
{
CurrentFuel = g;
}
int getCurrentFuel()
{
return CurrentFuel;
}
void IncrementFuel()
{
if (CurrentFuel < 15)
CurrentFuel++;
}
void DecrementFuel()
{
if (CurrentFuel > 0)
CurrentFuel--;
}
Error 2 error C3867: 'FuelGauge::getCurrentFuel': function call missing argument list; use '&FuelGauge::getCurrentFuel' to create a pointer to member
Error 1 error C3867: 'Odometer::getCurrentMileage': function call missing argument list; use '&Odometer::getCurrentMileage' to create a pointer to member
I don't know if I should change up my program if it is asking for the "&" after the functions or No clue where i should place the & if its going to change other parts of my program.
Think I was just adding some things to see if it could fix the problem But I changed it and it works but the output doesn't stop its going in a continuous loop
that's because you're looping it 999999 times which will take ages, and then even when you hit that it'll reset to zero and start again. So yea. It will loop continuously :)
EDIT: you only call DecrementFuel() in decrementCurrentMileage(), and you NEVER call this function. So in other words this: while (fuel.getCurrentFuel() > 0)
will always be true.