Hey guys! I have a class program here that I am stuck on. This is my first time officially asking for help, but after studying all avenues and research I still find myself wracking my brain. Most of the code is complete and without error...except for the last bit...of course. Here are the parameters of the assignment:
Writing Assignment: Class Car
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:
Car my_beemer(29); // 29 miles per gallon
my_beemer.add_gas(20); // Tank 20 gallons
my_beemer.drive(100); // Drive 100 miles
cout << my_beemer.get_gas() << "\n"; // Print fuel remaining
Where I am having trouble is the function drive that simulates driving for a specified distance. This will reduce the fuel level and the function get_gas, and return back to the current fuel level. I have tried coding this multiple ways and the compiler will typically deny just one word rendering all of it useless.....so.....I'm tired, and without chocolate on valentines day and my husband is working the dinner shift. Please please somebody help me, so I can enjoy the evening with him when he comes home. Hopefully with chocolate in his hand.
This is what I have so far:
(by the way...line 33 is just hanging there. I had a thought and just left it there. Maybe it will prove useful...maybe it wont)
#include <iostream>
#include <string>
using namespace std;
class Car
`Inline Code Example Here`
private:
double mpg; // Fuel efficiency in miles per gallon //
double fuel_capacity; // maximum fuel level in tank //
double fuelLevel; // amount of fuel in tank //
public:
Car (double mpg, double capacity); // Car is object. double mpg (efficiency) and capacity are constructors //
double get_gas(); // will return the current fuel level //
void add_gas (double gallons); // Tank Up! //
void distance (double milesDriven); // distance of miles driven //
};
Car::Car(double mpg, double capacity): mpg(mpg), fuel_capacity(capacity){ // Calling Constructor from //
// Constructor //
mpg = mpg;
fuel_capacity = capacity;
fuelLevel = 0.0;
}
void Car::add_gas (double gallons){ // If gas in the tank is below the fuel capacity tank up //
if ((fuelLevel + gallons) < fuel_capacity)
fuelLevel += gallons;
}
void Car:: get_gas.distance (milesDriven){
}
}