{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

CSCFINAL

# CSCFINAL - tank whichever is smaller void drive(double...

This preview shows pages 1–2. Sign up to view the full content.

/************************/ /* Brian Apple */ /* Assignment 0 */ /* CSC 1254 */ /* October 5 */ /************************/ #include<iostream> using namespace std; class Car { private: double fuel_efficiency; //mileage in miles/gallon double fuel_capacity; // capacity of fuel in gallons double fuel_in_tank; //current fuel in tank in gallons public: Car(double efficiency, double capacity); //all cars start with empty tanks double get_fuel() const; //returns current fuel level void add_fuel(double gallons); //increases fuel in tank // either by the gallons specified // or by the amount which fills the

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: // tank, whichever is smaller void drive(double miles); //reduces fuel in the tank }; Car::Car(double efficiency, double capacity) { fuel_efficiency = efficiency; fuel_capacity = capacity; } void Car::add_fuel(double gallons) { if(gallons < (fuel_capacity - fuel_in_tank)) fuel_in_tank = gallons + fuel_in_tank; else fuel_in_tank = (fuel_capacity - fuel_in_tank) + fuel_in_tank; } void Car::drive(double miles) { fuel_in_tank = fuel_in_tank - (miles * (1/fuel_efficiency)); } double Car::get_fuel() const { return fuel_in_tank; } int main() { Car c1(15.0, 20.0), c2(29.5, 30.0); c2.add_fuel(10.0); c2.drive(82.5); c1.add_fuel(25.0); &n...
View Full Document

{[ snackBarMessage ]}