Implement a class Car with the following properties. A car has a certain fuel efficiency (measured in miles/gallon or liters/km—pick one) and a certain amount of fuel in the gas tank. The efficiency is specified in the constructor, and the initial fuel level is 0. Supply a function drive that simulates driving the car for a certain distance, reducing the fuel level in the gas tank, and functions get_gas, to return the current fuel level, and add_gas, to tank up. Sample usage:
Try to keep it simple. Also, put some comments in your code, so others can understand what you are doing.
For now, you should have only one constructor, that takes the mpg, a function to print the gas level remaining, a function to add gas, and a function to drive. The only private variables are the mpg and the gas in the tank.
Also, when you post in this forum, please use the code tags, <> button
1 2 3 4 5 6 7 8 9 10 11
double gaslevel; //how much fuel is left in the tank
double mpg; //the mpg
Car(double mpg); //constructor
void add_gas(double gas);
void drive(double miles);
In your code you have fuel_mpg and mpg. You don't need both. You also have a constructor that takes no parameters. Think if you need that. The problem did not ask for maxmiles or for gasused, so don't put them in for now.